Semantic-release automates the whole package release workflow including: determining the next version number, generating the release notes and publishing the package. Plus: added integtration with rocketchat/slack
Requements
gitlab
gitlab runner
rocketchat(slack) integration with webhook
Create user with token
Let’s get user token from gitlab, which has access to target repo
F2LPsnFHpa_s1yf8sddddssasas
Create inegration webhook incoming with rocketchat
get webhook
https://rc.itc-life.ru/hooks/6B2bsuGsdsdsyHX3wH9c/5aBPBrzm6ykNMzG3EFKuZKugp8p55gNDYSL8fwvSxnYksbdn
Create repo for tesitng
ssh://git@git.linux2be.com:222/itc-life/demo-semantic.git
Create variable in ci-cd section in repo
GITLAB_TOKEN: F2LPsnFHpa_s1yf8sddddssasas
SLACK_WEBHOOK: https://rc.itc-life.ru/hooks/6B2bsuGsdsdsyHX3wH9c/5aBPBrzm6ykNMzG3EFKuZKugp8p55gNDYSL8fwvSxnYksbdn
Create file .releaserc.json in root project
{
"branches": ["master", "main", "+([0-9])?(.{+([0-9]),x}).x", "dev"],
"debug": "True",
"plugins": [
["@semantic-release/commit-analyzer", {
"preset": "angular",
"releaseRules": [
{"type": "patch", "release": "patch"},
{"type": "style", "release": "patch"},
{"type": "refactor", "release": "patch"}
],
"parserOpts": {
"noteKeywords": ["BREAKING CHANGE", "BREAKING CHANGES"]
}
}],
["@semantic-release/release-notes-generator",{
"dryRun": "false",
}],
["@semantic-release/gitlab", {
"dryRun": "false",
}],
["@semantic-release/exec", {
"verifyConditionsCmd": "./files/scripts/ci_cd/verify.sh",
"publishCmd": "./files/scripts/ci_cd/publish.sh ${nextRelease.version} ${options.branch} ${commits.length} ${Date.now()}"
}]
]
}
Create .gitlab-ci.yml
Create file .gitlab-ci.yml with to section build and release. Release must be latest job
stages:
- build
- release
variables:
d_image_semantic: "devsadds/semantic-release:node-14.17.6-buster-slim-v18.0.0"
d_image_compose: "devsadds/docker-compose:1.29.2.2"
SEMANTIC_RELEASE_PACKAGE: "semantic-release"
DOCKER_BUILD_VERSION: "20.10.7-dind"
BUILD_COMMON_LIBS_VCS_URL: "https://gitlab.com/cdn72/provisioning.git"
BUILD_COMMON_LIBS_VCS_BRANCH: "master"
DOCKER_TLS_CERTDIR: ""
great-russian-firewall:
stage: build
image: devsadds/docker-compose:alpine-1.25.4
timeout: 120m
services:
- docker:18.03.1-ce-dind
tags:
- itc-life-note-runner-1
variables:
<<: *production_variables
DOCKER_IMAGE_NAME: 'great-russian-firewall'
DOCKER_IMAGE_TAG: '1.0.0'
before_script:
- docker info
- docker login ${DOCKER_REGISTRY} -u ${DOCKER_REGISTRY_USER} -p ${DOCKER_REGISTRY_PASSWORD}
- docker login -u ${DOCKER_HUB_USER} -p ${DOCKER_HUB_PASSWORD}
script:
- tag_build=$(date +%Y-%m-%d__%H_%M)
- cd files/docker/build/devsadds/great-russian-firewall/production
- mkdir -p data/firewall/data
- echo "${tag_build}" >> data/firewall/data/demo.txt
only:
- master
artifacts:
paths:
- "files/docker/build/devsadds/great-russian-firewall/production/data/firewall/data/*"
release:
stage: release
image: $d_image_semantic
script:
- semantic-release
only:
refs:
- master
- main
variables:
- $CI_ACTION !~ /.*[a-z].*/
Make initial commit
git add . && git commit . -m"feat: initial commnit" && git push
Wait util pipelines fineshed
After finish pipelines we see release in release page
And make cnanges
commans for update version
Here is an example of the release type that will be done based on a commit messages:
Commit message
fix(pencil): stop graphite breaking when too much pressure applied Patch Release
feat(pencil): add ‘graphiteWidth’ option Minor Feature Release
perf(pencil): remove graphiteWidth option Minor Feature Release
BREAKING CHANGE: The graphiteWidth option has been removed. Major Breaking Release
Notes
Note 1
Make sure to configure your release branch as protected in order for the CI/CD build to access the protected variables.
Sources
Official docs semantic-release 1
Official docs semantic-release 2
Inet mans