Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Git history check workflow #4

Merged
merged 1 commit into from
Apr 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions .github/workflows/check_history.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: Check Git history
on:
pull_request:
types: [opened, reopened, synchronize]

jobs:
check_uses_latest_main:
if: ${{ github.event.pull_request.base.ref == 'main' }}
name: 'Check if PR is based on latest main'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }} # ensure we get the actual PR HEAD and not the merged result
fetch-depth: 0 # ensure the complete Git history is available

- name: Test if main has any commits not on this branch
shell: bash
run: |
COMMIT_COUNT=$(git log --oneline HEAD..origin/main | wc -l)
if [[ $COMMIT_COUNT -gt 0 ]]
then
echo
echo "There are $COMMIT_COUNT commits on main that are not on this branch."
echo
echo "Please rebase ${{ github.event.pull_request.head.ref }} onto origin/main"
echo
echo "Hint: this can also be done via the GitHub UI at ${{ github.event.pull_request.html_url }}"
echo
exit 1
fi
check_linear_history:
if: ${{ github.event.pull_request.base.ref == 'main' }}
name: 'Check if PR has a linear history without merges'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }} # ensure we get the actual PR HEAD and not the merged result
fetch-depth: 0 # ensure the complete Git history is available

- name: Test if PR HEAD contains any merge commits
shell: bash
run: |
MERGE_COMMIT_COUNT=$(git log --oneline --merges origin/main..HEAD | wc -l)
if [[ $MERGE_COMMIT_COUNT -gt 0 ]]
then
echo
echo "There are $MERGE_COMMIT_COUNT merge commits on this branch."
echo
echo "Please rebase ${{ github.event.pull_request.head.ref }} onto origin/main to get rid of these merges."
echo
exit 1
fi
check_has_no_fixups:
name: 'Check if PR has any fixup! or WIP commits'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }} # ensure we get the actual PR HEAD and not the merged result
fetch-depth: 0 # ensure the complete Git history is available

- name: Test if PR HEAD contains any commits starting with "!fixup" or "WIP"
shell: bash
run: |
COMMIT_COUNT=$(git log --oneline --format="%s" origin/main..HEAD | grep -E '^(fixup!|WIP)' | wc -l || true)
if [[ $COMMIT_COUNT -gt 0 ]]
then
echo
echo "There are $COMMIT_COUNT commits marked as WIP or fixup! on this branch."
echo
echo "Please fix the description of the WIP commits and do an interactive rebase of "
echo "${{ github.event.pull_request.head.ref }} onto origin/main to get rid of the fixup! commits."
echo
exit 1
fi