Repository navigation
98 lines (93 loc) · 4.37 KB
/
Copy pathautomerge.yaml
File metadata and controls
98 lines (93 loc) · 4.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
name: Auto-merge
# Adding the "automerge" label to a pull request turns on GitHub's auto-merge: the
# pull request is merged as soon as the required checks ("All green") pass.
# Removing the label turns it off again. Pull requests without the label are never
# merged automatically. New commits pushed after the label was added remove it (and
# turn auto-merge off), so what gets merged is always what was looked at.
#
# pull_request_target so that the token can merge pull requests from forks too; the
# pull request's code is never checked out or run here.
on:
pull_request_target:
types: [labeled, unlabeled, synchronize]
permissions:
contents: write
pull-requests: write
jobs:
automerge:
if: github.event.action != 'synchronize' && github.event.label.name == 'automerge'
concurrency:
group: automerge-${{ github.event.pull_request.number }}
cancel-in-progress: false
runs-on: ubuntu-latest
steps:
# the base branch (pull_request_target's default), for pixi's gh: never the pull request's code
- uses: actions/checkout@v6
with:
persist-credentials: false
- name: Disable git auto-maintenance
run: git config --global maintenance.auto false && git config --global gc.auto 0
- uses: prefix-dev/setup-pixi@v0.11.0
with:
locked: true # the lock file must match pixi.toml
pixi-version: v0.81.0
cache-write: false # saved from main only (pixi-cache.yaml)
# The merge has to come from the bot (or a PAT): a merge made with the
# workflow's own token would not trigger the main build workflow.
- name: Bot token
id: app
if: vars.ROBOSTACK_BOT_CLIENT_ID != ''
uses: actions/create-github-app-token@v3
with:
client-id: ${{ vars.ROBOSTACK_BOT_CLIENT_ID }}
private-key: ${{ secrets.ROBOSTACK_BOT_PRIVATE_KEY }}
- name: Turn auto-merge on or off
env:
GH_TOKEN: ${{ steps.app.outputs.token || secrets.GHA_PAT || github.token }}
BOT_TOKEN: ${{ steps.app.outputs.token || secrets.GHA_PAT }}
PR: ${{ github.event.pull_request.html_url }}
run: |
# labeled/unlabeled events can arrive out of order: go by the label the
# pull request has now, not by the event
enabled=$(pixi run gh pr view "$PR" --json labels --jq 'any(.labels[]; .name == "automerge")')
if [ "$enabled" = true ]; then
if [ -z "$BOT_TOKEN" ]; then
echo "::error::auto-merge needs the bot app (ROBOSTACK_BOT_CLIENT_ID + ROBOSTACK_BOT_PRIVATE_KEY) or GHA_PAT: a merge with the workflow token doesn't start the build workflow"
exit 1
fi
GH_TOKEN="$BOT_TOKEN" pixi run gh pr merge "$PR" --auto --merge
else
pixi run gh pr merge "$PR" --disable-auto
fi
drop-on-push:
if: >-
github.event.action == 'synchronize' &&
contains(github.event.pull_request.labels.*.name, 'automerge')
concurrency:
group: automerge-${{ github.event.pull_request.number }}
cancel-in-progress: false
runs-on: ubuntu-latest
steps:
# the base branch (pull_request_target's default), for pixi's gh: never the pull request's code
- uses: actions/checkout@v6
with:
persist-credentials: false
- name: Disable git auto-maintenance
run: git config --global maintenance.auto false && git config --global gc.auto 0
- uses: prefix-dev/setup-pixi@v0.11.0
with:
locked: true # the lock file must match pixi.toml
pixi-version: v0.81.0
cache-write: false # saved from main only (pixi-cache.yaml)
# removing the label with this token doesn't start the unlabeled run above, so
# turn auto-merge off here as well
- name: Remove the automerge label
env:
GH_TOKEN: ${{ github.token }}
PR: ${{ github.event.pull_request.html_url }}
BEFORE: ${{ github.event.before }}
AFTER: ${{ github.event.after }}
run: |
pixi run gh pr edit "$PR" --remove-label automerge
pixi run gh pr merge "$PR" --disable-auto || true
pixi run gh pr comment "$PR" --body "New commits (${BEFORE:0:7}..${AFTER:0:7}) arrived after the \`automerge\` label was added, so the label was removed and auto-merge turned off. Add the label again once the new commits are reviewed."