-
Notifications
You must be signed in to change notification settings - Fork 933
First run in Gitlab CI causes an error #885
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
Comments
This is interesting, thanks for reporting. I think # pseudo code
if [ $CI_BUILD_BEFORE_SHA == "0000000000000000000000000000000000000000" ];
then;
npx commitlint --to=HEAD
else;
npx commitlint --from=$CI_BUILD_BEFORE_SHA;
fi; |
This will fail with a |
|
I can confirm this little script is working as expected in gitlab-ci! |
Since I'm usually creating a new Git repo (about 3/month) and commitlint is one of the first things I set up, I ended up writing a little NPM utility to do it for me.
It seems to work fairly well for me, I've been messing with it for a little while and haven't had too many complaints. |
@dmoonfire nice, you wanna add this to the community section? If so, you can do that here: |
Honestly I would recommend this way instead https://gitlab.com/gitlab-org/cluster-integration/auto-build-image/-/blob/615afe1b2092881dab2955fe5fc562bbc6fc577f/.gitlab/ci/test.gitlab-ci.yml#L246 It will check all commits from a given merge request. |
Just a minor note I was using
It works on regular commit histories but if one execute a push force to remove a commit will fail since the previous build commit doesnt exists. |
In order for me to have commitlint run against all commits in an MR, as we would often have >1 commit per MR, I'm having to change the above to use
I'm concerned though that this will hit issues described above when people force push, etc. Will see how this works in practice, but if any advice please let me know. EDIT: Finding issues unfortunately - seems running with |
Just to let you know, I'm not sure what is happening on the second run of a Gitlab CI job but during the first the GIT_DEPTH variable is used to clone only a subset of the repo. In my case what was happening was that the CI was cloning the last 20 commits of the branch I was working on but the branch was 25 commits long. The fix was simply to set the lint:commits:
stage: lint
needs: []
only:
- merge_requests
variables:
GIT_DEPTH: 0
script:
- npx commitlint --from="$CI_MERGE_REQUEST_DIFF_BASE_SHA" |
When using a boilerplate setup (I have a yeoman generator to create my novel projects), the very first CI run blows up when on Gitlab because
$CI_BUILD_BEFORE_SHA
is0000000000000000000000000000000000000000
. Since that is never a valid SHA in Git, it would be nice if the tool would look for that and just scan the entire branch or just skip it with a warning. (Or have a flag that lets you choose which one if it gets into that condition).Expected Behavior
I use a boilerplate to set up my Gitlab repositories for my novels and stories. This is a semi-regular occurrence (1-3/month). Because I have it down to templates, I have
commitlint
in from the beginning of thechore: initial commit
. However, when using it in a CI file, it fails because it is the first run of the CI.When Gitlab CI starts, the environment variable is set to all zeros. The work-around is pretty simple, just make another change and push it up but that feels wrong because occasionally I forget that the first is always going to fail.
Current Behavior
Affected packages
Possible Solution
--on-initial-run
) have it either scan the entire branch (scan-branch
) or ignore everything (ignore-previous
).Steps to Reproduce (for bugs)
.gitlab-ci.yml
(see above).Context
Your Environment
commitlint --version
git --version
node --version
The text was updated successfully, but these errors were encountered: