Skip to content

Commit 30da4ad

Browse files
committed
ci: improve commit lint
1 parent 454fe71 commit 30da4ad

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

.github/workflows/commitlint.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Commit Lint
2+
3+
on:
4+
pull_request_target:
5+
types: [opened, reopened, synchronize]
6+
7+
jobs:
8+
commitlint:
9+
if: github.event_name == 'pull_request_target'
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v4
13+
with:
14+
fetch-depth: 0
15+
- name: Fetch PR head
16+
run: git fetch origin pull/${{ github.event.pull_request.number }}/head:pr_head
17+
- name: Run commitlint
18+
run: |
19+
merge_base_sha=$(git merge-base HEAD pr_head)
20+
first_commit_sha=$(git rev-list --no-merges --reverse $merge_base_sha..pr_head | head -n 1)
21+
22+
if [ -z "$first_commit_sha" ]; then
23+
echo "Could not determine the first commit of the PR. Skipping."
24+
exit 0
25+
fi
26+
27+
commit_message=$(git log -1 --pretty=%B $first_commit_sha)
28+
# we can't use npx see https://github.com/conventional-changelog/commitlint/issues/613
29+
echo '{}' > package.json
30+
npm install --no-fund --no-audit @commitlint/config-conventional @commitlint/cli
31+
echo "$commit_message" | ./node_modules/.bin/commitlint -g .commitlintrc
32+

0 commit comments

Comments
 (0)