From f6262411e2d6c3808f3d231dfff641523d83d381 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20Mac=C3=ADk?= Date: Mon, 21 Mar 2022 19:35:31 +0100 Subject: [PATCH] Add check for single commit PR (#1120) --- .github/workflows/pr-checks.yaml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/.github/workflows/pr-checks.yaml b/.github/workflows/pr-checks.yaml index 1846cb274a..c000a2edbb 100644 --- a/.github/workflows/pr-checks.yaml +++ b/.github/workflows/pr-checks.yaml @@ -283,3 +283,22 @@ jobs: name: kubernetes-without-olm-test-results path: ${{ env.TEST_RESULTS }} if: always() + + single-commit: + name: Single commit PR + runs-on: ubuntu-20.04 + + steps: + - name: Checkout Git Repository + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Verify number of commits in the PR is 1 + run: | + COMMIT_COUNT="$(git log --oneline ${{github.event.pull_request.base.sha}}..${{github.event.pull_request.head.sha}} | wc -l)" + if ! [ $COMMIT_COUNT -eq 1 ]; then + echo "Number of commits in the PR ($COMMIT_COUNT) must not be greater than one." + echo "Please squash all PR commits into a single one (https://git-scm.com/book/en/v2/Git-Tools-Rewriting-History#_squashing)" + exit 1 + fi