@dvashim/changesets-gitlab

Based on project un-ts/changesets-gitlab by JounQin
GitLab CI CLI for changesets, similar to the GitHub Action. It creates a merge request with all of the package versions updated and changelogs updated, and when there are new changesets on the default branch, the MR will be updated. When you're ready, you can merge the merge request and either publish the packages to npm manually or set up the CLI to do it for you.
Usage
Inputs
Note: environment variables are case-sensitive
INPUT_PUBLISH - The command to use to build and publish packages
INPUT_VERSION - The command to update version, edit CHANGELOG, read and delete changesets. Defaults to changeset version if not provided
INPUT_COMMIT - The commit message to use. Default Version Packages
INPUT_TITLE - The merge request title. Default Version Packages
Only available in @dvashim/changesets-gitlab
INPUT_PUBLISHED - Command executed after publishing
INPUT_ONLY_CHANGESETS - Command executed when only changesets are detected
INPUT_REMOVE_SOURCE_BRANCH - Enables the merge request "Delete source branch" checkbox. Default false
INPUT_TARGET_BRANCH - The merge request target branch. Defaults to the current branch
INPUT_CREATE_GITLAB_RELEASES - Whether to create GitLab releases after publish. Default true
INPUT_LABELS - A comma-separated string of labels to add to the version package merge request
Outputs
PUBLISHED - A boolean value indicating whether publishing happened
PUBLISHED_PACKAGES - A JSON array of published packages. Format: [{"name": "@xx/xx", "version": "1.2.0"}, {"name": "@xx/xy", "version": "0.8.9"}]
Environment Variables
GLOBAL_AGENT_HTTP_PROXY
GLOBAL_AGENT_HTTPS_PROXY
GLOBAL_AGENT_NO_PROXY
GITLAB_HOST
GITLAB_TOKEN
GITLAB_TOKEN_TYPE
GITLAB_CI_USER_NAME
GITLAB_CI_USER_EMAIL
GITLAB_COMMENT_TYPE
GITLAB_COMMENT_DISCUSSION_AUTO_RESOLVE
GITLAB_COMMENT_CUSTOM_LINKS
GITLAB_ADD_CHANGESET_MESSAGE
DEBUG_GITLAB_CREDENTIAL
Example workflow
Without publishing
Create a file at .gitlab-ci.yml with the following content.
stages:
- comment
- release
comment:
image: node:lts-alpine
stage: comment
before_script: pnpm install --frozen-lockfile
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
script: pnpm changesets-gitlab comment
release:
image: node:lts-alpine
stage: release
before_script: pnpm install --frozen-lockfile
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
script: pnpm changesets-gitlab
With publishing
You'll need an npm token that can publish the packages in the repo and doesn't have 2FA on publish enabled (2FA on auth can be enabled). Add it as a CI/CD variable with the name NPM_TOKEN.
stages:
- comment
- release
comment:
image: node:lts-alpine
stage: comment
before_script: pnpm install --frozen-lockfile
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
script: pnpm changesets-gitlab comment
release:
image: node:lts-alpine
stage: release
before_script: pnpm install --frozen-lockfile
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
script: pnpm changesets-gitlab
variables:
INPUT_PUBLISH: pnpm release
By default, the CLI creates a ~/.npmrc file with the NPM_TOKEN interpolated as the auth token for registry.npmjs.org. If a .npmrc file already exists, it will not be overwritten. This is useful if you need to configure .npmrc yourself:
script: |
cat << EOF > "$HOME/.npmrc"
email=my@email.com
//registry.npmjs.org/:_authToken=$NPM_TOKEN
EOF
With version script
If you need to add additional logic to the version command, you can use a version script.
When the version script is present, the CLI will run that script instead of changeset version, so make sure your script calls changeset version at some point. All changes made by the script will be included in the MR.
stages:
- comment
- release
comment:
image: node:lts-alpine
stage: comment
before_script: pnpm install --frozen-lockfile
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
script: pnpm changesets-gitlab comment
release:
image: node:lts-alpine
stage: release
before_script: pnpm install --frozen-lockfile
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
script: pnpm changesets-gitlab
variables:
INPUT_VERSION: pnpm version-packages
Changelog
Detailed changes for each release are documented in CHANGELOG.md.
License
MIT © Aleksei Reznichenko
Originally created by JounQin at un-ts/changesets-gitlab.