Releasing versions
The release.yml makes use of semantic-release and GitLabs release-cli to automatically generate changelogs, tags and releases.
Getting started
Configuration
To make use of semantic-release you first need to create a configuration file in the root directory of your project
release.config.js
const branch = process.env.CI_COMMIT_BRANCH
const config = {
tagFormat: "${version}",
branches: [
"+([0-9])?(.{+([0-9]),x}).x",
"main",
{
name: "dev",
channel: "default",
prerelease: "beta"
}
],
plugins: [
["@semantic-release/commit-analyzer", {
preset: "conventionalcommits"
}],
["@semantic-release/release-notes-generator", {
preset: "conventionalcommits"
}],
["@semantic-release/gitlab", {
labels: "Type::fix,From::Release Bot,Priority::High"
}]
]
}
if (config.branches.some(it => it === branch || (it.name === branch && !it.prerelease))) {
config.plugins.push([ "@semantic-release/changelog", {
changelogTitle: "# Changelog\n\nAll notable changes to this project will be documented in this file. See\n[Conventional Commits](https://conventionalcommits.org) for commit guidelines."
}]);
config.plugins.push([ "@semantic-release/git", {
message: "chore(release): ${nextRelease.version}\n\n${nextRelease.notes}"
}]);
}
if(branch !== "main" && branch !== "dev") {
config.branches.push({
name: branch,
channel: "default",
prerelease: "alpha"
})
}
module.exports = config
This will configure semantic release to:
- Use ConventionalCommits
- Create
stablereleases frommainbranch - Create
betareleases fromdevbranch - Create
alphareleases from any other branch - Create specific version releases from
major.xormajor.minor.xbranches - Generate changelog only on stable branches
GitLab CI
When you configured semantic-release you can add the release.yml to your GitLab CI
.gitlab-ci.yml
include:
- project: "abfelbaum/ci"
file: "release.yml"
It is using the deploy stage.
info
If you have not configured GPG singing please refer to this section.
info
If you prefer to not use the GitLab plugin, feel free to comment it out or remove it from the configuration file.
Now, for every commit you have a manual stage named semantic-release:deploy. The following happens on trigger
semantic-releaseanalyzes the commit messages and determines the next version- (stable branches only)
semantic-releasegeneratesCHANGELOG.md semantic-releasecreates a new tagsemantic-releasecreates a new release with the tag name as title and the commit message as descriptionsemantic-releasecomments to every issue that was resolved in that release that it has been resolved