Skip to content

Commit

Permalink
chore: move things to the right place
Browse files Browse the repository at this point in the history
  • Loading branch information
arzola committed May 14, 2024
1 parent 4abdf3b commit 76103d9
Showing 1 changed file with 84 additions and 0 deletions.
84 changes: 84 additions & 0 deletions .github/workflows/auto-merge.yml
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}}

0 comments on commit 76103d9

Please sign in to comment.