I am using semantic release for versioning in my repo. In my Gitlab when i merge my branch with develop my tag increases according to the commit and it works fine.
I now want to get the current version to pass it to another stage of CI.
I followed this
and I have this .releaserc.yml
file:
plugins:
- "@semantic-release/commit-analyzer"
- "@semantic-release/release-notes-generator"
- "@semantic-release/exec":
- publishCmd: "echo \"VERSION=${nextRelease.version}\" >> version.env"
- "@semantic-release/gitlab"
tagFormat:
- ${version}
branches:
- "develop"
and this is the gitlab CI stage that I would like to use to grab the current version and save it as artifact
fetch-semantic-version:
image: node:20
stage: fetch-version
variables:
GITLAB_TOKEN: $ACCESS_TOKEN
only:
refs:
- develop
script:
- npm install @semantic-release/gitlab @semantic-release/exec
- npx semantic-release --dry-run --no-ci --branches develop > VERSION.txt
- cat VERSION.txt
artifacts:
paths:
- VERSION.txt
reports:
dotenv: version.env # this will save the version.env file and apply all variables in the next stage
when I push a commit (using conventional commits ) I get this:
[7:10:42 AM] [semantic-release] › ℹ Found git tag 1.1.2 associated with version 1.1.2 on branch develop [7:10:42 AM] [semantic-release] › ℹ Found 29 commits since last release [7:10:42 AM] [semantic-release] › ✔ Completed step "analyzeCommits" of plugin "@semantic-release/commit-analyzer" [7:10:42 AM] [semantic-release] › ℹ There are no relevant changes, so no new version is released.
I this case, no new release, I would like to get 1.1.2
, in the case of a new release, the logs would be:
[2:43:30 PM] [semantic-release] › ✔ Completed step "analyzeCommits" of plugin "@semantic-release/commit-analyzer" [2:43:30 PM] [semantic-release] › ℹ The next release version is 1.1.2 [2:43:30 PM] [semantic-release] › ℹ Start step "generateNotes" of plugin "@semantic-release/release-notes-generator" [2:43:30 PM] [semantic-release] › ✔ Completed step "generateNotes" of plugin "@semantic-release/release-notes-generator" [2:43:33 PM] [semantic-release] › ✔ Created tag 1.1.2
how to fix it in such a way I can get, previous, version found and next to be sure I pass the correct one to the next stage?