Skip to content

Commit 84b8b38

Browse files
authored
chore(ci): add conventional commits check (#12)
1 parent 8fa4ede commit 84b8b38

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

.github/workflows/pr_title.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: PR Title Check
2+
3+
on:
4+
pull_request_target:
5+
types: [opened, edited, synchronize, reopened]
6+
jobs:
7+
commitlint:
8+
name: PR title / description conforms to semantic-release
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/setup-node@v3
12+
with:
13+
node-version: "18"
14+
- run: npm install @commitlint/config-conventional
15+
- run: >
16+
echo 'module.exports = {
17+
// Workaround for https://github.com/dependabot/dependabot-core/issues/5923
18+
"ignores": [(message) => /^Bumps \[.+]\(.+\) from .+ to .+\.$/m.test(message)]
19+
}' > .commitlintrc.js
20+
- run: npx commitlint --extends @commitlint/config-conventional --verbose <<< $COMMIT_MSG
21+
env:
22+
COMMIT_MSG: >
23+
${{ github.event.pull_request.title }}
24+
25+
${{ github.event.pull_request.body }}
26+
- if: failure()
27+
uses: actions/github-script@v6
28+
with:
29+
script: |
30+
const message = `**ACTION NEEDED**
31+
32+
Substrait follows the [Conventional Commits
33+
specification](https://www.conventionalcommits.org/en/v1.0.0/) for
34+
release automation.
35+
36+
The PR title and description are used as the merge commit message.\
37+
Please update your PR title and description to match the specification.
38+
`
39+
// Get list of current comments
40+
const comments = await github.paginate(github.rest.issues.listComments, {
41+
owner: context.repo.owner,
42+
repo: context.repo.repo,
43+
issue_number: context.issue.number
44+
});
45+
// Check if this job already commented
46+
for (const comment of comments) {
47+
if (comment.body === message) {
48+
return // Already commented
49+
}
50+
}
51+
// Post the comment about Conventional Commits
52+
github.rest.issues.createComment({
53+
owner: context.repo.owner,
54+
repo: context.repo.repo,
55+
issue_number: context.issue.number,
56+
body: message
57+
})
58+
core.setFailed(message)

0 commit comments

Comments
 (0)