CI/CD Integration
@neosjs/release natively supports running releases non-interactively in any CI/CD environment.
Automatic CI Detection and --ci Mode
The tool uses ci-info to automatically detect whether it is running in a CI environment (such as GitHub Actions, GitLab CI, CircleCI, Travis CI, Jenkins, or Bitbucket Pipelines):
- When a CI environment is detected,
ci: trueis enabled automatically; you can also force it at any time with--ci, or force it off with--no-ci. - Behavior differences in CI mode:
- The screen is not cleared and the interactive welcome box is not printed.
- All confirmation prompts are skipped, and every enabled step runs automatically.
- When no version increment is specified explicitly, the version type recommended by the
changelogplugin based on releasable commits takes precedence; if there are new commits since the last tag but no releasable changes (for example, onlydocs/chore/ci), the release is skipped with exit code0by default after a notice (the skip can be disabled with--no-changelog.requireReleasableCommits). - The interface language follows the system locale: common CI runners (such as Ubuntu / GitHub Actions) default to
C.UTF-8oren_US.UTF-8, so CI logs are in English by default; to get Chinese logs, setNEOS_RELEASE_LANG=zh-CNor pass--lang zh-CN. - In a non-TTY environment, the task list prints status only, and error messages are aggregated and printed once at the top level.
npm publishdoes not inherit the terminal's interactive stream (to submit packages in CI without 2FA, see staged publishing withnpm.stage).- If Git tag signing is enabled but the signature did not take effect, CI mode fails outright and deletes the unsigned tag.
Hybrid Mode (--only-version)
When releasing manually on your local machine, if you only want to confirm the version number yourself (plus the npm publish confirmation / OTP) and have all the other steps (changelog, Git commit/tag/push, creating the Release) run automatically, use:
release --only-versionScripting Mode (--release-version / --only-changelog)
Useful in custom CI scripts when you only need to read the calculated version number or changelog without triggering the release flow:
NEXT_VERSION=$(release --release-version)
release --only-changelog > CHANGELOG_SECTION.mdThese two options automatically switch to CI mode and send all auxiliary logs to stderr, keeping stdout limited to the clean result.
Practical GitHub Actions Configuration
1. Manually Triggered Automated Release (npm + GitHub Release)
name: Release
on:
workflow_dispatch:
inputs:
increment:
description: 'Version increment type (leave empty to recommend from commits)'
required: false
type: choice
options:
- ''
- patch
- minor
- major
- prepatch
- preminor
- premajor
permissions:
contents: write
issues: write
pull-requests: write
id-token: write
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
# Full history and tags are required to analyze commits and the latest tag
fetch-depth: 0
- name: Setup pnpm
uses: pnpm/action-setup@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 22
cache: pnpm
registry-url: https://registry.npmjs.org
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Configure Git
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
- name: Run release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
pnpm release ${{ inputs.increment }} --ci --npm.publish --github.releaseTip: When running in GitHub Actions (the
GITHUB_ACTIONSenvironment variable is present), thegithubplugin automatically skips the token check and the collaborator check.
2. Automatically Publish Canary Preview Builds from a Development Branch
name: Canary Release
on:
push:
branches:
- develop
jobs:
canary:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v4
with:
node-version: 22
cache: pnpm
registry-url: https://registry.npmjs.org
- run: pnpm install --frozen-lockfile
- run: pnpm build
- name: Publish canary
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: pnpm release --canary --ci --npm.publish --npm.skipChecks3. Staged Publishing in CI (npm.stage)
For packages with strict 2FA enabled where you do not want CI to bypass approval and publish directly, you can submit the package to the npm staging queue in CI and let a maintainer approve the publish:
pnpm release --ci --npm.publish --npm.stagePractical GitLab CI Configuration
GitLab CI can use the built-in CI_JOB_TOKEN to create GitLab Releases directly, with no need to request an extra personal access token:
release.config.ts:
import { defineConfig } from '@neosjs/release'
export default defineConfig({
gitlab: {
release: true,
tokenRef: 'CI_JOB_TOKEN',
tokenHeader: 'JOB-TOKEN'
}
}).gitlab-ci.yml:
release:
image: node:22
stage: deploy
rules:
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
when: manual
variables:
GIT_DEPTH: 0
before_script:
- corepack enable
- pnpm install --frozen-lockfile
- git config user.name "${GITLAB_USER_NAME}"
- git config user.email "${GITLAB_USER_EMAIL}"
- git remote set-url origin "https://oauth2:${GIT_PUSH_TOKEN}@${CI_SERVER_HOST}/${CI_PROJECT_PATH}.git"
- git checkout -B "${CI_COMMIT_REF_NAME}"
script:
- pnpm release --ciMore CI Scenario Guides
- Release-via-PR pipeline for a protected default branch: Protected Branch PR Pipeline
- Scheduled CI that releases only when there are new commits: Release Only on New Commits