1.5.0 • Published 7 years ago

gitlab-ci-releaser v1.5.0

Weekly downloads
-
License
MIT
Repository
gitlab
Last release
7 years ago

gitlab-ci-releaser

Yet another conventional GitLab releaser : find unreleased changes, bump version, commit/push changes and create a new GitLab release with notes

Installation

The setup requires Node 6+.

  1. Add a new release stage in your .gitlab-ci.yml.
  2. Install gitlab-ci-releaser using npm install gitlab-ci-releaser
  3. Add the environment variables GITLAB_CI_RELEASER_NAME, GITLAB_CI_RELEASER_EMAIL and GITLAB_CI_RELEASER_TOKEN with settings of a user having Developer permissions and the permission to push to the release branch (e.g. master).
  4. Optionally, add an environment variable NPM_TOKEN if you want to publish your packages to a npm registry.

I recommend creating and using a new user with Developer + push permissions, adding the user to the project members and generating all the environment variables using this user account (the SSH access permissions are not needed for this account).

Usage

You can use the gitlab-ci-releaser command to create releases:

$(npm bin)/gitlab-ci-releaser

To publish to npm, add the npm option:

$(npm bin)/gitlab-ci-releaser --npm

You can optionally pass the npm registry and authentication token via command line arguments:

$(npm bin)/gitlab-ci-releaser --token "<gitlab auth token>" --npmToken "<npm auth token>" --npmRegistry "http://localhost:4873/"

This being said, I strongly recommend using environment variables for this sensitive information instead of passing them as program arguments.

Here is an example of GitLab CI stage for releasing with npm publishing.

image: node:6

stages:
  - build
  - release

build:
  stage: build
  script:
    - npm install

release:
  stage: release
  before_script:
    - npm install gitlab-ci-releaser
  only:
    - master
  script:
    - $(npm bin)/gitlab-ci-releaser --npm
  when: manual

Environment variables

gitlab-ci-releaser relies on many environment variables:

NameTypeSet byDescriptionExample
GITLAB_CI_RELEASER_NAMEMandatoryAdminGitLab account username, used to create release commitsikhemissi
GITLAB_CI_RELEASER_EMAILMandatoryAdminGitLab account email, used to create release commitsmail.address@example.com
GITLAB_CI_RELEASER_TOKENMandatoryAdminGitLab account access token, used to push commitsaBcde1234AbcD5678ef
NPM_TOKENOptionalAdminNPM authToken. Only needed when publishing to NPM.9febf68b-f1b7-5bd9-701a-576eba203a1f3
NPM_REGISTRYOptionalAdminNPM registry. By default, it will be fetched from npm configurationhttp://private.sinopia.registry:4873/
CI_PROJECT_URLMandatoryGitLab CIProject urlhttps://gitlab.com/ikhemissi/test-release-project
CI_PROJECT_PATHMandatoryGitLab CIProject ID (user name + project name)ikhemissi/test-release-project
CI_BUILD_REPOMandatoryGitLab CIProject repositoryhttps://gitlab-ci-token:xxxx@gitlab.com/ikhemissi/test-release-project.git
CI_BUILD_REF_NAMEMandatoryGitLab CIProject branch used in the buildmaster
GITLAB_USER_EMAILOptionalGitLab CIEmail of the user who triggered the buildmail.address@example.com
CI_BUILD_IDOptionalGitLab CIInternal GitLab build number50

Release versions

By default, gitlab-ci-releaser uses semantic commit types and footers to determine the next release version:

  • if this is the first release, then the version 1.0.0 will be used to create the release
  • if the new changes include a commit with a breaking change (the commit message contains BREAKING CHANGE) then a major release will be created
  • if there is at least one feature commit (commit type = feat), then a minor release will be created
  • otherwise, a patch release will be created

This being said, you can force a specific release type or version as long as they conform to the semver spec using the following options:

  • releaseType: This option allows you to force a specific release version increment (e.g. major, minor, patch). For example, by running gitlab-ci-releaser --releaseType major we get a version 2.0.0 if the previous one was 1.5.0, and we get 4.0.0 if the previous one was 3.0.0.
  • releaseVersion: With this option, you can force using a specific release version (e.g. 1.9.1). For example, by running gitlab-ci-releaser --releaseVersion 1.9.1 we create a release having the version 1.9.1 even if the previous one was 2.0.0, which may lead to potential issues.

Please note that the semantic commits are also used to generate the release notes, so I don't recommend using the releaseType and releaseVersion unless your project do not use semantic commits.

If you plan to switch to semantic commits, I strongly suggest using a tool like commitizen to create your commits and have better commit messages.

Similar projects

Contributing

Please follow the Airbnb guidelines and commit your changes with commitzen using git cz.