Fork of https://gitlab.com/ikhemissi/gitlab-ci-releaser with the following changes:
You can add preid to your command to be able to have for example "1.0.0-rc.0" as version. preid will be incremented when using command with preid set.
For example stay you start a new project and you have package version "1.0.0". After running
gitlab-ci-releaser --preid rc version will be comiited as "1.0.0-rc.0". Now if you run
gitlab-ci-releaser --preid rc again it will become "1.0.0-rc.1", and once more rc.2, etc.
Whenever you run
gitlab-ci-releaser the preid will be discarded, and version according to above example would be commited as "1.0.0".
This is useful if you have a flow where you have feature branches you merge down to a development branch, and then merge to a stable/master branch to make a final delivery release. Then in your gitlab-ci.yml for the scripts running from develop you run with preid to get release candidate versions tagged and published to npm, and from master branch you run without preid to get final release versions.
- Updated gitlab environment variables.
Following vars has been renamed:
CI_BUILD_REPO -> CI_REPOSITORY_URL CI_BUILD_ID -> CI_JOB_ID CI_BUILD_REF_NAME -> CI_COMMIT_REF_NAME
Yet another conventional GitLab releaser : find unreleased changes, bump version, commit/push changes and create a new GitLab release with notes
The setup requires Node 6+.
- Add a new release stage in your .gitlab-ci.yml.
npm install gitlab-ci-releaser
- Add the environment variables
GITLAB_CI_RELEASER_TOKENwith settings of a user having
Developerpermissions and the permission to push to the release branch (e.g.
- Optionally, add an environment variable
NPM_TOKENif 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).
You can use the
gitlab-ci-releaser command to create releases:
To publish to npm, add the
$(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
gitlab-ci-releaser relies on many environment variables:
||Mandatory||Admin||GitLab account username, used to create release commits||ikhemissi|
||Mandatory||Admin||GitLab account email, used to create release firstname.lastname@example.org|
||Mandatory||Admin||GitLab account access token, used to push commits||aBcde1234AbcD5678ef|
||Optional||Admin||NPM authToken. Only needed when publishing to NPM.||9febf68b-f1b7-5bd9-701a-576eba203a1f3|
||Optional||Admin||NPM registry. By default, it will be fetched from npm configuration||http://private.sinopia.registry:4873/|
||Mandatory||GitLab CI||Project url||https://gitlab.com/ikhemissi/test-release-project|
||Mandatory||GitLab CI||Project ID (user name + project name)||ikhemissi/test-release-project|
||Mandatory||GitLab CI||Project repository||https://gitlab-ci-token:email@example.com/ikhemissi/test-release-project.git|
||Mandatory||GitLab CI||Project branch used in the build||master|
||Optional||GitLab CI||Email of the user who triggered the firstname.lastname@example.org|
||Optional||GitLab CI||Internal GitLab build number||50|
- if this is the first release, then the version
1.0.0will 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 majorwe get a version
2.0.0if the previous one was
1.5.0, and we get
4.0.0if the previous one was
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.1we create a release having the version
1.9.1even 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
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.
- semantic-release-gitlab: this project inspired me to write gitlab-ci-releaser. Many thanks to Hutson.