forked from finos/architecture-as-code
-
Notifications
You must be signed in to change notification settings - Fork 0
134 lines (109 loc) · 5.45 KB
/
validate-pr-commits.yml
File metadata and controls
134 lines (109 loc) · 5.45 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
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
name: Validate PR Commit Messages
on:
pull_request:
types: [opened, synchronize, reopened]
jobs:
validate-commits:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup Node.js
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
with:
node-version: v22
- name: Install commitlint dependencies
run: |
npm install @commitlint/cli@^19.5.0 @commitlint/config-conventional@^19.5.0
- name: Validate commit messages
run: |
# Get the base branch (usually main)
BASE_SHA=$(git merge-base origin/${{ github.base_ref }} HEAD)
# Validate all commits in the PR
npx commitlint --from $BASE_SHA --to HEAD --verbose
- name: Comment on PR if validation fails
if: failure()
uses: actions/github-script@v7
with:
script: |
const message = `## ❌ Commit Message Validation Failed
Some commit messages in this PR don't follow the [Conventional Commits](https://conventionalcommits.org/) specification.
### Required Format:
\`\`\`
<type>[optional scope]: <description>
[optional body]
[optional footer(s)]
\`\`\`
### Valid Types:
- **feat**: A new feature (triggers a minor release)
- **fix**: A bug fix (triggers a patch release)
- **docs**: Documentation only changes
- **style**: Changes that do not affect the meaning of the code
- **refactor**: A code change that neither fixes a bug nor adds a feature
- **perf**: A code change that improves performance
- **test**: Adding missing tests or correcting existing tests
- **build**: Changes that affect the build system or external dependencies
- **ci**: Changes to our CI configuration files and scripts
- **chore**: Other changes that don't modify src or test files
### Valid Scopes:
- \`cli\`: Changes specific to the CLI package
- \`shared\`: Changes to shared utilities
- \`calm\`: Changes to the CALM spec
- \`calm-widgets\`: Changes to the widgets package
- \`calm-hub\`: Changes to the hub backend
- \`calm-hub-ui\`: Changes to the hub frontend
- \`docs\`: Changes to documentation
- \`workspace\`: Changes affecting the entire workspace
### Examples:
- \`feat(cli): add new validation command\`
- \`fix(shared): resolve parsing issue with YAML files\`
- \`docs: update README with installation instructions\`
- \`feat!: remove deprecated API endpoints\` (breaking change)
### For Breaking Changes:
Add \`!\` after the type or include \`BREAKING CHANGE:\` in the commit footer.
Please update your commit messages to follow this format. You can use \`git rebase -i\` to edit commit messages, or squash commits and create new ones with proper formatting.
You can also use \`npm run commit\` in the repository to get guided commit message creation.`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: message
});
- name: Comment on PR if validation succeeds
if: success()
uses: actions/github-script@v7
with:
script: |
const message = `## ✅ Commit Message Validation Passed
All commit messages in this PR follow the [Conventional Commits](https://conventionalcommits.org/) specification. Great job! 🎉
This means semantic-release will be able to properly analyze the changes and determine the appropriate version bump when this PR is merged.`;
// Check if we already commented on this PR
const comments = await github.rest.issues.listComments({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
});
const existingComment = comments.data.find(comment =>
comment.body.includes('Commit Message Validation') &&
comment.user.type === 'Bot'
);
if (existingComment) {
// Update existing comment
await github.rest.issues.updateComment({
comment_id: existingComment.id,
owner: context.repo.owner,
repo: context.repo.repo,
body: message
});
} else {
// Create new comment
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: message
});
}