mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-06-09 19:13:26 +03:00
workflows/get-merge-commit: inline get-merge-commit.sh script as github-script
The reason this was a separate shell script was, that this would be included in multiple workflows separately. But a while ago this had been changed to a re-usable workflow, so we can just as well inline the script. This also allows us to use actions/github-script, which makes for a much more readable script than the bash script before.
This commit is contained in:
parent
f66ede7fd3
commit
277f7b998c
3 changed files with 41 additions and 128 deletions
61
.github/workflows/get-merge-commit.yml
vendored
61
.github/workflows/get-merge-commit.yml
vendored
|
@ -22,8 +22,8 @@ jobs:
|
|||
resolve-merge-commit:
|
||||
runs-on: ubuntu-24.04-arm
|
||||
outputs:
|
||||
mergedSha: ${{ steps.merged.outputs.mergedSha }}
|
||||
targetSha: ${{ steps.merged.outputs.targetSha }}
|
||||
mergedSha: ${{ fromJSON(steps.merged.outputs.result).mergedSha }}
|
||||
targetSha: ${{ fromJSON(steps.merged.outputs.result).targetSha }}
|
||||
systems: ${{ steps.systems.outputs.systems }}
|
||||
steps:
|
||||
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
||||
|
@ -33,24 +33,45 @@ jobs:
|
|||
|
||||
- name: Check if the PR can be merged and get the test merge commit
|
||||
id: merged
|
||||
env:
|
||||
GH_TOKEN: ${{ github.token }}
|
||||
GH_EVENT: ${{ github.event_name }}
|
||||
run: |
|
||||
case "$GH_EVENT" in
|
||||
push)
|
||||
echo "mergedSha=${{ github.sha }}" >> "$GITHUB_OUTPUT"
|
||||
;;
|
||||
pull_request*)
|
||||
if commits=$(base/ci/get-merge-commit.sh ${{ github.repository }} ${{ github.event.number }}); then
|
||||
echo -e "Checking the commits:\n$commits"
|
||||
echo "$commits" >> "$GITHUB_OUTPUT"
|
||||
else
|
||||
# Skipping so that no notifications are sent
|
||||
echo "Skipping the rest..."
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
|
||||
with:
|
||||
script: |
|
||||
if (context.eventName == 'push') return { mergedSha: context.sha }
|
||||
|
||||
for (const retryInterval of [5, 10, 20, 40, 80]) {
|
||||
console.log("Checking whether the pull request can be merged...")
|
||||
const prInfo = (await github.rest.pulls.get({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
pull_number: context.payload.pull_request.number
|
||||
})).data
|
||||
|
||||
if (prInfo.state != 'open') throw new Error ("PR is not open anymore.")
|
||||
|
||||
if (prInfo.mergeable == null) {
|
||||
console.log(`GitHub is still computing whether this PR can be merged, waiting ${retryInterval} seconds before trying again...`)
|
||||
await new Promise(resolve => setTimeout(resolve, retryInterval * 1000))
|
||||
continue
|
||||
}
|
||||
|
||||
if (prInfo.mergeable) {
|
||||
console.log("The PR can be merged.")
|
||||
|
||||
const mergedSha = prInfo.merge_commit_sha
|
||||
const 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 {
|
||||
throw new Error("The PR has a merge conflict. Skipping the rest...")
|
||||
}
|
||||
}
|
||||
throw new Error("Not retrying anymore. It's likely that GitHub is having internal issues: check https://www.githubstatus.com.")
|
||||
|
||||
- name: Load supported systems
|
||||
id: systems
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue