diff --git a/.github/workflows/check-single-commit.yml b/.github/workflows/check-single-commit.yml new file mode 100644 index 000000000000..e3f909f2e566 --- /dev/null +++ b/.github/workflows/check-single-commit.yml @@ -0,0 +1,34 @@ +name: Check single commit + +on: + pull_request: + types: [opened, synchronize, reopened, ready_for_review] + +jobs: + check-single-commit: + runs-on: ubuntu-latest + steps: + - name: Count commits in PR + id: commits + run: | + PR_NUMBER=${{ github.event.pull_request.number }} + REPO_OWNER=${{ github.repository_owner }} + REPO_NAME=${{ github.event.repository.name }} + + COMMIT_COUNT=$(curl -s \ + -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ + -H "Accept: application/vnd.github+json" \ + "https://api.github.com/repos/$REPO_OWNER/$REPO_NAME/pulls/$PR_NUMBER/commits" \ + | jq '. | length') + + echo "commit_count=$COMMIT_COUNT" >> $GITHUB_OUTPUT + + - name: Enforce single commit + run: | + if [ "${{ steps.commits.outputs.commit_count }}" -gt 1 ]; then + echo "❌ PR has more than one commit (${{ + steps.commits.outputs.commit_count }})" + exit 1 + else + echo "✅ PR has a single commit" + fi diff --git a/test.adoc b/test.adoc new file mode 100644 index 000000000000..74214361a79b --- /dev/null +++ b/test.adoc @@ -0,0 +1 @@ +This is again a second commit and should trigger the single commit check to fail. \ No newline at end of file