-
Notifications
You must be signed in to change notification settings - Fork 66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ci: support co-authoring for auto-merged PRs #176
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,12 +21,35 @@ jobs: | |
if: github.event.pull_request.draft == false && (github.event.pull_request.user.login != 'asyncapi-bot' || github.event.pull_request.user.login != 'dependabot[bot]' || github.event.pull_request.user.login != 'dependabot-preview[bot]') #it runs only if PR actor is not a bot, at least not a bot that we know | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Get list of authors | ||
uses: sergeysova/jq-action@v2 | ||
id: authors | ||
with: | ||
# This cmd does following (line by line): | ||
# 1. CURL querying the list of commits of the current PR via GH API. Why? Because the current event payload does not carry info about the commits. | ||
# 2. Iterates over the previous returned payload, and creates an array with the filtered results (see below) so we can work wit it later. An example of payload can be found in https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#webhook-payload-example-34. | ||
# 3. Grabs the data we need for adding the `Co-authored-by: ...` lines later and puts it into objects to be used later on. | ||
# 4. Filters the results by excluding the current PR sender. We don't need to add it as co-author since is the PR creator and it will become by default the main author. | ||
# 5. Removes repeated authors (authors can have more than one commit in the PR). | ||
# 6. Builds the `Co-authored-by: ...` lines with actual info. | ||
# 7. Transforms the array into plain text. Thanks to this, the actual stdout of this step can be used by the next Workflow step (wich is basically the automerge). | ||
cmd: | | ||
curl -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${{ secrets.GH_TOKEN }}" "${{github.event.pull_request._links.commits.href}}?per_page=100" | ||
| jq -r '[.[] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Iterating over the payload GH gives us, creating an array with the filtered results (below). An example of payload can be found in https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#webhook-payload-example-34 |
||
| {name: .commit.author.name, email: .commit.author.email, login: .author.login}] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line grabs the data we need for adding the |
||
| map(select(.login != "${{github.event.pull_request.user.login}}")) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line filters results by excluding the current PR sender. We don't need to add it as co-author since is the PR creator and it will become by default the main author. |
||
| unique | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We remove repeated authors |
||
| map("Co-authored-by: " + .name + " <" + .email + ">") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We finally write the lines we want to later on print to stdout |
||
| join("\n")' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Transforming the array into a plain text so we can directly copy this stdout to the next Workflow step (wich is basically the automerge) |
||
multiline: true | ||
- name: Automerge PR | ||
uses: pascalgn/automerge-action@v0.14.3 | ||
env: | ||
GITHUB_TOKEN: "${{ secrets.GH_TOKEN }}" | ||
MERGE_LABELS: "!do-not-merge,ready-to-merge" | ||
MERGE_METHOD: "squash" | ||
MERGE_COMMIT_MESSAGE: "{pullRequest.title} (#{pullRequest.number})" | ||
# Using the output of the previous step (`Co-authored-by: ...` lines) as commit description. | ||
# Important to keep 2 empty lines as https://docs.github.com/en/pull-requests/committing-changes-to-your-project/creating-and-editing-commits/creating-a-commit-with-multiple-authors#creating-co-authored-commits-on-the-command-line mentions | ||
MERGE_COMMIT_MESSAGE: "{pullRequest.title} (#{pullRequest.number})\n\n\n${{ steps.authors.outputs.value }}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We use the output of the previous step and put it into the description. |
||
MERGE_RETRIES: "20" | ||
MERGE_RETRY_SLEEP: "30000" | ||
MERGE_RETRY_SLEEP: "30000" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is querying the list of commits of the current PR via GH API. Why? Because the current event payload does not carry info about the commits.