Skip to content

Commit

Permalink
ci: add checks for merge strategy and linear history
Browse files Browse the repository at this point in the history
  • Loading branch information
mhofman committed Aug 27, 2023
1 parent a9fd671 commit e0eb08b
Showing 1 changed file with 64 additions and 1 deletion.
65 changes: 64 additions & 1 deletion .github/workflows/mergify-ready.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Integration tests triggered
name: Pre-merge checks

on:
pull_request:
Expand Down Expand Up @@ -28,3 +28,66 @@ jobs:
needs ${{ toJSON(needs.pre_check.outputs) }}
EOF
sleep 5
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:merge') ||
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:merge') ||
contains(github.event.pull_request.labels.*.name, 'bypass:automerge')
) &&
!contains(github.event.pull_request.labels.*.name, 'bypass:linear-history')
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- shell: bash
run: |
merge_commits=$(git rev-list --merges "origin/$GITHUB_BASE_REF".."origin/$GITHUB_HEAD_REF")
if [ -n "$merge_commits" ]; then
echo "Error: merge commits found in $GITHUB_BASE_REF..$GITHUB_HEAD_REF"
for merge_commit in $merge_commits; do
echo "$merge_commit"
done
exit 1
fi
fixup_commits=
for commit in $(git rev-list $GITHUB_BASE_REF..$GITHUB_HEAD_REF); do
case $(git show --pretty=format:%s -s $commit) in fixup\!*|squash\!*)
fixup_commits="$fixup_commits\n$commit"
;;
esac
done
if [ -n "$fixup_commits" ]; then
echo "Error: fixup/squash commits found in $GITHUB_BASE_REF..$GITHUB_HEAD_REF"
echo -e "$fixup_commits"
exit 1
fi

0 comments on commit e0eb08b

Please sign in to comment.