semver
semver copied to clipboard
After generating the tag, the pipeline fails in gitlab ci.
After generating the tag, the pipeline fails. It seems to be a problem when pushing the code. Is there something wrong with my setup?
$ npx nx affected --target=version --base=$NX_BASE --parallel=1
> NX Running target version for 2 project(s):
- next-app
- next-app-e2e
> nx run next-app:version
[next-app] 🟠 No previous version tag found, fallback to version 0.0.0.
New version will be calculated based on all changes since first commit.
If your project is already versioned, please tag the latest release commit with [email protected] and run this command again.
[next-app] 🆕 Calculated new version "0.1.0".
[next-app] 📜 Generated CHANGELOG.md.
[next-app] 📦 Committed "chore(next-app): release version 0.1.0".
[next-app] 🔖 Tagged "[email protected]".
[next-app] ❌ Error: error: src refspec main does not match any.
error: failed to push some refs to '[https://gitlab-ci-token:[MASKED]@gitlab.com/watarunrun/nx-next-release-note.git']
at /builds/watarunrun/nx-next-release-note/node_modules/@jscutlery/semver/src/executors/common/exec.js:10:34
at ChildProcess.exithandler (node:child_process:406:5)
at ChildProcess.emit (node:events:527:28)
at maybeClose (node:internal/child_process:1092:16)
at Process.ChildProcess._handle.onexit (node:internal/child_process:302:5)
I did exactly what the document says. https://github.com/jscutlery/semver#gitlab-ci
my .gitlab-ci.yml
image: node:16
stages:
- build
- release
.distributed:
interruptible: true
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
when: manual
- if: '$CI_COMMIT_BRANCH == "main"'
when: manual
cache:
key:
files:
- package-lock.json
paths:
- .npm/
before_script:
- npm ci --cache .npm --prefer-offline --legacy-peer-deps
- NX_HEAD=$CI_COMMIT_SHA
- NX_BASE=${CI_MERGE_REQUEST_DIFF_BASE_SHA:-$CI_COMMIT_BEFORE_SHA}
artifacts:
paths:
- node_modules/.cache/nx
build:
stage: build
extends: .distributed
script:
- npx nx affected --base=$NX_BASE --head=$NX_HEAD --target=build --parallel=3
release-app:
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
when: always
stage: release
extends: .distributed
variables:
GIT_DEPTH: '0'
script:
- git config --global user.name "watarunrun"
- git config --global user.email "[email protected]"
- git remote set-url origin https://gitlab-ci-token:${DEPLOY_KEY}@gitlab.com/watarunrun/nx-next-release-note.git
- npx nx affected --target=version --base=$NX_BASE
- git tag -f last-release
- git push origin last-release --force -o ci.skip
I changed settings of project.json to generate CHANGELOG.md as follows.
"version": {
"executor": "@jscutlery/semver:version",
"options": {
"preset": "conventional",
"tagPrefix": "${projectName}@",
"push": true
}
}
@hayawata3626 I think it comes from a misconfiguration of the base branch, the error occurs on the push like if "main" is not a correct ref, what is your base branch, master or main?
@edbzn Thanks for the reply! My base branch is main.
@edbzn Perhaps this has something to do with it? https://forum.gitlab.com/t/src-refspec-master-does-not-match-any/24691
Yeah, it could come from the way you are initializing the repository, did you try to change or remove the GIT_DEPTH variable?
Yeah, I tried this to debug.
did you try to change or remove the GIT_DEPTH variable?
same here, using GH Actions
@edbzn Any ideas to work around this problem? 🤔
It's hard to say by just looking at the code sample, it can come from the way the repo is initialized in your CI, peraps the main branch is not fetched correctly.
@gabsmprocha @hayawata3626 Did you find a workaround ?
@nhuray No solution has been found yet.
@edbzn for me the git HEAD is going crazy, any hint please?
is there something I could do to avoid this chain effect?
are some of them running in parallel? :thinking:
> nx run assets:release
[assets] 🆕 Calculated new version "0.0.2".
[assets] 📜 Generated CHANGELOG.md.
[assets] 📝 Updated package.json version.
[assets] ❌ Error: fatal: cannot lock ref 'HEAD': is at 1fd3f3e8fe216c6742173eb23ae7e684d2fbed8c but expected 2dd3456cf558789467c5c8b4625d26f780a3d79f
at /opt/gitlab-runner/builds/mynd/frontend/megarepo/node_modules/@jscutlery/semver/src/executors/common/exec.js:10:34
> nx run select:release
[select] 🆕 Calculated new version "0.0.2".
[select] 📜 Generated CHANGELOG.md.
[select] 📝 Updated package.json version.
[select] 📦 Committed "ci: release @mynd/[email protected]".
[select] 🔖 Tagged "@mynd/[email protected]".
> nx run common:release
[common] 🆕 Calculated new version "0.0.2".
[common] 📜 Generated CHANGELOG.md.
[common] 📝 Updated package.json version.
[common] ❌ Error: fatal: cannot lock ref 'HEAD': is at 1fd3f3e8fe216c6742173eb23ae7e684d2fbed8c but expected 2dd3456cf558789467c5c8b4625d26f780a3d79f
at /opt/gitlab-runner/builds/mynd/frontend/megarepo/node_modules/@jscutlery/semver/src/executors/common/exec.js:10:34
> nx run checkbox:release
[checkbox] 🆕 Calculated new version "0.0.2".
[checkbox] 📜 Generated CHANGELOG.md.
[checkbox] 📝 Updated package.json version.
[checkbox] ❌ Error: fatal: cannot lock ref 'HEAD': is at ebe032a50be83d3996260515d5326242950ba19b but expected 1fd3f3e8fe216c6742173eb23ae7e684d2fbed8c
at /opt/gitlab-runner/builds/mynd/frontend/megarepo/node_modules/@jscutlery/semver/src/executors/common/exec.js:10:34
> nx run switch:release
[switch] 🆕 Calculated new version "0.0.2".
[switch] 📜 Generated CHANGELOG.md.
[switch] 📝 Updated package.json version.
[switch] ❌ Error: fatal: cannot lock ref 'HEAD': is at ebe032a50be83d3996260515d5326242950ba19b but expected 1fd3f3e8fe216c6742173eb23ae7e684d2fbed8c
at /opt/gitlab-runner/builds/mynd/frontend/megarepo/node_modules/@jscutlery/semver/src/executors/common/exec.js:10:34
> nx run design-tokens:release
[design-tokens] 🆕 Calculated new version "0.0.2".
[design-tokens] 📜 Generated CHANGELOG.md.
[design-tokens] 📝 Updated package.json version.
[design-tokens] ❌ Error: fatal: cannot lock ref 'HEAD': is at 9ecad87159ad0ef13c5d486d25544e1671831e4c but expected ebe032a50be83d3996260515d5326242950ba19b
at /opt/gitlab-runner/builds/mynd/frontend/megarepo/node_modules/@jscutlery/semver/src/executors/common/exec.js:10:34
> nx run radio:release
[radio] 🆕 Calculated new version "0.0.2".
[radio] 📜 Generated CHANGELOG.md.
[radio] 📝 Updated package.json version.
[radio] ❌ Error: fatal: cannot lock ref 'HEAD': is at 9ecad87159ad0ef13c5d486d25544e1671831e4c but expected ebe032a50be83d3996260515d5326242950ba19b
at /opt/gitlab-runner/builds/mynd/frontend/megarepo/node_modules/@jscutlery/semver/src/executors/common/exec.js:10:34
Hi,
I had the same issue and found that nx affected "parallel" option has a default value of 3.
Using --parallel=1 worked for me
Switching to --parallel=1 did not fix this issue
There are two different issues here. Concerning the lock issue, it's a matter of parallel=1.
Otherwise, it feels like an issue with the way gitlab fetches the refs. Gitlab users, did you try setting GIT_STRATEGY to "clone"?
https://docs.gitlab.com/ee/ci/runners/configure_runners.html
I Hope that this will help.