Semantic Releases with Gitlab CI

boadude

Miguel Meza

Posted on August 11, 2020

Semantic Releases with Gitlab CI

If you read about Commit Standard and Semantic Versioning for any project from my previous post you'll know what I'm talking about, if not go back and read the post.

In this Post. I'll show you how to configure the same project but now using GitLab CI to create the release version.

First of all, install these two dependencies. We used gitlab-config dependency to configure our repository to handle the release.

npm i -D @semantic-release/gitlab @semantic-release/gitlab-config
Enter fullscreen mode Exit fullscreen mode

Now we need to modify our package.json and add this code. The only difference here is that we don't have *@semantic-release/github *dependency anymore, and for the release, we share or extend the configuration from gitlab-config dependency.

"plugins": [
    "@semantic-release/commit-analyzer",
    "@semantic-release/release-notes-generator",
    "@semantic-release/changelog",
    "@semantic-release/gitlab",
    "@semantic-release/npm",
    "@semantic-release/git"
  ],
  "release": {
    "extends": "@semantic-release/gitlab-config",
    "prepare": [
      "@semantic-release/changelog",
      "@semantic-release/npm",
      {
        "path": "@semantic-release/git",
        "assets": [
          "package.json",
          "package-lock.json",
          "CHANGELOG.md"
        ],
        "message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
      }
    ]
  },
Enter fullscreen mode Exit fullscreen mode

Now, we create a gitlab-ci.yml file in the root of our project to Gitlab configure our pipeline using the instruction in this file.

stages:
  - release

semantic_release:
  image: node:12
  stage: release
  only:
    - master
  script:
    - npm i
    - npx semantic-release
Enter fullscreen mode Exit fullscreen mode

Finally, push your changes to the master branch, and see the magic happens 😜.

💖 💪 🙅 🚩
boadude
Miguel Meza

Posted on August 11, 2020

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related