Provide a github actions cli just like commitlint-travis.
It should easy setup for running commitlint as part of a github actions setup.
Yes, a Github action would be cool. Want to lend a hand with this?
I made this but have no idea if it works, since i'm not in the beta
Nice, I can give it a try.
Added you to the repo. Do your worst 馃拑
I'm accepted in the beta, so whatever happens, I can try it out too 馃槃 Also building some actions for Expo, but ran into some issues and trying to fix it with the GH team.
I think we also need to discuss where this will be hosted. We can do something like conventional-changelog/commitlint-action, I would be happy to submit it (officially) to the marketplace too! What do you guys think @marionebl @escapedcat?
As a small side note, I would definitely recommend using the _full LTS node_ version (node:10).
With these two minor, but good changes, the action covers more edge cases. I believe that was the main purpose of actions, make it simple and easy to use for everyone.
Or do you have a different opinion about this @bennypowers?
Agreed, I think it would be nice to have actions for CI environments.
I think we should solve #613 and zero config before doing this right? That way, we can simply create an action with everything set to default. If projects have their own conventions, they simply need to add a npm install action before the commitlint action. Personally, I think this is the best approach for the actions. Or am I overthinking this?
@byCedric I have no strong opinion regarding node versions. probably newer is better. I can add you to the repo also
Thanks! I'm trying to help out the guys at global-dirs, they make awesome reports on the issues (worth reading 馃槈). If this is resolved, I'll get started on the zero-config and this!
Ok, I published this
https://github.com/marketplace/actions/commitlint-cli
Haven't tried it out just yet 馃檲
I've created a github action for this that doesn't require any setup, if you want to have a look: https://github.com/marketplace/actions/commit-linter
I tried using @bennypowers's action but got some issues and ended up creating another one, as explained here
I am already using in some projects, feel free to use it too and let me know if anything goes wrong :smiley:
I think you can also just call @commitlint/cli for this and get number of commits from PR event commitlint --from HEAD~${{ github.event.pull_request.commits }} --to HEAD and fetch all commits in checkout fetch-depth: 0. Here is full example:
on: [pull_request]
jobs:
lint-commits:
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
with:
# we actually need "github.event.pull_request.commits + 1" commit
fetch-depth: 0
- uses: actions/[email protected]
# or just "yarn" if you depend on "@commitlint/cli" already
- run: yarn add @commitlint/cli
- run: yarn run commitlint --from HEAD~${{ github.event.pull_request.commits }} --to HEAD
I was looking to lint all commit messages of a pull request and ended up using these steps:
# https://github.com/actions/checkout
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
persist-credentials: false
ref: ${{ github.event.pull_request.head.sha }}
- name: lint
run: |
FIRST_COMMIT_SHA=$(curl -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" ${{ github.event.pull_request.commits_url }} | jq -r '.[0].sha')
npm ci
npx commitlint --from $FIRST_COMMIT_SHA^
The above step:
P.S authentication to the comments API is facilitated by the built in secret -> ${{ secrets.GITHUB_TOKEN }}
@eladchen very creative. Any reason you couldn't use the solution recommended by @arznaar and avoid the curl command?
@arznaar can you help me better understand the need for fetch-depth: 0 and how that relates to your PR commit comment? What happends if you don't include that?
@eladchen very creative. Any reason you couldn't use the solution recommended by @arznaar and avoid the
curlcommand?
@ericis
His solution will only be covering the last 20 commits, as that is a hard limit in the event payload
@ericis
can you help me better understand the need for fetch-depth: 0
As we lint the whole PR history, we usually need more than 1 commit and in their readme, action/checkout fetches only one commit (https://github.com/actions/checkout/blob/592cf69a223b04e75ddf345919130b91010eb2a6/README.md):
Only a single commit is fetched by default, for the ref/SHA that triggered the workflow. Set fetch-depth: 0 to fetch all history for all branches and tags
Not sure why my solution above would be limited to 20 commits, as I specifically avoid it by using HEAD~<numberOfCommits> from event to calculate PR source and it's strange that this number would be limited somehow. Looks like I need to play with it more, thanks @eladchen
Thanks @eladchen. Perhaps I'll just deny PRs with more than 20 commits in them hahah.
Most helpful comment
I've created a github action for this that doesn't require any setup, if you want to have a look: https://github.com/marketplace/actions/commit-linter
I tried using @bennypowers's action but got some issues and ended up creating another one, as explained here
I am already using in some projects, feel free to use it too and let me know if anything goes wrong :smiley: