|
1 | 1 | #!/bin/bash
|
2 |
| -set -e |
3 |
| -set -o pipefail |
| 2 | +set -eo pipefail |
4 | 3 |
|
5 | 4 | main() {
|
6 |
| - echo "Current ref: ${GITHUB_REF}" |
| 5 | + PR_REF="${GITHUB_REF%/merge}/head" |
| 6 | + BASE_REF="${GITHUB_BASE_REF}" |
7 | 7 |
|
8 |
| - if [[ "$GITHUB_REF" != "refs/heads/"* ]]; then |
9 |
| - echo "Only check branches, not tags or other refs." |
10 |
| - exit 0 |
11 |
| - fi |
12 |
| - |
13 |
| - BRANCH=${GITHUB_REF:11} |
14 |
| - echo "Current branch: ${BRANCH}" |
| 8 | + echo "Current ref: ${PR_REF}" |
| 9 | + echo "Base ref: ${BASE_REF}" |
15 | 10 |
|
16 |
| - if [ "$BRANCH" == "master" ]; then |
17 |
| - echo "No check of master branch needed." |
18 |
| - exit 0 |
| 11 | + if [[ "$PR_REF" != "refs/pull/"* ]]; then |
| 12 | + echo "This check works only with pull_request events" |
| 13 | + exit 1 |
19 | 14 | fi
|
20 | 15 |
|
21 | 16 | # Using git directly because the $GITHUB_EVENT_PATH file only shows commits in
|
22 | 17 | # most recent push.
|
23 |
| - /usr/bin/git -c protocol.version=2 fetch --no-tags --prune --progress --no-recurse-submodules --depth=1 origin master |
24 |
| - /usr/bin/git -c protocol.version=2 fetch --no-tags --prune --progress --no-recurse-submodules --shallow-exclude=master origin ${BRANCH} |
| 18 | + /usr/bin/git -c protocol.version=2 fetch --no-tags --prune --progress --no-recurse-submodules --depth=1 origin "${BASE_REF}:__ci_base" |
| 19 | + /usr/bin/git -c protocol.version=2 fetch --no-tags --prune --progress --no-recurse-submodules --shallow-exclude="${BASE_REF}" origin "${PR_REF}:__ci_pr" |
25 | 20 | # Get the list before the "|| true" to fail the script when the git cmd fails.
|
26 |
| - COMMIT_LIST=`/usr/bin/git log --pretty=format:%s origin/master..origin/${BRANCH}` |
| 21 | + COMMIT_LIST=`/usr/bin/git log --pretty=format:%s __ci_base..__ci_pr` |
27 | 22 |
|
28 | 23 | FIXUP_COUNT=`echo $COMMIT_LIST | grep fixup! | wc -l || true`
|
29 |
| - echo "Fixup! commits: ${FIXUP_COUNT}" |
30 |
| - if [ "$FIXUP_COUNT" -gt "0" ]; then |
31 |
| - /usr/bin/git log --pretty=format:%s origin/master..origin/${BRANCH} | grep fixup! |
| 24 | + echo "Fixup! commits: $FIXUP_COUNT" |
| 25 | + if [[ "$FIXUP_COUNT" -gt "0" ]]; then |
| 26 | + /usr/bin/git log --pretty=format:%s __ci_base..__ci_pr | grep fixup! |
32 | 27 | echo "failing..."
|
33 | 28 | exit 1
|
34 | 29 | fi
|
35 | 30 |
|
36 | 31 | SQUASH_COUNT=`echo $COMMIT_LIST | grep squash! | wc -l || true`
|
37 |
| - echo "Squash! commits: ${SQUASH_COUNT}" |
38 |
| - if [ "$SQUASH_COUNT" -gt "0" ]; then |
39 |
| - /usr/bin/git log --pretty=format:%s origin/master..origin/${BRANCH} | grep squash! |
| 32 | + echo "Squash! commits: $SQUASH_COUNT" |
| 33 | + if [[ "$SQUASH_COUNT" -gt "0" ]]; then |
| 34 | + /usr/bin/git log --pretty=format:%s __ci_base..__ci_pr | grep squash! |
40 | 35 | echo "failing..."
|
41 | 36 | exit 1
|
42 | 37 | fi
|
|
0 commit comments