Skip to content

Commit 31f38b1

Browse files
committed
Testing single-commit action
1 parent cfc69c6 commit 31f38b1

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Check single commit
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened, ready_for_review]
6+
7+
jobs:
8+
check-single-commit:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Count commits in PR
12+
id: commits
13+
run: |
14+
PR_NUMBER=${{ github.event.pull_request.number }}
15+
REPO_OWNER=${{ github.repository_owner }}
16+
REPO_NAME=${{ github.event.repository.name }}
17+
18+
COMMIT_COUNT=$(curl -s \
19+
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
20+
-H "Accept: application/vnd.github+json" \
21+
"https://api.github.com/repos/$REPO_OWNER/$REPO_NAME/pulls/$PR_NUMBER/commits" \
22+
| jq '. | length')
23+
24+
echo "commit_count=$COMMIT_COUNT" >> $GITHUB_OUTPUT
25+
26+
- name: Enforce single commit
27+
run: |
28+
if [ "${{ steps.commits.outputs.commit_count }}" -gt 1 ]; then
29+
echo "❌ PR has more than one commit (${{
30+
steps.commits.outputs.commit_count }})"
31+
exit 1
32+
else
33+
echo "✅ PR has a single commit"
34+
fi

test.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This is the second commit and should trigger the single commit check to fail.

0 commit comments

Comments
 (0)