Add .github/workflows/check-based-on-master (#1991)

This commit is contained in:
Dima Lazerka 2021-12-21 20:27:41 +02:00 committed by GitHub
parent 9bb7905d26
commit 06cf4e0f70
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 0 deletions

12
.github/workflows/check-based-on-master.sh vendored Executable file
View file

@ -0,0 +1,12 @@
#!/usr/bin/env bash
set -x -e
MASTER_ID=$(git rev-parse "origin/master")
CURRENT_ID=$(git rev-parse "HEAD")
BASED_ON_ID=$(git merge-base "$CURRENT_ID" "$MASTER_ID")
if [[ "$MASTER_ID" != "$BASED_ON_ID" ]]
then
echo "Current branch is based on $BASED_ON_ID, which is not the latest \`master\`: $MASTER_ID. Consider \`git rebase origin/master\`."
exit 1
fi

View file

@ -0,0 +1,18 @@
name: check-based-on-master
on:
pull_request:
push:
branches: [ master ]
jobs:
hook:
name: Check whether this branch is based on master branch
runs-on: ubuntu-latest
steps:
- name: Check out repo @ current branch
uses: actions/checkout@v2
with:
fetch-depth: 1000 # Hopefully current branch is less than 1000 commits from main
- name: Fetch origin/master
run: "git fetch origin master"
- name: Run check-based-on-master
run: .github/workflows/check-based-on-master.sh