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 use it in Github Actions? #7

Closed
provokateurin opened this issue Jul 14, 2023 · 10 comments · Fixed by #11
Closed

How to use it in Github Actions? #7

provokateurin opened this issue Jul 14, 2023 · 10 comments · Fixed by #11

Comments

@provokateurin
Copy link

Hi, I'm trying to use commitlint in Github Actions to validate commit messages in the CI. For some reason I can't get it to fail when it should. The current workflow is at nextcloud/neon@a32ce68. I was able to get it working locally with https://github.com/nektos/act when using --from=main --to=@, but that also didn't work on Github Actions. Can someone help me get this working? I'm not sure if the workflow is the problem or if there is a bug in this tool.

@hyiso
Copy link
Owner

hyiso commented Jul 15, 2023

You can see the configuration in this repo https://github.com/hyiso/commitlint/blob/main/.github/workflows/pr_title.yml

@provokateurin
Copy link
Author

That only validates the PR title but I can't get it working with the commit range of the PR

@hyiso
Copy link
Owner

hyiso commented Jul 15, 2023

I've added a Github Action in this repo and created a PR to test it #8.

From The Action Running Log, the problem happened during getting commit messages in Github Action Runner, which seems to be not related to this package:

commitlint:read - from = main, to = feature/validate-pr-commit, edit = null
commitlint:read - git log --format=%B main..feature/validate-pr-commit
commitlint:read - stdout = 
commitlint:read - stderr = fatal: ambiguous argument 'main..feature/validate-pr-commit': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'

@provokateurin
Copy link
Author

Thanks for the investigation. Can we still try to fix it here? I already tried things like fetching the whole repo or pulling the main branch etc.

@provokateurin
Copy link
Author

Can you try

      - uses: actions/checkout@v3
        with:
          fetch-depth: 0

@hyiso
Copy link
Owner

hyiso commented Jul 15, 2023

After several tries, the following configuration works finally:

uses: actions/checkout@v3
        with:
          fetch-depth: 0
          ref: ${{ github.head_ref }}
...
dart run commitlint_cli --from="origin/${{ github.base_ref }}" --to="${{ github.head_ref }}"

You can see the log https://github.com/hyiso/commitlint/actions/runs/5560955537/jobs/10158300171?pr=8

The important parts are checkout with ref and --from with origin/ prefix

@provokateurin
Copy link
Author

Thanks a lot! I'll try it out on my repo. I think ref: ${{ github.head_ref }} is not necessary for this to work.

@provokateurin
Copy link
Author

Ok I was wrong, you need to set ref. It works in my repo too! Maybe you can also add an example to show how to set it up.

@provokateurin
Copy link
Author

It works, but if someone creates a PR from a fork then it doesn't work because the branch can't be found :/

@provokateurin
Copy link
Author

❤️

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

Successfully merging a pull request may close this issue.

2 participants