Skip to content

Commit fc96020

Browse files
committed
chore: enforce linear history for PRs
1 parent f43d978 commit fc96020

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Check branch status
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- "**"
7+
8+
jobs:
9+
check_branch_history:
10+
name: Check - Linear history
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout source code
14+
uses: actions/checkout@v3
15+
with:
16+
ref: ${{ github.event.pull_request.head.sha }} # otherwise, it'd create a merge commit
17+
fetch-depth: "0"
18+
- name: Check HEAD is rebased on ${{ github.event.pull_request.base.ref }}
19+
run: |
20+
git config --global user.name "$GITHUB_ACTOR"
21+
git config --global user.email "github-actions@github.com"
22+
git fetch origin $GITHUB_BASE_REF
23+
PR_HEAD_SHA=$(git rev-parse HEAD)
24+
git rebase FETCH_HEAD
25+
REBASED_SHA=$(git rev-parse HEAD)
26+
echo "PR HEAD: $PR_HEAD_SHA"
27+
echo "Rebased HEAD: $REBASED_SHA"
28+
git range-diff FETCH_HEAD..$PR_HEAD_SHA FETCH_HEAD..$REBASED_SHA
29+
if [[ "$REBASED_SHA" != "$PR_HEAD_SHA" ]]; then
30+
echo "Not fast forward, aborting!"
31+
echo "Ensure that the PR branch is rebased on $GITHUB_BASE_REF and does not contain merge commits."
32+
exit 1
33+
fi

0 commit comments

Comments
 (0)