# Releases
# Release Versioning
Release versioning is automated by combining our Versioning strategy with the Semantic Release package integrated into our GitLab CI.
For example, consider the following commit message:
fix(api): /user endpoint now accepts mythical figures, including Norse Gods
Closes #1
When the developer attempts to commit this to the allow-thor branch the release process proceeds as follows:
- The dev attempts to commit the change to the
non-masterbranch (allow-thor). - The commit message is validated.
- The commit is pushed to the
allow-thorbranch on GitLab. - GitLab CI performs the
testingenvironment deployment process, as defined in .gitlab-ci.yml. - If all
testingenvironment pipeline stages succeed, the dev can now create a merge request to mergeallow-thorinto themasterbranch. - Once the merge request is accepted GitLab CI executes the
productionenvironment pipeline. - At the end of the
productiondeployment pipeline is thereleasestage, which uses Semantic Release to analyze the full collection of commits within the merge request. - The proper new version number (tag) is automatically generated, based on the semantic versioning rules defined by our active Commit Message Syntax.
- A changelog is auto-generated and associated with the tagged release.
Our full Semantic Release configuration can be found in the .releaserc.json file.
# How to Add Releasing to an Existing Project
- Add any missing node modules to
package.json:
- Bash
- PowerShell
yarn add -D @commitlint/cli @commitlint/config-conventional @semantic-release/git @semantic-release/gitlab \
@semantic-release/npm commitizen cz-conventional-changelog husky
- Add a
config: commitizensection topackage.json:
{
"config": {
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
}
}
}
- Add a
commitscript topackage.json:
{
"scripts": {
"commit": "git-cz"
}
}
- Copy
.commitlintrc.js,.huskyrc.js, and.releaserc.jsonfiles to project root directory. - Update
repositoryUrland@semantic-release/gitlab: gitlabUrlin.releaserc.jsonto match the private GitLab repo endpoint and URL, respectively:
{
"repositoryUrl": "git@gitlab.solarixdigital.com:path/to/project.git",
"plugins": [
[
"@semantic-release/gitlab",
{
"gitlabUrl": "https://gitlab.solarixdigital.com/path/to/project"
}
]
]
}
- Add a new
releasestage to.gitlab-ci.ymland add a matchingproduction:releasejob:
stages:
# ...
- release
# ...
production:release:
stage: release
only:
- master
environment:
name: production
image: node:12-buster-slim
before_script:
- apt-get update && apt-get install -y --no-install-recommends git-core ca-certificates
- npm install -g semantic-release @semantic-release/gitlab @semantic-release/git conventional-changelog-conventionalcommits
script:
- semantic-release
- On GitLab create a new Personal Access Token with
apiscope. - Under Project > Settings > CI / CD > Variables create a new
GITLAB_TOKENvariable with the generated token as the value.
Now, the next production pipeline CI should evaluate the commit history and perform a semantic release, if necessary.