Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to run commitlint in GitHub workflow on every commit of a push #2568

Closed
2 of 4 tasks
obviouslynotthedarklord opened this issue Apr 29, 2021 · 5 comments
Closed
2 of 4 tasks
Labels

Comments

@obviouslynotthedarklord
Copy link

obviouslynotthedarklord commented Apr 29, 2021

I 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.

image

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

image

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
@escapedcat
Copy link
Member

Is this related to #586?

@obviouslynotthedarklord
Copy link
Author

@escapedcat yes, I think so.

I created my workflow based on this question

https://stackoverflow.com/questions/64708371/how-to-run-github-workflow-on-every-commit-of-a-push

and I think I almost got it, I just need to fix my syntax but don't know how ...

@obviouslynotthedarklord
Copy link
Author

@escapedcat I updated my question, maybe this helps :)

@matthiashermsen
Copy link

I think this comment provides a solution

#586 (comment)

so your command should be

npx commitlint --from HEAD~${{ github.event.pull_request.commits }} --to HEAD --verbose

@knocte
Copy link
Contributor

knocte commented Sep 11, 2022

so your command should be

         for commit in $(git rev-list ${{ github.base_ref }}..${{
         github.head_ref }}); do
             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:

run: |
  echo 'Going to run commitlint for ${{ github.event.pull_request.commits }} commits'
  npx commitlint --from ${{ github.event.pull_request.head.sha }}~${{ github.event.pull_request.commits }} --to ${{ github.event.pull_request.head.sha }} --verbose

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

4 participants