AgentSkillsCN

npm-publish

提供通过 CI/CD 自动化流程升级软件包版本并发布至 npm 的指南。当用户咨询如何发布、上线、升级版本,或部署至 npm 时,可参考本指南。

SKILL.md
--- frontmatter
name: npm-publish
description: Guide for bumping package versions and publishing to npm via CI/CD. Use when the user asks about publishing, releasing, version bumping, or deploying to npm.

NPM Publish Workflow

This project uses GitHub Actions CI/CD to automatically publish to npm when a version tag is pushed.

Quick Publish

bash
# 1. Bump the version (updates package.json and creates a git tag)
npm version patch   # 0.1.0 -> 0.1.1
npm version minor   # 0.1.0 -> 0.2.0
npm version major   # 0.1.0 -> 1.0.0

# 2. Push to trigger CI/CD
git push && git push --tags

The CI pipeline will automatically:

  • Run tests on multiple platforms (Ubuntu, macOS) and Node versions (18, 20)
  • Build the project
  • Publish to npm if all tests pass

Version Types

CommandUse WhenExample
npm version patchBug fixes, small updates0.1.0 → 0.1.1
npm version minorNew features, backwards compatible0.1.0 → 0.2.0
npm version majorBreaking changes0.1.0 → 1.0.0

Pre-release Versions

bash
npm version prerelease --preid=alpha  # 0.1.0 -> 0.1.1-alpha.0
npm version prerelease --preid=beta   # 0.1.0 -> 0.1.1-beta.0
npm version prerelease --preid=rc     # 0.1.0 -> 0.1.1-rc.0

Setup (One-time)

Add NPM_TOKEN to GitHub repository secrets:

  1. Generate token at https://www.npmjs.com/settings/[username]/tokens
  2. Add to GitHub repo: Settings → Secrets and variables → Actions → New repository secret
  3. Name: NPM_TOKEN, Value: [your token]

Troubleshooting

CI fails to publish?

  • Verify NPM_TOKEN is set in GitHub secrets
  • Check if version already exists on npm
  • Review GitHub Actions logs

Need to skip CI tests?

  • Not recommended, but you can manually publish: npm publish --access public