-
Notifications
You must be signed in to change notification settings - Fork 0
ci(workflows): introduce shared force merge workflow #9
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,124 @@ | ||
| name: "Force merge automation (shared)" | ||
| description: Merge a pull request when N committers post a comment with the command /force-merge | ||
|
|
||
| on: workflow_call | ||
|
|
||
| env: | ||
| quorum: 3 | ||
|
|
||
| jobs: | ||
| force_merge: | ||
| # This job only runs for pull request comments | ||
| if: ${{ github.event.issue.pull_request }} | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: Check pull request | ||
| id: should-run | ||
| uses: actions/github-script@v7 | ||
| with: | ||
| script: | | ||
| const issue = await github.rest.issues.get({ | ||
| issue_number: context.issue.number, | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo | ||
| }) | ||
|
|
||
| const isClosed = issue.data.closed_at != null | ||
| const isDraft = issue.data.draft | ||
|
|
||
| return !isClosed && !isDraft | ||
|
|
||
| - name: Count votes | ||
| id: count-votes | ||
| if: ${{ steps.should-run.outputs.result == 'true' }} | ||
| uses: actions/github-script@v7 | ||
| with: | ||
| script: | | ||
| const comments = await github.rest.issues.listComments({ | ||
| issue_number: context.issue.number, | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo | ||
| }) | ||
|
|
||
| // Check if debug mode is enabled by any comment containing "/debug-force-merge" | ||
| const debugEnabled = comments.data.some(comment => | ||
| comment.body && comment.body.includes('/debug-force-merge') | ||
| ); | ||
|
|
||
| // Debug: Print all commenters and their associations (only if debug enabled) | ||
| if (debugEnabled) { | ||
| console.log("=== All Comments Debug ==="); | ||
| for(const comment of comments.data) { | ||
| console.log(`User: ${comment.user.login}`); | ||
| console.log(`Association: ${comment.author_association}`); | ||
| console.log(`Has voting rights: ${comment.author_association === 'MEMBER' || comment.author_association === 'OWNER'}`); | ||
| console.log(`Has casted vote: ${comment.body && comment.body.trim() === '/force-merge'}`); | ||
| console.log("---"); | ||
| } | ||
| } | ||
|
|
||
| const votes = new Map(); | ||
| for(const comment of comments.data) { | ||
| const hasVotingRights = comment.author_association === 'MEMBER' || comment.author_association === 'OWNER' | ||
| const hasCastedVote = comment.body && comment.body.trim() === '/force-merge' | ||
|
|
||
| if(hasVotingRights && hasCastedVote) { | ||
| votes.set(comment.user.login, comment.author_association); | ||
| } | ||
| } | ||
|
|
||
| // Display voters and role | ||
| console.table(votes) | ||
|
|
||
| return votes.size | ||
|
|
||
| - name: Set labels | ||
| if: ${{ steps.should-run.outputs.result == 'true' }} | ||
| uses: actions/github-script@v7 | ||
| with: | ||
| script: | | ||
| const labels = await github.rest.issues.listLabelsOnIssue({ | ||
| issue_number: context.issue.number, | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo | ||
| }) | ||
| const labelsToAdd = [] | ||
| for(const label of labels.data) { | ||
| if(!label.name.startsWith('force-merge-votes-')) { | ||
| labelsToAdd.push(label.name) | ||
| } | ||
| } | ||
|
|
||
| const votes = ${{ steps.count-votes.outputs.result }} | ||
| if(votes >= 1 && votes < ${{env.quorum}}) { | ||
| labelsToAdd.push("force-merge-votes-" + votes) | ||
| } | ||
|
|
||
| const result = github.rest.issues.setLabels({ | ||
| issue_number: context.issue.number, | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| labels: labelsToAdd | ||
| }) | ||
|
|
||
| - name: Perform merge | ||
| if: ${{ (steps.should-run.outputs.result == 'true') && (steps.count-votes.outputs.result >= env.quorum) }} | ||
| uses: actions/github-script@v7 | ||
| with: | ||
| github-token: ${{ secrets.KURA_BOT_GITHUB_TOKEN }} | ||
| script: | | ||
| github.rest.issues.addLabels({ | ||
| issue_number: context.issue.number, | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| labels: ['force-merged'] | ||
| }) | ||
|
|
||
| await github.rest.pulls.merge({ | ||
| pull_number: context.issue.number, | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| merge_method: "squash" | ||
| }); | ||
|
|
||
This file contains hidden or 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,15 @@ | ||
| name: "Force merge automation" | ||
| description: Merge a pull request when N committers post a comment with the command /force-merge | ||
|
|
||
| on: | ||
| issue_comment: | ||
| types: [created, edited, deleted] | ||
|
|
||
| permissions: | ||
| contents: write | ||
| pull-requests: write | ||
| issues: write | ||
|
|
||
| jobs: | ||
| call-workflow-in-public-repo: | ||
| uses: eclipse-kura/.github/.github/workflows/_shared-force-merge.yml@main |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.