@@ -2,24 +2,18 @@ name: Validate Commit Messages
22
33permissions :
44 contents : read
5- pull-requests : write
6- issues : write
75
86on :
9- pull_request_target :
7+ pull_request :
108 types : [opened, edited, synchronize]
119
1210jobs :
1311 commitlint :
1412 runs-on : ubuntu-latest
15- # Security: Only run on events we trust (not from untrusted forks doing malicious things)
16- if : github.event_name == 'pull_request_target' && github.event.action != 'closed'
1713 steps :
1814 - name : Checkout code
1915 uses : actions/checkout@v4
2016 with :
21- # For pull_request_target, we need to explicitly checkout the PR head
22- ref : ${{ github.event.pull_request.head.sha }}
2317 fetch-depth : 0
2418
2519 - name : Setup Node.js
@@ -31,86 +25,13 @@ jobs:
3125 - name : Install dependencies
3226 run : npm ci
3327
34- - name : Validate current commit (last commit)
35- id : commitlint-last
36- run : npx commitlint --from HEAD~1 --to HEAD --verbose
37- continue-on-error : true
38-
3928 - name : Validate all commits in PR
40- id : commitlint-pr
41- run : npx commitlint --from ${{ github.event.pull_request.base.sha }} --to HEAD --verbose
42- continue-on-error : true
43-
44- - name : Comment PR with commit guidelines (on failure)
45- if : steps.commitlint-last.outcome == 'failure' || steps.commitlint-pr.outcome == 'failure'
46- uses : actions/github-script@v7
47- continue-on-error : true
48- with :
49- script : |
50- try {
51- const message = `## 🚨 Commit Message Validation Failed
52-
53- Your commit messages don't follow our conventional commit format. Here's what you need to know:
54-
55- ### ✅ Valid Commit Format
56- \`\`\`
57- <type>(<scope>): <description>
58-
59- [optional body]
60-
61- [optional footer(s)]
62- \`\`\`
63-
64- ### 📋 Required Elements
65- - **type**: The kind of change (feat, fix, docs, style, refactor, test, chore, etc.)
66- - **scope**: The module affected (optional but recommended - can be auto-detected)
67- - **description**: A short description of the change (lowercase, no period at the end)
68-
69- ### 🎯 Examples of Good Commits
70- \`\`\`
71- feat(cli): add semantic versioning support
72- fix(shared): resolve validation error for empty schemas
73- docs: update installation instructions
74- chore(deps): update typescript to version 5.8.3
75- test(cli): add unit tests for version command
76- \`\`\`
77-
78- ### 🔄 Why We Use Conventional Commits
79- - **Automated Versioning**: We use semantic-release to automatically determine version bumps
80- - **Changelog Generation**: Commit messages become our release notes
81- - **Better Collaboration**: Clear, consistent commit history helps everyone understand changes
82- - **Selective Releases**: Only CLI-scoped commits trigger CLI releases
83- - **Scope Auto-detection**: We provide tools to help detect the right scope from your changes
84-
85- ### 🛠️ How to Fix
86- 1. **Rewrite your commit messages** using \`git rebase -i\`
87- 2. **Use the correct format** shown above
88- 3. **Consider adding scope** for better organization (use \`./commit-helper.sh\` for suggestions)
89- 4. **Keep descriptions lowercase** and without trailing periods
90-
91- ### 🔧 Version Impact (CLI only)
92- - \`fix(cli):\` → PATCH release (1.0.1)
93- - \`feat(cli):\` → MINOR release (1.1.0)
94- - \`feat(cli)!:\` or \`BREAKING CHANGE:\` → MAJOR release (2.0.0)
95- - \`fix(shared):\` → No CLI release (affects shared module only)
96-
97- Please update your commits and push again. Thank you! 🙏`;
98-
99- await github.rest.issues.createComment({
100- issue_number: context.issue.number,
101- owner: context.repo.owner,
102- repo: context.repo.repo,
103- body: message
104- });
105-
106- console.log('✅ Successfully posted commit guidelines comment');
107- } catch (error) {
108- console.log('⚠️ Could not post comment (likely permissions issue):', error.message);
109- console.log('📋 Commit validation failed - see job logs for details');
110- }
111-
112- - name : Fail workflow if commitlint failed
113- if : steps.commitlint-last.outcome == 'failure' || steps.commitlint-pr.outcome == 'failure'
29+ run : |
30+ echo "� Validating commit messages from base branch to HEAD..."
31+ npx commitlint --from ${{ github.event.pull_request.base.sha }} --to HEAD --verbose
32+
33+ - name : Display validation summary
34+ if : failure()
11435 run : |
11536 echo "## 🚨 Commit Message Validation Failed" >> $GITHUB_STEP_SUMMARY
11637 echo "" >> $GITHUB_STEP_SUMMARY
12748 echo "### 🛠️ How to Fix" >> $GITHUB_STEP_SUMMARY
12849 echo "1. Use \`git rebase -i\` to rewrite commit messages" >> $GITHUB_STEP_SUMMARY
12950 echo "2. Follow the format: \`<type>(<scope>): <description>\`" >> $GITHUB_STEP_SUMMARY
130- echo "3. Run \`./commit-helper.sh\` for scope suggestions" >> $GITHUB_STEP_SUMMARY
131- echo "" >> $GITHUB_STEP_SUMMARY
132- exit 1
0 commit comments