Semantic-release(Fully automated version management and package publishing) with gitlab and gitlab ci/cd tools and rocket chat(slack)

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

get user token from gitlab

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
GL_TOKEN: F2LPsnFHpa_s1yf8sddddssasas
SEMANTIC_RELEASE_PACKAGE: semantic-release
SLACK_WEBHOOK: https://rc.itc-life.ru/hooks/6B2bsuGsdsdsyHX3wH9c/5aBPBrzm6ykNMzG3EFKuZKugp8p55gNDYSL8fwvSxnYksbdn

Create file .releaserc.json in root project

{
  "branches": ["master", "+([0-9])?(.{+([0-9]),x}).x", "dev"],
  "debug": "True",
  "plugins": [
    ["@semantic-release/commit-analyzer",{
      "dryRun": "false",
    }],
    ["@semantic-release/release-notes-generator",{
      "dryRun": "false",
    }],
    ["@semantic-release/gitlab", {
      "dryRun": "false",
    }],
    ["@semantic-release/exec", {
      "verifyConditionsCmd": "./verify.sh",
      "publishCmd": "./publish.sh ${nextRelease.version} ${options.branch} ${commits.length} ${Date.now()}"
    }],
    "semantic-release-slack-bot"
  ]
}

Create .gitlab-ci.yml

Create file .gitlab-ci.yml with to section build and release. Release must be latest job

stages:
  - build
  - release
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: node:12-buster-slim
  tags:
    - itc-life-note-runner-1
  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-slack-bot @semantic-release/exec
  script:
    - semantic-release --debug
  only:
    - master

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

See addtional on page

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

Posted in git

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *

 

Этот сайт использует Akismet для борьбы со спамом. Узнайте как обрабатываются ваши данные комментариев.