Skip to content

Commit

Permalink
Automerge every 15-min any PR with passing tests labeled with 'autome…
Browse files Browse the repository at this point in the history
…rge'
  • Loading branch information
addyess committed Sep 16, 2024
1 parent 407f739 commit cbe0f06
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/auto-merge-successful-prs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Auto-merge Successful PRs

on:
workflow_dispatch:
schedule:
- cron: "*/15 * * * *" # Every 15 minutes

permissions:
contents: read
pull-requests: write

jobs:
find_and_merge:
runs-on: ubuntu-latest

steps:
- name: Harden Runner
uses: step-security/harden-runner@v2
with:
egress-policy: audit
- name: Checking out repo
uses: actions/checkout@v4

# Fetch open pull requests and check for status checks on automerge PRs
- name: Auto-merge pull requests if all status checks pass
env:
GITHUB_TOKEN: ${{ secrets.DEPLOY_KEY_TO_UPDATE_STRICT_BRANCH }}
run: |
build-scripts/hack/auto-merge-successful-prs.sh
4 changes: 4 additions & 0 deletions .github/workflows/update-components.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,9 @@ jobs:
title: "[${{ matrix.branch }}] Update component versions"
body: "[${{ matrix.branch }}] Update component versions"
branch: "autoupdate/sync/${{ matrix.branch }}"
labels: |
automerge
automated pr
component update
delete-branch: true
base: ${{ matrix.branch }}
25 changes: 25 additions & 0 deletions build-scripts/auto-merge-successful-pr.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

set -e

# Fetch the open pull requests
prs=$(gh pr list --state open --json number,headRefName,labels | jq '[.[] | select(.labels | any(.name == "automerge"))]')

for pr in $(echo "$prs" | jq -r '.[] | @base64'); do
_jq() {
echo ${pr} | base64 --decode | jq -r ${1}
}

pr_number=$(_jq '.number')
head_branch=$(_jq '.headRefName')

# Check status checks for each PR
checks_passed=$(gh pr checks $pr_number --json bucket | jq -r '.[].bucket == "pass"' | sort | uniq)

if [[ "$checks_passed" == "true" ]]; then
echo "All status checks passed for PR #$pr_number. Proceeding with merge..."
gh pr merge $pr_number --auto --squash
else
echo "Status checks have not passed for PR #$pr_number. Skipping merge."
fi
done

0 comments on commit cbe0f06

Please sign in to comment.