-
Notifications
You must be signed in to change notification settings - Fork 913
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
docs: fix github actions ci example #3892
docs: fix github actions ci example #3892
Conversation
@letsaguiar sorry if the above review comes off as harsh, PRs upgrading documentation are appreciated! thanks for cooking this PR |
Don't worry, thank you for the insights :D I've updated the PR according to your requests |
git --version | ||
node --version | ||
npm --version | ||
npx commitlint --version |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@letsaguiar and why dont you like printing versions 😭 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Short answer: I don't think it's useful since we already know which version of git comes with Ubuntu 22.04 and which version of node we're installing
Long answer: an unnecessary step makes the pipeline slow and increase the cloud costs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
those points apply to git and node, but not to the other 2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
btw, your long answer is shorter than your short answer 😆
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But the meaning is deeper haha
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm going to revert it :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sounds good
run: | | ||
npm install conventional-changelog-conventionalcommits | ||
npm install commitlint@latest | ||
run: npm install --global @commitlint/{cli,config-conventional} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@letsaguiar are you sure this syntax is correct? I've tried it myself in a repo of mine because I thought it would be nice to adopt it, and I'm getting this error:
Run npm install --global @commitlint/{cli,config-conventional}
npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path /__w/conventions/conventions/@commitlint/{cli,config-conventional}/package.json
npm ERR! errno -2
npm ERR! enoent ENOENT: no such file or directory, open '/__w/conventions/conventions/@commitlint/{cli,config-conventional}/package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! A complete log of this run can be found in: /github/home/.npm/_logs/202[4](https://github.com/knocte/conventions/actions/runs/7771223169/job/21192285282#step:6:5)-02-04T02_[5](https://github.com/knocte/conventions/actions/runs/7771223169/job/21192285282#step:6:6)[9](https://github.com/knocte/conventions/actions/runs/7771223169/job/21192285282#step:6:10)_54_919Z-debug-0.log
Error: Process completed with exit code 254.
(conventions
is the name of my repo btw)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting thing is that the above syntax works when you're running your CI job without a container:
attribute, but fails with the above message when using container:
(a docker image). I have no idea why this happens. But this needs to be reverted from the PR in case the commitlint user reading the documentation is using container images instead of default github VMs.
I just reproduced this problem myself, and the culprit is actually because the git repository only has 1 commit (the initial commit). In this case, walking backwards to HEAD~1 may not be supported. Are we sure the |
So, the workaround is just push a 2nd commit, and then it works. |
Are we good here? |
Not yet, she said she would revert something which she didn't yet; and after that I raised 2 concerns. |
I've also been thinking about changing the GitHub Actions CI example in this repo. Fortunately, before contributing, I checked existing PRs. It's awesome to find other contributors working on the same issue! 🚀 - name: Validate commits
if: contains(fromJSON('["push", "pull_request"]'), github.event_name)
env:
FROM: ${{ github.event.before || github.event.pull_request.base.sha }}
TO: ${{ github.event.after || github.event.pull_request.head.sha }}
run: npx commitlint --from $FROM --to $TO --verbose This
We can also recommend installing |
Very interesting! Do you know if it works also on repos with just 1 commit? |
Sure, I've tested this step on one of my projects, and it works in all scenarios, including a single commit. |
Are you 100% sure? I haven't tested it yet but AFAIU in a single-commit scenario both $FROM and $TO would map to the same commit hash, which then would make commit-lint not crash (which, granted, is better than crashing) but would actually not do anything, at least according to this bug that I filed some months ago: #3376 |
I can confirm that the |
Thanks for your input @viveleroi ; the problem I have with that solution is that it may work for a |
I'm just starting this repo so I've only been using pushes. That fix solved pushes for me. I know the ref has the |
But I guess the issue was only happening when the repo had one single commit, right? |
Do you mean the push or the entire repo? I was pushing to a relatively new repo. It had one commit already when I first added an action, but didn't include commitlint in that work. So by the time I pushed this commitlint action I had 2 commits in the repo, 1 commit in my push. The action failed. I pushed again with the fix above and it succeeded - with 3 commits in the repo and and 1 push. None of these were via PR |
From the GitHub Actions documentation, |
@primeare if you say your cropped screenshot comes from an execution on a repo that only has 1 commit, then why are there 2 commit hashes? |
Sorry, @knocte, I misunderstood you. I tested this workflow with the initial single commit, and you are right. It does not work because GitHub Actions uses zero commit hash as a |
Also, my proposed workflow step does not work with force push: GitHub Actions provide the hash of the previous commit in |
In a single-commit repo, this would lead to this error: ``` Error: fatal: ambiguous argument 'HEAD~1..HEAD': unknown revision or path not in the working tree. ``` Now that we have the `--last` flag, this should work for the case in which we want just to analyze the last commit, not specify a range of commits via `--from` and `--to`. Closes conventional-changelog#3892
Mmm, how about this other idea (which looks cleaner to me): |
Rather use more straightforward package names, as advised in [1] and [2]. [1] conventional-changelog/commitlint#3892 [2] Kochava/github-workflows#30
Rather use more straightforward package names, as advised in [1] and [2]. [1] conventional-changelog/commitlint#3892 [2] Kochava/github-workflows#30
In a single-commit repo, this would lead to this error: ``` Error: fatal: ambiguous argument 'HEAD~1..HEAD': unknown revision or path not in the working tree. ``` Now that we have the `--last` flag, this should work for the case in which we want just to analyze the last commit, not specify a range of commits via `--from` and `--to`. Closes conventional-changelog#3892
In a single-commit repo, this would lead to this error: ``` Error: fatal: ambiguous argument 'HEAD~1..HEAD': unknown revision or path not in the working tree. ``` Now that we have the `--last` flag, this should work for the case in which we want just to analyze the last commit, not specify a range of commits via `--from` and `--to`. Closes conventional-changelog#3892
In a single-commit repo, this would lead to this error: ``` Error: fatal: ambiguous argument 'HEAD~1..HEAD': unknown revision or path not in the working tree. ``` Now that we have the `--last` flag, this should work for the case in which we want just to analyze the last commit, not specify a range of commits via `--from` and `--to`. Closes conventional-changelog#3892
In a single-commit repo, this would lead to this error: ``` Error: fatal: ambiguous argument 'HEAD~1..HEAD': unknown revision or path not in the working tree. ``` Now that we have the `--last` flag, this should work for the case in which we want just to analyze the last commit, not specify a range of commits via `--from` and `--to`. Closes conventional-changelog#3892
In a single-commit repo, this would lead to this error: ``` Error: fatal: ambiguous argument 'HEAD~1..HEAD': unknown revision or path not in the working tree. ``` Now that we have the `--last` flag, this should work for the case in which we want just to analyze the last commit, not specify a range of commits via `--from` and `--to`. Closes conventional-changelog#3892
) * test(cli): add regression test * feat(cli): implement new `--last` CLI flag The upgrade of ES2017 to ES2022 is because of the use of `Object.hasOwn` API which is less ugly than hardcoding `undefined`. * docs(ci): stop recommending HEAD~1 In a single-commit repo, this would lead to this error: ``` Error: fatal: ambiguous argument 'HEAD~1..HEAD': unknown revision or path not in the working tree. ``` Now that we have the `--last` flag, this should work for the case in which we want just to analyze the last commit, not specify a range of commits via `--from` and `--to`. Closes #3892 * fix: use --pretty=format:"%B" instead of --pretty=%B The latter adds unnecessary whitespace at the end of the commit msg. --------- Co-authored-by: Mehrshad <code.rezaei@gmail.com>
Description
This PR updates the github actions CI example. The previous one doesn't works by itself and has some unnecessary steps, so these changes turns the example CI more solid and developer friendly.
Motivation and Context
When I try to run the provided github CI example in a personal project it always returns the following error:
This happens because we have to manually checkout the repository with the ref tag on actions/checkout actions. Otherwise, there is going to be no HEAD in the container running our pipeline. This is the main change.
How Has This Been Tested?
I've used the exact same implementation on a personal project and it worked
Types of changes
Checklist: