From b7c5b1ea2e3d99c141503a6474d089056f8b99d6 Mon Sep 17 00:00:00 2001 From: Xavier Chapron Date: Thu, 21 Dec 2023 15:48:18 +0100 Subject: [PATCH] CI: Add workflow to enforce rebase before merge --- .github/workflows/force-rebase.yml | 33 ++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 .github/workflows/force-rebase.yml diff --git a/.github/workflows/force-rebase.yml b/.github/workflows/force-rebase.yml new file mode 100644 index 000000000..8d53e94f3 --- /dev/null +++ b/.github/workflows/force-rebase.yml @@ -0,0 +1,33 @@ +name: Force rebased + +on: [pull_request] + +jobs: + force-rebase: + runs-on: ubuntu-latest + steps: + - name: 'PR commits + 1' + run: echo "PR_FETCH_DEPTH=$(( ${{ github.event.pull_request.commits }} + 1 ))" >> "${GITHUB_ENV}" + + - name: 'Checkout PR branch and all PR commits' + uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.head.sha }} + fetch-depth: ${{ env.PR_FETCH_DEPTH }} + + - name: Show git log + shell: bash + run: | + git log + + - name: Check if branch is up-to-date + shell: bash + run: | + git merge-base --is-ancestor ${{ github.event.pull_request.base.sha }} HEAD + + - name: Check for merge commits + shell: bash + run: | + merges=$(git log --oneline HEAD~${{ github.event.pull_request.commits }}...HEAD --merges ); \ + echo "--- Merges ---\n${merges}"; \ + [ -z "${merges}" ]