I'm (mis)using semantic-release when building a C++ application in a GitLab CI.
My config is quite minimal .releaserc.json
{
"branches": ["main", "develop"],
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/gitlab",
"@semantic-release/release-notes-generator",
[
"@semantic-release/changelog",
{
"changelogFile": "public/CHANGELOG.md"
}
],
[
"@semantic-release/git",
{
"assets": ["public/CHANGELOG.md"]
}
]
]
}
In the GitLab Ci, I have a couple of stages
Versioning -> Build -> Test -> Deploy
Versioning
version:
tags:
- macOS
stage: version
script:
- export PATH=$PATH:/usr/local/bin
# Configure semantic-release
- npm install
- npm ci --cache .npm --prefer-offline
- |
{
echo "@${CI_PROJECT_ROOT_NAMESPACE}:registry=${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/npm/"
echo "${CI_API_V4_URL#https?}/projects/${CI_PROJECT_ID}/packages/npm/:_authToken=\${CI_JOB_TOKEN}"
} | tee -a .npmrc
- npm run semantic-release
- VERSION=$(grep -i -ow '\d\.\d\.\d' public/CHANGELOG.md | head -1)
- echo $VERSION > public/VERSION.txt
- echo $VERSION
artifacts:
name: "Changelog"
paths:
- public/*
Build relies on the Artifacts of Versioning, because it needs to add the current version to cmake. And yes, I'm grepping the version number from the change log, don't judge me :D
Works fine, but semantic-release is creating the tag right in the version stage. This could lead to problems, if the pipeline fails. Re-running a failed pipeline should result in an error "semantic-release: tag already exists".
is there any way to create the tag in a seperate stage at the very end, only if the rest of the pipeline succeeded?
Thanks!