forked from nim-works/nimskull
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
633: prepare for migration to GitHub merge queue r=alaviss a=alaviss ## Summary Prepare workflows and documentations for migrating from bors-ng to GitHub Merge Queue. ## Details Other than some reformatting here and there, the main changes centers around making our workflows aware of merge_group event and to make them pass on PRs even when they're skipped. For publisher, it will now operate under an environment to allow for stricter deployment rules and signed releases in the future. Documentation has also been updated, and a new /merge command has been added for trimming PR description and queuing a merge. Co-authored-by: Leorize <[email protected]>
- Loading branch information
Showing
6 changed files
with
221 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,14 @@ jobs: | |
publisher: | ||
runs-on: ubuntu-latest | ||
|
||
permissions: | ||
actions: read | ||
contents: write | ||
|
||
environment: | ||
name: release | ||
url: ${{ steps.release.outputs.url }} | ||
|
||
steps: | ||
# Publish action needs a checkout | ||
- uses: actions/checkout@v3 | ||
|
@@ -85,7 +93,8 @@ jobs: | |
echo "version=$(./release_manifest version)" >> $GITHUB_OUTPUT | ||
working-directory: release-staging | ||
|
||
- name: Create pre-release | ||
- id: release | ||
name: Create pre-release | ||
uses: softprops/[email protected] | ||
with: | ||
prerelease: true | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
name: /merge handler | ||
|
||
on: | ||
repository_dispatch: | ||
types: [merge-command] | ||
|
||
permissions: | ||
pull-requests: write | ||
|
||
concurrency: merge-handler-${{ github.event.client_payload.pull_request.node_id || github.run_id }} | ||
|
||
jobs: | ||
merge: | ||
if: github.event.client_payload.pull_request != null | ||
name: Trim description and merge | ||
runs-on: ubuntu-latest | ||
steps: | ||
- id: pr-data | ||
name: Get PR data and trim PR body | ||
uses: actions/github-script@v6 | ||
with: | ||
script: | | ||
const pull_id = context.payload.client_payload.pull_request.node_id; | ||
core.debug(`Pull request ID: ${pull_id}.`); | ||
const query = `query($id: ID!) { | ||
node(id: $id) { | ||
... on PullRequest { | ||
autoMergeRequest { | ||
mergeMethod | ||
} | ||
mergeQueueEntry { | ||
state | ||
} | ||
closed | ||
body | ||
} | ||
} | ||
}`; | ||
const { node: pr_info } = await github.graphql(query, { id: pull_id }); | ||
core.debug(`PR data: ${JSON.stringify(pr_info)}`); | ||
if (pr_info.closed) { | ||
core.notice('PR is already merged or closed.'); | ||
return; | ||
} | ||
if (pr_info.autoMergeRequest || pr_info.mergeQueueEntry) { | ||
core.notice('PR is already queued for merging.'); | ||
return; | ||
} | ||
let [ body, body_tail ] = pr_info.body.split(/^---\s*$/m, 2); | ||
body = body.trimEnd(); | ||
body_tail = body_tail?.trimEnd() || ''; | ||
// Only runs when the PR is still open and is not staged for merging. | ||
core.setOutput('run', 'true'); | ||
core.setOutput('body', body); | ||
core.setOutput('body-tail', body_tail); | ||
if (pr_info.body !== body) { | ||
// Only attempt PR description update if there are changes to be made | ||
core.setOutput('update-body', 'true'); | ||
} | ||
- if: steps.pr-data.outputs.run | ||
id: find-comment | ||
name: Find previously generated informational comment | ||
uses: peter-evans/find-comment@v2 | ||
with: | ||
issue-number: ${{ github.event.client_payload.pull_request.number }} | ||
comment-author: github-actions[bot] | ||
body-includes: <!-- /merge info comment --> | ||
direction: last | ||
|
||
# Only update the comment if there's a tail. This prevents the | ||
# tail from being replaced due to multiple /merge calls. | ||
- if: >- | ||
steps.pr-data.outputs.run | ||
&& !(steps.find-comment.outputs.comment-id | ||
&& steps.pr-data.outputs.body-tail == '') | ||
name: Create or update informational comment | ||
uses: peter-evans/create-or-update-comment@v3 | ||
with: | ||
comment-id: ${{ steps.find-comment.outputs.comment-id }} | ||
issue-number: ${{ github.event.client_payload.pull_request.number }} | ||
body: | | ||
<!-- /merge info comment --> | ||
<!-- Autogenerated by merge-command. DO NOT EDIT --> | ||
Merge requested by: @${{ github.event.client_payload.github.payload.comment.user.login }} | ||
Contents after the first section break of the PR description has been removed and preserved below: | ||
--- | ||
<blockquote> | ||
${{ steps.pr-data.outputs.body-tail }} | ||
</blockquote> | ||
edit-mode: replace | ||
- if: steps.pr-data.outputs.run && steps.pr-data.outputs.update-body | ||
name: Update PR description | ||
env: | ||
PR_URL: ${{ github.event.client_payload.pull_request.html_url }} | ||
NEW_PR_BODY: ${{ steps.pr-data.outputs.body }} | ||
GH_TOKEN: ${{ github.token }} | ||
run: gh pr edit "$PR_URL" --body "$NEW_PR_BODY" | ||
|
||
# An app token is required for CI to trigger | ||
- if: steps.pr-data.outputs.run | ||
id: token | ||
name: Create app token for merges | ||
uses: tibdex/github-app-token@v1 | ||
with: | ||
app_id: ${{ secrets.CHORE_APP_ID }} | ||
private_key: ${{ secrets.CHORE_APP_KEY }} | ||
|
||
# TODO: Switch to GitHub CLI once | ||
# https://github.com/cli/cli/issues/7213 is solved. | ||
- if: steps.pr-data.outputs.run | ||
name: Queue for merging | ||
uses: actions/github-script@v6 | ||
with: | ||
script: | | ||
const pull_id = context.payload.client_payload.pull_request.node_id; | ||
const queue = `mutation ($input: EnablePullRequestAutoMergeInput!) { | ||
enablePullRequestAutoMerge(input: $input) { | ||
clientMutationId | ||
} | ||
}`; | ||
await github.graphql(queue, { | ||
input: { | ||
pullRequestId: pull_id | ||
} | ||
}); | ||
github-token: ${{ steps.token.outputs.token }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
name: Dispatch slash commands | ||
|
||
on: | ||
issue_comment: | ||
types: | ||
- created | ||
|
||
jobs: | ||
dispatch_pr: | ||
if: github.event.issue.pull_request | ||
name: Dispatch on Pull Request comments | ||
runs-on: ubuntu-latest | ||
steps: | ||
- id: token | ||
uses: tibdex/github-app-token@v1 | ||
with: | ||
app_id: ${{ secrets.CHORE_APP_ID }} | ||
private_key: ${{ secrets.CHORE_APP_KEY }} | ||
|
||
- uses: peter-evans/slash-command-dispatch@v3 | ||
with: | ||
token: ${{ steps.token.outputs.token }} | ||
reaction-token: ${{ steps.token.outputs.token }} | ||
commands: | | ||
merge | ||
issue-type: pull-request | ||
permission: write |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters