-
Notifications
You must be signed in to change notification settings - Fork 1.1k
65 lines (63 loc) · 2.51 KB
/
Copy pathpr-validation.yaml
File metadata and controls
65 lines (63 loc) · 2.51 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
name: Pull Request Validation
"on":
pull_request:
types: [opened, synchronize, reopened, edited, auto_merge_enabled, auto_merge_disabled]
branches: [main]
jobs:
# Count the number of commits in a pull request. This can be
# disabled by adding a trailer line of the following form to the
# pull request message:
#
# Disable-Check: commit-count
#
# The check is case-insensitive and ignores other contents on the
# line as well, so it is possible to add several different checks if
# that is necessary.
#
# It is assumed that the trailer is following RFC2822 conventions,
# but this is currently not enforced.
count_commits:
name: Enforce single commit pull request
runs-on: timescaledb-runner-arm64
steps:
- name: Checkout source
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0
- name: Check number of commits
if: github.event.pull_request.auto_merge.merge_method != 'squash'
shell: bash --norc --noprofile {0}
env:
BODY: ${{ github.event.pull_request.body }}
run: |
base=${{ github.event.pull_request.base.sha }}
head=${{ github.event.pull_request.head.sha }}
count=$(git rev-list --no-merges --count $base..$head)
# Hard limit of 5 commits per pull request. This check cannot
# be disabled via the Disable-check trailer or by using squash
# merge.
if [[ "$count" -gt 5 ]]; then
echo "Found $count commits in pull request (there must be no more than 5):"
git log --format=format:'- %h %s' $base..$head
echo
echo "This limit cannot be overridden. Please rebase and reduce"
echo "the number of commits to 5 or fewer."
exit 1
fi
if ! echo "$BODY" | grep -Eqsi '^disable-check:.*\<commit-count\>'
then
if [[ "$count" -ne 1 ]]; then
echo "Found $count commits in pull request (there should be only one):"
git log --format=format:'- %h %s' $base..$head
echo
echo "To disable commit count, add this trailer to pull request message:"
echo
echo "Disable-check: commit-count"
echo
echo "Trailers follow RFC2822 conventions, so no whitespace"
echo "before field name and the check is case-insensitive for"
echo "both the field name and the field body."
exit 1
fi
fi