How to run commitlint in GitHub workflow on every commit of a push
See original GitHub issueI created a new Github repository and followed https://commitlint.js.org/#/guides-local-setup. After that I created this workflow
name: Run commitlint on pull request
'on': pull_request
jobs:
run-commitlint-on-pull-request:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Setup Node
uses: actions/setup-node@v2
with:
node-version: 14.x
- name: Install dependencies
run: npm install
- name: Validate all commits from PR
run: >
for commit in $(git rev-list ${{ github.base_ref }}..${{
github.head_ref }}); do
npx commitlint --from $commit --to HEAD --verbose
done
to validate each commit message in a PR. I created a new branch and made a change 3 times with the following commit messages:
- invalid one
- feat: valid two
- invalid three
Expected Behavior
I would expect that commit message 1 and 3 are invalid so the workflow rejects the pull request.
Current Behavior
Unfortunately the validation passes.
I also tried this
run: npx commitlint --from ${{ github.base_ref }} --to ${{ github.head_ref }} --verbose
This time the workflow didn’t pass but the output result is wrong
Affected packages
- cli
- core
- prompt
- config-angular
Possible Solution
As shown in the image I think my syntax is wrong and needs to get fixed.
Steps to Reproduce (for bugs)
- Create a new Github repository
- Clone it
- Setup npm
- Setup commitlint with husky as shown in the docs
- Create a Github workflow (take my code from above)
- Push everything
- Create a new branch
- Make some changes with valid and invalid commit messages
- Create a PR
- The PR should get rejected by the workflow but it passes
Context
I would like to validate each commit message from commits in a PR
Your Environment
Executable | Version |
---|---|
commitlint/cli --version |
12.1.1 |
commitlint/config-conventional --version |
12.1.1 |
git --version |
2.25.1 |
node --version |
14 |
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:5
Top Results From Across the Web
How to run commitlint in GitHub workflow on every commit of a ...
Solution. The straight-forward solution is to use the --to and --from arguments of commitlint with the SHA-1 values instead of the branch ...
Read more >Lints Pull Request commits with commitlint - the Github Action
Lints Pull Request commits with commitlint. Usage. Create a github workflow in the .github folder, e.g. .github/workflows/commitlint.yml ...
Read more >Document use of commitlint as a github action (possible own ...
Provide a github actions cli just like commitlint-travis . Context. It should easy setup for running commitlint as part of a github actions ......
Read more >commitlint-github-action fails yet commitlint cli passes? #57
But if I run commitlint's CLI directly on my branch, then we get no errors: $ commitlint -f main -t HEAD --config commitlint.config.js...
Read more >How lint every single commit in a PR? · Issue #36 - GitHub
Run wagoid/commitlint-github-action@v15s Run ... name: On Pull Request on: [pull_request] jobs: lint-commit: runs-on: ubuntu-latest steps: ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I think this comment provides a solution
https://github.com/conventional-changelog/commitlint/issues/586#issuecomment-657226800
so your command should be
npx commitlint --from HEAD~${{ github.event.pull_request.commits }} --to HEAD --verbose
That didn’t work for me.
I had to tweak it to this: