-
Notifications
You must be signed in to change notification settings - Fork 208
120 lines (108 loc) · 3.98 KB
/
mergify-ready.yml
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
name: Pre-merge checks
on:
pull_request:
types:
- opened
- reopened
- synchronize
- converted_to_draft
- ready_for_review
- labeled
- unlabeled
- auto_merge_enabled
- auto_merge_disabled
merge_group:
jobs:
wait-integration-pre-checks:
runs-on: ubuntu-latest
steps:
- shell: bash
run: echo "TODO remove this vestigial job"
merge-strategy:
runs-on: ubuntu-latest
if: >-
github.event_name != 'pull_request' ||
github.event.pull_request.draft == true ||
github.event.pull_request.base.ref != 'master' || (
contains(github.event.pull_request.labels.*.name, 'automerge:squash') ||
contains(github.event.pull_request.labels.*.name, 'automerge:no-update') ||
contains(github.event.pull_request.labels.*.name, 'automerge:rebase') ||
contains(github.event.pull_request.labels.*.name, 'bypass:automerge') ||
github.event.pull_request.auto_merge != null
)
strategy:
# abuse the matrix feature to create a check which stays pending until
# a merge strategy is chosen
matrix:
merge: [chosen]
steps:
- shell: bash
run: echo "Merge strategy chosen"
linear-history:
runs-on: ubuntu-latest
if: >-
github.event_name == 'pull_request' &&
github.event.pull_request.draft == false &&
github.event.pull_request.base.ref == 'master' && (
contains(github.event.pull_request.labels.*.name, 'automerge:no-update') ||
contains(github.event.pull_request.labels.*.name, 'bypass:automerge')
) &&
!contains(github.event.pull_request.labels.*.name, 'bypass:linear-history')
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- shell: bash
env:
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
HEAD_LABEL: ${{ github.event.pull_request.head.label }}
BASE_SHA: ${{ github.event.pull_request.base.sha }}
BASE_LABEL: ${{ github.event.pull_request.base.label }}
run: |
merge_commits=$(git rev-list --merges "$BASE_SHA".."$HEAD_SHA")
if [ -n "$merge_commits" ]; then
echo "Error: merge commits found in $BASE_LABEL..$HEAD_LABEL"
for merge_commit in $merge_commits; do
echo "$merge_commit"
done
exit 1
fi
fixup_commits=
for commit in $(git rev-list $BASE_SHA..$HEAD_SHA); do
case $(git show --pretty=format:%s -s $commit) in fixup\!*|squash\!*|amend\!*)
fixup_commits="$fixup_commits\n$commit"
;;
esac
done
if [ -n "$fixup_commits" ]; then
echo "Error: fixup/squash/amend commits found in $BASE_LABEL..$HEAD_LABEL"
echo -e "$fixup_commits"
exit 1
fi
no-fixup-commits:
runs-on: ubuntu-latest
if: >-
github.event_name == 'pull_request' &&
github.event.pull_request.draft == false &&
github.event.pull_request.base.ref == 'master' &&
contains(github.event.pull_request.labels.*.name, 'automerge:rebase') &&
!contains(github.event.pull_request.labels.*.name, 'bypass:linear-history')
env:
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
BASE_SHA: ${{ github.event.pull_request.base.sha }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check for fixup commits
id: fixup-commits
run: |
if ! git merge-base --is-ancestor "$BASE_SHA" "$HEAD_SHA"; then
echo "PR is not up to date with target branch, skipping fixup commit check"
elif [[ $(git rev-list "$BASE_SHA".."$HEAD_SHA" --grep="^\(fixup\|amend\|squash\)! " | wc -l) -eq 0 ]]; then
echo "No fixup/amend/squash commits found in commit history"
else
echo "fixup/amend/squash commits found in commit history"
exit 1
fi