Skip to content

Commit 646dcff

Browse files
ci(auto-merge): bidirectional sync between labels and native auto-merge (#75979)
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
1 parent 3f81be2 commit 646dcff

4 files changed

Lines changed: 150 additions & 73 deletions

File tree

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: "Auto-Merge Label Removal"
2+
3+
# When the last auto-merge label is removed from a PR, disable GitHub's
4+
# native auto-merge so the PR no longer merges automatically.
5+
6+
permissions: {}
7+
8+
on:
9+
pull_request_target:
10+
types:
11+
- unlabeled
12+
13+
jobs:
14+
disable-auto-merge:
15+
name: Disable native auto-merge
16+
# Runs when either auto-merge label is removed and the other is not
17+
# still present on the PR.
18+
if: >
19+
github.event.action == 'unlabeled'
20+
&& (
21+
github.event.label.name == 'auto-merge'
22+
|| github.event.label.name == 'auto-merge/bypass-ci-checks'
23+
)
24+
&& !contains(github.event.pull_request.labels.*.name, 'auto-merge')
25+
&& !contains(github.event.pull_request.labels.*.name, 'auto-merge/bypass-ci-checks')
26+
permissions: {}
27+
runs-on: ubuntu-24.04
28+
steps:
29+
- name: Authenticate as GitHub App
30+
uses: actions/create-github-app-token@67018539274d69449ef7c02e8e71183d1719ab42 # v2.1.4
31+
id: get-app-token
32+
with:
33+
owner: "airbytehq"
34+
repositories: "airbyte"
35+
app-id: ${{ secrets.OCTAVIA_BOT_APP_ID }}
36+
private-key: ${{ secrets.OCTAVIA_BOT_PRIVATE_KEY }}
37+
38+
- name: Check if native auto-merge is enabled
39+
id: check-auto-merge
40+
env:
41+
GH_TOKEN: ${{ steps.get-app-token.outputs.token }}
42+
PR_NUMBER: ${{ github.event.pull_request.number }}
43+
run: |
44+
AUTO_MERGE=$(gh pr view "$PR_NUMBER" --repo "${{ github.repository }}" --json autoMergeRequest --jq '.autoMergeRequest')
45+
echo "enabled=$( [ "$AUTO_MERGE" != "null" ] && [ -n "$AUTO_MERGE" ] && echo true || echo false )" \
46+
| tee -a "$GITHUB_OUTPUT"
47+
48+
- name: Disable native auto-merge
49+
if: steps.check-auto-merge.outputs.enabled == 'true'
50+
env:
51+
GH_TOKEN: ${{ steps.get-app-token.outputs.token }}
52+
PR_NUMBER: ${{ github.event.pull_request.number }}
53+
run: >
54+
gh pr merge "$PR_NUMBER"
55+
--repo "${{ github.repository }}"
56+
--disable-auto
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# Responds to GitHub's native auto-merge being enabled or disabled on a PR:
2+
#
3+
# 1. Enabled: adds a notice to the PR description.
4+
# 2. Disabled: updates the PR description notice and removes auto-merge
5+
# labels so the scheduled auto_merge.yml cron no longer re-processes
6+
# the PR.
7+
#
8+
# Note: Adding an `auto-merge*` label no longer auto-promotes draft PRs.
9+
# The connectors_up_to_date pipeline handles draft promotion and auto-merge
10+
# enablement directly. Draft PRs must be explicitly marked "Ready for review"
11+
# before native auto-merge and label-based automation will take effect.
12+
13+
name: "Auto-Merge Toggle"
14+
15+
permissions: {}
16+
17+
on:
18+
pull_request_target:
19+
types: [auto_merge_enabled, auto_merge_disabled]
20+
21+
jobs:
22+
# ---------- Update PR description notice ----------
23+
update-description:
24+
runs-on: ubuntu-24.04
25+
permissions:
26+
pull-requests: write
27+
steps:
28+
- name: Add Auto-Merge Notice
29+
if: github.event.action == 'auto_merge_enabled'
30+
uses: bcgov/action-pr-description-add@14338bfe0278ead273b3c1189e5aa286ff6709c4 # v2.0.0
31+
with:
32+
add_markdown: |
33+
> [!IMPORTANT]
34+
> ⚡ **Auto-merge enabled.**
35+
>
36+
> _This PR is set to merge automatically when all requirements are met._
37+
38+
- name: Remove Auto-Merge Notice
39+
if: github.event.action == 'auto_merge_disabled'
40+
uses: bcgov/action-pr-description-add@14338bfe0278ead273b3c1189e5aa286ff6709c4 # v2.0.0
41+
with:
42+
add_markdown: |
43+
> [!NOTE]
44+
> **Auto-merge may have been disabled. Please check the PR status to confirm.**
45+
46+
# ---------- Remove auto-merge labels when native auto-merge is disabled ----------
47+
remove-labels:
48+
name: Remove auto-merge labels
49+
if: >
50+
github.event.action == 'auto_merge_disabled'
51+
&& (
52+
contains(github.event.pull_request.labels.*.name, 'auto-merge')
53+
|| contains(github.event.pull_request.labels.*.name, 'auto-merge/bypass-ci-checks')
54+
)
55+
permissions: {}
56+
runs-on: ubuntu-24.04
57+
steps:
58+
- name: Authenticate as 'octavia-bot-hoard' GitHub App
59+
uses: actions/create-github-app-token@67018539274d69449ef7c02e8e71183d1719ab42 # v2.1.4
60+
id: get-app-token
61+
with:
62+
owner: "airbytehq"
63+
repositories: "airbyte"
64+
app-id: ${{ secrets.OCTAVIA_BOT_HOARD_APP_ID }}
65+
private-key: ${{ secrets.OCTAVIA_BOT_HOARD_PRIVATE_KEY }}
66+
67+
- name: Remove auto-merge label
68+
if: contains(github.event.pull_request.labels.*.name, 'auto-merge')
69+
env:
70+
GH_TOKEN: ${{ steps.get-app-token.outputs.token }}
71+
PR_NUMBER: ${{ github.event.pull_request.number }}
72+
run: >
73+
gh pr edit "$PR_NUMBER"
74+
--repo "${{ github.repository }}"
75+
--remove-label "auto-merge"
76+
77+
- name: Remove bypass-ci-checks label
78+
if: contains(github.event.pull_request.labels.*.name, 'auto-merge/bypass-ci-checks')
79+
env:
80+
GH_TOKEN: ${{ steps.get-app-token.outputs.token }}
81+
PR_NUMBER: ${{ github.event.pull_request.number }}
82+
run: >
83+
gh pr edit "$PR_NUMBER"
84+
--repo "${{ github.repository }}"
85+
--remove-label "auto-merge/bypass-ci-checks"
86+
87+
- name: Post notice comment
88+
env:
89+
GH_TOKEN: ${{ steps.get-app-token.outputs.token }}
90+
PR_NUMBER: ${{ github.event.pull_request.number }}
91+
run: >
92+
gh pr comment "$PR_NUMBER"
93+
--repo "${{ github.repository }}"
94+
--body "Auto-merge labels removed because native auto-merge was disabled on this PR. Re-add the label to re-enable."

.github/workflows/auto_merge_notification.yml

Lines changed: 0 additions & 31 deletions
This file was deleted.

.github/workflows/promote-draft-on-auto-merge-label.yml

Lines changed: 0 additions & 42 deletions
This file was deleted.

0 commit comments

Comments
 (0)