Skip to content

Commit bd5504f

Browse files
authored
Merge pull request #21 from lumeohq/base-ref
Rewrite branch logic to allow base branches other than master
2 parents 6521b8e + b16f6dc commit bd5504f

File tree

3 files changed

+20
-25
lines changed

3 files changed

+20
-25
lines changed

.github/workflows/git.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: Git Checks
22

3-
on: [push]
3+
on: [pull_request]
44

55
jobs:
66
block-fixup:

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ following:
2525
```yaml
2626
name: Git Checks
2727

28-
on: [push]
28+
on: [pull_request]
2929

3030
jobs:
3131
block-fixup:
@@ -34,7 +34,7 @@ jobs:
3434
steps:
3535
- uses: actions/[email protected]
3636
- name: Block Fixup Commit Merge
37-
uses: 13rac1/block-fixup-merge-action@v1.1.2
37+
uses: 13rac1/block-fixup-merge-action@v2.0.0
3838
```
3939
4040
Optionally, setup Branch Protection to block merging of PRs against the `master`

entrypoint.sh

+17-22
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,37 @@
11
#!/bin/bash
2-
set -e
3-
set -o pipefail
2+
set -eo pipefail
43

54
main() {
6-
echo "Current ref: ${GITHUB_REF}"
5+
PR_REF="${GITHUB_REF%/merge}/head"
6+
BASE_REF="${GITHUB_BASE_REF}"
77

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}"
1510

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
1914
fi
2015

2116
# Using git directly because the $GITHUB_EVENT_PATH file only shows commits in
2217
# 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"
2520
# 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`
2722

2823
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!
3227
echo "failing..."
3328
exit 1
3429
fi
3530

3631
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!
4035
echo "failing..."
4136
exit 1
4237
fi

0 commit comments

Comments
 (0)