Skip to content
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

Automerge every 4 hours any labeled PR with passing tests #675

Merged
merged 6 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
addyess marked this conversation as resolved.
Show resolved Hide resolved

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
with:
ssh-key: ${{ secrets.BOT_SSH_KEY }}

# Fetch open pull requests and check for status checks on automerge PRs
- name: Auto-merge pull requests if all status checks pass
run: |
build-scripts/hack/auto-merge-successful-prs.sh
2 changes: 1 addition & 1 deletion .github/workflows/update-branches.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
- name: Sync ${{ github.ref }} to ${{ steps.determine.outputs.branch }}
uses: actions/checkout@v4
with:
ssh-key: ${{ secrets.DEPLOY_KEY_TO_UPDATE_STRICT_BRANCH }}
ssh-key: ${{ secrets.BOT_SSH_KEY }}
- name: Apply ${{ matrix.patch }} patch
run: |
git checkout -b ${{ steps.determine.outputs.branch }}
Expand Down
7 changes: 5 additions & 2 deletions .github/workflows/update-components.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
uses: actions/checkout@v4
with:
ref: ${{ matrix.branch }}
ssh-key: ${{ secrets.DEPLOY_KEY_TO_UPDATE_STRICT_BRANCH }}
ssh-key: ${{ secrets.BOT_SSH_KEY }}

- name: Setup Python
uses: actions/setup-python@v5
Expand All @@ -51,10 +51,13 @@ jobs:
- name: Create pull request
uses: peter-evans/create-pull-request@v6
with:
git-token: ${{ secrets.DEPLOY_KEY_TO_UPDATE_STRICT_BRANCH }}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it took some digging, but i believe i confirmed this wasn't doing anything because the branch on the runner was checked out using an SSH key -- the token isn't necessary here to push to the branch. Instead it relies on the ssh key already being part of the local git config.

commit-message: "[${{ matrix.branch }}] Update component versions"
title: "[${{ matrix.branch }}] Update component versions"
body: "[${{ matrix.branch }}] Update component versions"
branch: "autoupdate/sync/${{ matrix.branch }}"
labels: |
automerge
automated pr
component update
addyess marked this conversation as resolved.
Show resolved Hide resolved
delete-branch: true
base: ${{ matrix.branch }}
26 changes: 26 additions & 0 deletions build-scripts/auto-merge-successful-pr.sh
addyess marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/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 review $pr_number --approve -b "All status checks passed for PR #$pr_number."
gh pr merge $pr_number --auto --squash
else
echo "Status checks have not passed for PR #$pr_number. Skipping merge."
fi
done
9 changes: 6 additions & 3 deletions build-scripts/patches/moonray/apply
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

DIR="$(realpath "$(dirname "${0}")")"

# Configure git author
git config user.email [email protected]
git config user.name k8s-bot
# Configure git author if unset
addyess marked this conversation as resolved.
Show resolved Hide resolved
git_email=$(git config --default "" user.email)
if [ -z "${git_email}" ]; then
git config user.email [email protected]
git config user.name 'k8s-team-ci (CDK Bot)'
fi

# Remove unrelated tests
rm "${DIR}/../../../tests/integration/tests/test_cilium_e2e.py"
Expand Down
7 changes: 5 additions & 2 deletions build-scripts/patches/strict/apply
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
DIR="$(realpath "$(dirname "${0}")")"

# Configure git author
git config user.email [email protected]
git config user.name k8s-bot
git_email=$(git config --default "" user.email)
if [ -z "${git_email}" ]; then
git config user.email [email protected]
git config user.name 'k8s-team-ci (CDK Bot)'
fi

# Apply strict patch
git am "${DIR}/0001-Strict-patch.patch"
Loading