logo
1
2
WeChat Login

semantic-release

semantic-release plugin, which generates git tag and changelog based on commit history.

semantic-release: 24.2.6

How It Works

Automatically runs the semantic-release tool in the working directory.

For the workflow of semantic-release, refer to semantic-release#release-steps.

The current tool automatically executes the following semantic-release plugins:

  • @semantic-release/commit-analyzer
  • @semantic-release/release-notes-generator
  • @semantic-release/changelog
  • @semantic-release/npm (loaded only when npm.npmPublish=true)
  • @semantic-release/git

Parameters

tagFormat

  • Type: String
  • Required: No
  • Default: v${version}

Specifies the tag format, where ${version} will be replaced by the generated target tag, e.g., 1.2.3. Thus, v${version} becomes v1.2.3.

dryRun

  • Type: Boolean
  • Required: No
  • Default: false

Runs in dry-run mode, generating a new version number but without executing git tag or publishing.

branch

  • Type: String
  • Required: No

The branch used to generate the tag. The commit logs from this branch are used to determine the tag.

changelog_changelogFile

  • Type: String
  • Required: No
  • Default: CHANGELOG.md

Specifies the filename for the generated changelog file.

changelog_changelogTitle

  • Type: String
  • Required: No
  • Default: -

Specifies the title (first line) of the changelog file.

npm_npmPublish

  • Type: Boolean
  • Required: No
  • Default: true if npm_token is set, otherwise false

Whether to publish the npm package.

npm_token

  • Type: String
  • Required: No

The token used to publish the npm package.

npm_pkgRoot

  • Type: String
  • Required: No
  • Default: .

The root directory of the npm package to be published.

npm_tarballDir

  • Type: Boolean
  • Required: No
  • Default: false

The directory path to write the package tarball. If set to false, the tarball will not be saved to the file system.

git_message

  • Type: String
  • Required: No
  • Default: chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}

The commit message for the release commit.

git_assets

  • Type: Array[String] | Boolean
  • Required: No
  • Default: ['CHANGELOG.md', 'package.json', 'package-lock.json', 'npm-shrinkwrap.json']

Files to include in the release commit.
Set to false to disable adding files to the release commit.

resultFile

  • Type: String
  • Required: No
  • Default: semantic-release-result.json

The file path to store the execution result, which can later be read using the cnb:read-file built-in task.

Output

{
    // https://github.com/semantic-release/semantic-release/blob/v20.1.1/docs/developer-guide/js-api.md#lastrelease
    lastRelease.version, // Last release version
    lastRelease.gitHead, // Last release commit
    lastRelease.gitTag, // Last release tag
    lastRelease.channel, // Last release 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 type of this release
    nextRelease.version, // Version of this release
    nextRelease.gitHead, // Commit of this release
    nextRelease.gitTag, // Tag of this release
    nextRelease.notes, // Changelog of this release
    // https://github.com/semantic-release/semantic-release/blob/v20.1.1/docs/developer-guide/js-api.md#releases
    releases,
}

Example

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:dev
          # Secret repository file with NPM_TOKEN configured
          imports: https://cnb.cool/xxx/xxx/-/blob/main/npm_secret.yml
          settings:
            tagFormat: v\${version} # Escape $ to avoid being treated as an environment variable
            branch: main
            dryRun: false
            changelog_changelogFile: CHANGELOG.md
            changelog_changelogTitle: "-"
            # Retrieved from the imported file
            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
        # The above task outputs the result to semantic-release-result.json,
        # which is then parsed to export environment variables
        - name: read file
          type: cnb:read-file
          options:
            filePath: semantic-release-result.json
          exports:
            nextRelease.version: VERSION
        - name: echo VERSION
          script: echo $VERSION

Note

This plugin has upgraded its dependent npm libraries and adjusted parameter names. Parameters that originally contained . have been changed to _. If you are using an older version, you can use tencentcom/semantic-release:v1.2.0.

About

semantic-release

920.00 KiB
1 forks2 stars1 branches1 TagREADMEMIT license
Language
Markdown68.6%
JavaScript22.1%
Shell3.8%
License3.5%
Others2%