-
-
Notifications
You must be signed in to change notification settings - Fork 34
61 lines (49 loc) · 2.31 KB
/
lint-commit.yml
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
name: Lint commit messages
on: pull_request_target
jobs:
lint_commits:
runs-on: ubuntu-latest
if: always() && github.repository == 'oddlama/vane'
steps:
- uses: actions/[email protected]
with:
fetch-depth: 0
persist-credentials: false
ref: ${{ github.event.pull_request.head.sha }}
- uses: actions/[email protected]
with:
node-version: 16
- run: |
# Setup commitlint
if ! yarn add {ts-node, @commitlint/{config-conventional,cli}} >> /dev/null 2>&1; then
exit 0
fi
echo "module.exports = {extends: ['@commitlint/config-conventional']}" > commitlint.config.js
# Get the PR commits
FIRST_COMMIT_SHA=$(curl -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" ${{ github.event.pull_request.commits_url }} | jq -r '.[0].sha')
commit_log=$(git log $FIRST_COMMIT_SHA^...HEAD --pretty=format:"%s")
readarray -t commits <<<"$commit_log"
errors=()
for commit in "${commits[@]}"; do
if ! echo $commit | yarn -s run commitlint -q; then
errors+=( "$commit" )
fi
done
if (( ${#errors[@]} )); then
printf "One or more of the commits in this PR do not follow the Conventional Commits style:\n\n"
for error in "${errors[@]}"; do
echo "$error"
done
echo "CONTAINS_ERRORS=1" >> $GITHUB_ENV
exit 1
else
exit 0
fi
- name: Comment on PR
if: ${{ failure() && env.CONTAINS_ERRORS == '1' && !github.event.pull_request.draft }}
uses: thollander/actions-comment-pull-request@v1
with:
message: |
Hello!
One or more of the commits in this PR do not follow the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) style. See the `lint_commits` job for more details. Please modify your commit message(s) with [git commit --amend](https://docs.github.com/en/pull-requests/committing-changes-to-your-project/creating-and-editing-commits/changing-a-commit-message) and force push those changes to update this PR.
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}