# 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-master
branch (allow-thor
). - The commit message is validated.
- The commit is pushed to the
allow-thor
branch on GitLab. - GitLab CI performs the
testing
environment deployment process, as defined in .gitlab-ci.yml. - If all
testing
environment pipeline stages succeed, the dev can now create a merge request to mergeallow-thor
into themaster
branch. - Once the merge request is accepted GitLab CI executes the
production
environment pipeline. - At the end of the
production
deployment pipeline is therelease
stage, 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: commitizen
section topackage.json
:
{
"config": {
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
}
}
}
- Add a
commit
script topackage.json
:
{
"scripts": {
"commit": "git-cz"
}
}
- Copy
.commitlintrc.js
,.huskyrc.js
, and.releaserc.json
files to project root directory. - Update
repositoryUrl
and@semantic-release/gitlab: gitlabUrl
in.releaserc.json
to 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
release
stage to.gitlab-ci.yml
and add a matchingproduction:release
job:
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
api
scope. - Under Project > Settings > CI / CD > Variables create a new
GITLAB_TOKEN
variable 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.