diff --git a/.github/actions/get-merge-commit/action.yml b/.github/actions/get-merge-commit/action.yml index 1505d582efd8..51f8a00286b5 100644 --- a/.github/actions/get-merge-commit/action.yml +++ b/.github/actions/get-merge-commit/action.yml @@ -5,10 +5,10 @@ description: 'Checks whether the Pull Request is mergeable and returns two commi outputs: mergedSha: description: "The merge commit SHA" - value: ${{ fromJSON(steps.merged.outputs.result).mergedSha }} + value: ${{ steps.merged.outputs.mergedSha }} targetSha: description: "The target commit SHA" - value: ${{ fromJSON(steps.merged.outputs.result).targetSha }} + value: ${{ steps.merged.outputs.targetSha }} runs: using: composite @@ -17,7 +17,7 @@ runs: uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 with: script: | - if (context.eventName == 'push') return { mergedSha: context.sha } + if (context.eventName == 'push') return core.setOutput('mergedSha', context.sha) for (const retryInterval of [5, 10, 20, 40, 80]) { console.log("Checking whether the pull request can be merged...") @@ -35,32 +35,31 @@ runs: continue } + let mergedSha, targetSha + if (prInfo.mergeable) { console.log("The PR can be merged.") - const mergedSha = prInfo.merge_commit_sha - const targetSha = (await github.rest.repos.getCommit({ + mergedSha = prInfo.merge_commit_sha + targetSha = (await github.rest.repos.getCommit({ owner: context.repo.owner, repo: context.repo.repo, ref: prInfo.merge_commit_sha })).data.parents[0].sha - - console.log(`Checking the commits:\nmerged:${mergedSha}\ntarget:${targetSha}`) - - return { mergedSha, targetSha } } else { console.log("The PR has a merge conflict.") - const mergedSha = prInfo.head.sha - const targetSha = (await github.rest.repos.compareCommitsWithBasehead({ + mergedSha = prInfo.head.sha + targetSha = (await github.rest.repos.compareCommitsWithBasehead({ owner: context.repo.owner, repo: context.repo.repo, basehead: `${prInfo.base.sha}...${prInfo.head.sha}` })).data.merge_base_commit.sha - - console.log(`Checking the commits:\nmerged:${mergedSha}\ntarget:${targetSha}`) - - return { mergedSha, targetSha } } + + console.log(`Checking the commits:\nmerged:${mergedSha}\ntarget:${targetSha}`) + core.setOutput('mergedSha', mergedSha) + core.setOutput('targetSha', targetSha) + return } throw new Error("Not retrying anymore. It's likely that GitHub is having internal issues: check https://www.githubstatus.com.")