cycjimmy/semantic-release-action

repository·main·Indexed 20 days ago

https://github.com/cycjimmy/semantic-release-action

A GitHub Action that automates the semantic-release process for automated versioning and publishing of software based on commit messages. It supports custom plugins via extra_plugins, configurable release branches, and provides detailed outputs such as new_release_version and new_release_notes. Version 6.0.0 supports semantic-release v16+ features including the branches input and CI support.

Tokens
2.3K
Snippets
6
Records
7
Agent score
22%

What's inside cycjimmy/semantic-release-action

  1. Configure release branches for semantic-release

    main

    You can specify which branches trigger a release using the branches input (for semantic-release v16+) or the branch input (for versions older than v16). These inputs override the configuration in your repository's release config file.

    For semantic-release v16 and above (branches): Use the branches input with a YAML list. If not configured, it defaults to: ['+([0-9])?(.{+([0-9]),x}).x', 'master', 'next', 'next-major', {name: 'beta', prerelease: true}, {name: 'alpha', prerelease: true}]

    steps:
      - name: Checkout
        uses: actions/checkout@v5
      - name: Semantic Release
        uses: cycjimmy/semantic-release-action@v6
        with:
          semantic_version: 16
          branches: |
            [
              '+([0-9])?(.{+([0-9]),x}).x',
              'master',
              'next',
              'next-major',
              {
                name: 'beta',
                prerelease: true
              },
              {
                name: 'alpha',
                prerelease: true
              }
            ]
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
  2. Add extra plugins to Semantic Release

    main

    To use plugins not included in the default semantic-release list (e.g., @semantic-release/changelog or @semantic-release/git), you must perform two steps:

    1. In the GitHub Action workflow: Add the plugins to the extra_plugins input.
    2. In your Semantic Release configuration file: Add the same plugins to the plugins array.

    It is recommended to specify a version range for the plugins to prevent unexpected errors.

    # GitHub Action Workflow
    steps:
      - name: Checkout
        uses: actions/checkout@v5
      - name: Semantic Release
        uses: cycjimmy/semantic-release-action@v6
        with:
          extra_plugins: |
            @semantic-release/changelog@6.0.0
            @semantic-release/git
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
    # Release Config
      plugins: [
        .
    +   "@semantic-release/changelog"
    +   "@semantic-release/git",
      ]
  3. Setup Semantic Release Action in GitHub Actions

    main

    To use cycjimmy/semantic-release-action, follow these three steps:

    1. Configure Semantic Release: Set up your Semantic Release configuration in your repository.
    2. Add Secrets: Add the necessary authentication environment variables (like GITHUB_TOKEN and NPM_TOKEN) to your GitHub repository secrets.
    3. Add a Workflow File: Create a GitHub Actions workflow file to trigger the release process.

    Important: Protected Branches

    GITHUB_TOKEN does not have sufficient permissions to operate on protected branches. If your release process targets protected branches, you must use a Personal Access Token instead.

    If you are using the @semantic-release/git plugin on protected branches, ensure you set persist-credentials: false in your actions/checkout step to avoid credential persistence issues.

    steps:
      - name: Checkout
        uses: actions/checkout@v5
        with:
          persist-credentials: false
      - name: Semantic Release
        uses: cycjimmy/semantic-release-action@v6
        env:
          GITHUB_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
          NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
  4. Use the Semantic Release Action in a GitHub Workflow

    main

    The semantic-release-action is a GitHub Action that automates the semantic release process. It handles environment setup, installs semantic-release, executes extra plugins or extended configurations, and runs the release process.

    To use it, you must first ensure your repository has a valid Semantic Release Configuration and the necessary Authentication Secrets (such as GH_TOKEN or NPM_TOKEN) configured in your repository settings.

    steps:
      - name: Release
        uses: cycjimmy/semantic-release-action@v4
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
  5. Access Semantic Release Action outputs

    main

    You can access information about the release (such as the new version or release notes) in subsequent steps by assigning an id to the action step.

    Available Outputs:

    • new_release_published: String ("true" or "false") indicating if a release was published.
    • new_release_version: The version of the new release (e.g., "1.3.0").
    • new_release_major_version: Major version (e.g., "1").
    • new_release_minor_version: Minor version (e.g., "3").
    • new_release_patch_version: Patch version (e.g., "0").
    • new_release_channel: The distribution channel used.
    • new_release_notes: The release notes.
    • new_release_git_head: SHA of the last commit in the new release.
    • new_release_git_tag: The Git tag associated with the release.
    • last_release_version: Version of the previous release.
    • last_release_git_head: SHA of the last commit in the previous release.
    • last_release_git_tag: Git tag of the previous release.
    steps:
      - name: Checkout
        uses: actions/checkout@v5
      - name: Semantic Release
        uses: cycjimmy/semantic-release-action@v6
        id: semantic   # Required to use outputs
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
    
      - name: Do something when a new release published
        if: steps.semantic.outputs.new_release_published == 'true'
        run: |
          echo ${{ steps.semantic.outputs.new_release_version }}
          echo ${{ steps.semantic.outputs.new_release_major_version }}
  6. Configure Semantic Release Action Inputs

    main

    The following input parameters are available for cycjimmy/semantic-release-action@v6:

    Input ParameterRequiredDescription
    semantic_versionfalseSpecify version range for semantic-release.
    branchesfalseThe branches on which releases should happen (Supports semantic-release above v16).
    branchfalseThe branch on which releases should happen (Only supports semantic-release older than v16).
    extra_pluginsfalseExtra plugins for pre-install.
    dry_runfalseWhether to run semantic release in dry-run mode.
    cifalseWhether to run semantic release with CI support (Supports semantic-release above v16).
    unset_gha_envfalseWhether to unset the GITHUB_ACTIONS environment variable.
    extendsfalseUse a sharable configuration.
    working_directoryfalseUse another working directory for semantic release.
    tag_formatfalseSpecify format of tag (useful for monorepos).
    repository_urlfalseThe Git repository url. Defaults to current repository.