-
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.
chore: move things to the right place
- Loading branch information
Showing
1 changed file
with
84 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
name: Auto merge workflow 🤖 | ||
on: | ||
workflow_call: | ||
inputs: | ||
pr_title_pattern: | ||
required: false | ||
type: string | ||
default: '^(chore(l10n|i18n)?: update languages|^chore: Composer update with)' | ||
|
||
jobs: | ||
automerge: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Check Pull Request Title | ||
id: title-check | ||
run: | | ||
PR_TITLE="${{ github.event.pull_request.title }}" | ||
PR_TITLE_PATTERN="${{ inputs.pr_title_pattern }}" | ||
shouldMerge=$(echo "$PR_TITLE" | grep -Eq "$PR_TITLE_PATTERN" && echo 'true' || echo 'false') | ||
echo "shouldMerge=$shouldMerge" >> $GITHUB_OUTPUT | ||
- name: Wait for checks to complete | ||
if: steps.title-check.outputs.shouldMerge == 'true' | ||
uses: actions/github-script@v6 | ||
env: | ||
GITHUB_TOKEN: ${{secrets.PAT_FOR_GITHUB_ACTIONS}} | ||
with: | ||
result-encoding: string | ||
script: | | ||
const wait = ms => new Promise(resolve => setTimeout(resolve, ms)); | ||
async function waitForChecks() { | ||
while (true) { | ||
const response = await github.rest.checks.listForRef({ | ||
owner: context.payload.repository.owner.login, | ||
repo: context.payload.repository.name, | ||
ref: context.payload.pull_request.head.ref | ||
}); | ||
// Filter out checks that are not completed and not the current check | ||
const checks = response.data.check_runs.filter(check => { | ||
return check.status !== 'completed' && check.name !== 'automerge / automerge'; | ||
}); | ||
if (checks.length === 0) { | ||
console.log('All checks completed.'); | ||
break; | ||
} | ||
console.log('Waiting for checks to complete...'); | ||
await wait(10000); // Wait for 10 seconds | ||
} | ||
} | ||
return waitForChecks(); | ||
github-token: ${{github.token}} | ||
|
||
- name: Merge Composer auto update PRs | ||
if: steps.title-check.outputs.shouldMerge == 'true' | ||
uses: actions/github-script@v6 | ||
env: | ||
GITHUB_TOKEN: ${{secrets.PAT_FOR_GITHUB_ACTIONS}} | ||
with: | ||
result-encoding: string | ||
script: | | ||
github.rest.pulls.createReview({ | ||
owner: context.payload.repository.owner.login, | ||
repo: context.payload.repository.name, | ||
pull_number: context.payload.pull_request.number, | ||
event: 'APPROVE' | ||
}).then(() => { | ||
github.rest.pulls.listReviews({ | ||
owner: context.payload.repository.owner.login, | ||
repo: context.payload.repository.name, | ||
pull_number: context.payload.pull_request.number | ||
}).then((reviews) => { | ||
const approvingReviews = reviews.data.filter(review => review.state === 'APPROVED') | ||
if (approvingReviews.length > 0) { | ||
github.rest.pulls.merge({ | ||
owner: context.payload.repository.owner.login, | ||
repo: context.payload.repository.name, | ||
pull_number: context.payload.pull_request.number | ||
}) | ||
} | ||
}) | ||
}) | ||
github-token: ${{github.token}} |