logo
2
2
Login
feat: 调整参数名,下划线替代点,升级npm库

semantic-release

semantic-release 插件, 根据历史提交信息,生成 git tagchangelog

semantic-release: 24.2.6

工作原理

在工作目录下执行自动运行 semantic-release工具。

semantoc-release 的工作时序 参考 semantic-release#release-steps

当前工具会自动执行以下 semantic-release 插件:

  • @semantic-release/commit-analyzer
  • @semantic-release/release-notes-generator
  • @semantic-release/changelog
  • @semantic-release/npm (当npm.npmPublish=true时才会加载此插件)
  • @semantic-release/git

参数

tagFormat

  • type: String
  • 必填: 否
  • 默认值: v${version}

指定 tag 格式,其中 ${version} 将会由生成的目标 tag 号替换,如 1.2.3。那么 v${version} 即为 v1.2.3

dryRun

  • type: Boolean
  • 必填: 否
  • 默认值: false

仅试运行,生成新的版本号,但不会执行git tag和发布操作。

branch

  • type: string
  • 必填: 否

自动生成 tag 依据的分支,根据这个分支获取提交日志,根据提交日志生成 tag

changelog_changelogFile

  • type: String
  • 必填: 否
  • 默认值: CHANGELOG.md

指定生成的Changelog文件的文件名

changelog_changelogTitle

  • type: String
  • 必填: 否
  • 默认值: -

指定Changelog文件的标题(第一行内容)

npm_npmPublish

  • type: Boolean
  • 必填: 否
  • 默认值: npm_token 有值时为true, 否则为false

是否发布npm包

npm_token

  • type: String
  • 必填: 否

发布 npm 包所使用的 token

npm_pkgRoot

  • type: String
  • 必填: 否
  • 默认值: .

要发布的npm包的根目录

npm_tarballDir

  • type: Boolean
  • 必填: 否
  • 默认值: false

用于写入包压缩文件(tarball)的目录路径。如果设置为 false,则不会将压缩文件保留在文件系统中。

git_message

  • type: String
  • 必填: 否
  • 默认值: chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}

发布的commit的提交信息。

git_assets

  • type: Array[String] | Boolean
  • 必填: 否
  • 默认值: ['CHANGELOG.md', 'package.json', 'package-lock.json', 'npm-shrinkwrap.json']

要包含在发布提交中的文件。
设置为 false 可禁用将文件添加到发布提交中。

resultFile

  • type: String
  • 必填: 否
  • 默认值: semantic-release-result.json

执行结果存入的文件地址,后面可用cnb:read-file内置任务读取。

输出结果

{ // https://github.com/semantic-release/semantic-release/blob/v20.1.1/docs/developer-guide/js-api.md#lastrelease lastRelease.version, // 上次发布的版本号 lastRelease.gitHead, // 上次发布的 commit lastRelease.gitTag, // 上次发布的 tag lastRelease.channel, // 上次发布的 channel // https://github.com/semantic-release/semantic-release/blob/v20.1.1/docs/developer-guide/js-api.md#commits commits, // https://github.com/semantic-release/semantic-release/blob/v20.1.1/docs/developer-guide/js-api.md#nextrelease nextRelease.type, // 本次发布的 semver 类型 nextRelease.version, // 本次发布的版本号 nextRelease.gitHead, // 本次发布的 commit nextRelease.gitTag, // 本次发布的 tag nextRelease.notes, // 本次发布的变更记录 // https://github.com/semantic-release/semantic-release/blob/v20.1.1/docs/developer-guide/js-api.md#releases releases, }

示例

docker run --rm \ -v $(pwd):$(pwd) \ -w $(pwd) \ \ -e PLUGIN_DRYRUN="true" \ \ tencentcom/semantic-release:dev
main: push: - stages: - name: semantic-release image: tencentcom/semantic-release # 配置了 NPM_TOKEN 的密钥仓库文件 imports: https://cnb.cool/xxx/xxx/-/blob/main/npm_secret.yml settings: tagFormat: v\${version} #由于$符合默认会认为是环境变量,所有加反斜杠转义 branch: main dryRun: false changelog_changelogFile: CHANGELOG.md changelog_changelogTitle: "-" # 从 imports 引入的文件中获取 npm_token: $NPM_TOKEN npm_pkgRoot: "." npm_tarballDir: false git_message: | chore(release): ${nextRelease.version} [skip ci] \${nextRelease.notes} git_assets: - CHANGELOG.md - package.json - package-lock.json - npm-shrinkwrap.json # 上面任务将结果输出到 semantic-release-result.json 文件中,该任务解析导出环境变量 - name: read file type: cnb:read-file options: filePath: semantic-release-result.json exports: nextRelease.version: VERSION - name: echo VERSION script: echo $VERSION

注意

该插件升级了依赖的 npm 库,以及调整了参数名,原参数包含 .,现改为 _,若使用旧版本,可用 tencentcom/semantic-release:v1.2.0