-
Notifications
You must be signed in to change notification settings - Fork 0
32 lines (31 loc) · 1.15 KB
/
check_single_commit.yml
File metadata and controls
32 lines (31 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
name: Check Single Commit, fails if a PR contains more than one commit to encourage squashing commits before merging.
run-name: Check Single Commit
on:
workflow_call:
jobs:
check-single-commit:
name: Check Single Commit
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Check number of commits in PR
uses: actions/github-script@v8
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const pr = context.payload.pull_request;
if (!pr && !(github.head_ref == 'develop' && github.base_ref == 'main')) {
console.log("Not a pull request event. Skipping commit check.");
return;
}
const commits = await github.rest.pulls.listCommits({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: pr.number,
});
const count = commits.data.length;
if (count > 1) {
core.setFailed(`PR has ${count} commits. Please squash to a single commit.`);
} else {
console.log("PR has a single commit. ✅");
}