release-please-action

repository·main·Indexed 25 days ago

https://github.com/googleapis/release-please-action

A GitHub Action that automates software releases by parsing Conventional Commit messages to create release Pull Requests and tags. It supports SemVer automation, CHANGELOG generation, and various release types, including monorepo support via manifest configurations. Version 5.0.0.

Tokens
10.4K
Snippets
12
Records
19
Agent score
32%

What's inside release-please-action

  1. Use Conventional Commits for SemVer automation

    main

    Release Please uses Conventional Commit prefixes to determine the next SemVer version:

    • fix:: Correlates to a patch release.
    • feat:: Correlates to a minor release.
    • feat!:, fix!:, refactor!:, etc.: The ! indicates a breaking change, resulting in a major release.
  2. How Release Please works

    main

    Release Please automates CHANGELOG generation, GitHub release creation, and version bumps by parsing git history for Conventional Commit messages.

    Instead of releasing immediately upon merging to a default branch, it maintains Release PRs. These PRs are kept up-to-date as new work is merged. When you are ready to release, you simply merge the Release PR, which triggers the actual release and tagging.

  3. Configure GitHub Credentials for Release Please

    main

    Release Please requires a GitHub token to access the GitHub API, which is configured via the token option.

    If you use the default GITHUB_TOKEN secret, GitHub will prevent actions triggered by Release Please (such as release tags or release pull requests) from starting subsequent workflows to avoid infinite loops.

    To ensure that CI checks and other workflows run automatically on Release Please's PRs and releases, you must use a Personal Access Token (PAT) stored as a GitHub Actions secret.

  4. Access path-prefixed outputs in monorepos

    main

    In a monorepo, outputs for specific components are prefixed with the component's path. If the path contains a /, you must use JavaScript-style property access to retrieve the value from the steps.<id>.outputs object.

    run: npm publish --workflow packages/my-module
    if: ${{ steps.release.outputs['packages/my-module--release_created'] }}
  5. Migrate package options from GitHub Action inputs to manifest configuration

    main

    In version 4, advanced options previously passed as GitHub Action inputs must now be configured within the release-please manifest configuration file.

    Options are categorized into two types:

    1. Root-only options: These are configured at the top level of the manifest (e.g., $.plugins, $.always-update).
    2. Package-only or Root/Package options: These can be configured at the root level or specifically for a package within the $.packages[path] object (e.g., $.packages[path].changelog-path, $.packages[path].version-file).

    Refer to the mapping table for exact key transformations.

    | Old Option                         | New Option                                                                  |
    | ---------------------------------- | --------------------------------------------------------------------------- |
    | `path`                             | `$.packages`                                                                |
    | `changelog-path`                   | `$.packages[path].changelog-path`                                           |
    | `component`                        | `$.packages[path].component`                                                |
    | `package-name`                     | `$.packages[path].package-name`                                             |
    | `always-link-local`                | `$.always-link-local`                                                       |
    | `always-update`                    | `$.always-update`                                                           |
    | `bootstrap-sha`                    | `$.bootstrap-sha`                                                           |
    | `commit-search-depth`              | `$.commit-search-depth`                                                      |
    | `group-pull-request-title-pattern` | `$.group-pull-request-title-pattern`                                        |
    | `last-release-sha`                 | `$.last-release-sha`                                                        |
    | `plugins`                          | `$.plugins`                                                                 |
    | `release-search-depth`             | `$.release-search-depth`                                                    |
    | `sequential-calls`                  | `$.sequential-calls`                                                        |
    | `skip-labeling`                    | `$.skip-labeling`                                                           |
    | `signoff`                           | `$.signoff`                                                                 |
    | `bump-minor-pre-major`             | `$.bump-minor-pre-major` or `$.packages[path].bump-minor-pre-major`          |
    | `bump-patch-for-minor-pre-major`   | `$.bump-path-for-minor-pre-major` or `$.packages[path].bump-path-for-minor-pre-major` |
    | `changelog-host`                   | `$.changelog-host` or `$.packages[path].changelog-host`                     |
    | `changelog-notes-type`             | `$.changelog-type` or `$.packages[path].changelog-type`                     |
    | `changelog-types`                  | `$.changelog-sections` or `$.packages[path].changelog-sections`             |
    | `component-no-space`               | `$.component-no-space` or `$.packages[path].component-no-space`             |
    | `date-format`                      | `$.date-format` or `$.packages[path].date-format`                           |
    | `draft`                            | `$.draft` or `$.packages[path].draft`                                       |
    | `draft-pull-request`               | `$.draft-pull-request` or `$.packages[path].draft-pull-request`              |
    | `exclude-paths`                    | `$.exclude-paths` or `$.packages[path].exclude-paths`                       |
    | `extra-files`                      | `$.extra-files` or `$.packages[path].extra-files`                           |
    | `extra-labels`                     | `$.extra-labels` or `$.packages[path].extra-labels`                         |
    | `include-v-in-tag`                 | `$.include-v-in-tag` or `$.packages[path].include-v-in-tag`                   |
    | `initial-version`                  | `$.initial-version` or `$.packages[path].initial-version`                   |
    | `labels`                           | `$.label` or `$.packages[path].label`                                       |
    | `monorepo-tags`                    | `$.include-component-in-tag` or `$.packages[path].include-component-in-tag` |
    | `prerelease`                       | `$.prerelease` or `$.packages[path].prerelease`                             |
    | `prerelease-type`                  | `$.prerelease-type` or `$.packages[path].prerelease-type`                   |
    | `pull-request-footer`              | `$.pull-request-footer` or `$.packages[path].pull-request-footer`           |
    | `pull-request-header`              | `$.pull-request-header` or `$.packages[path].pull-request-header`           |
    | `pull-request-title-pattern`       | `$.pull-request-title-pattern` or `$.packages[path].pull-request-title-pattern` |
    | `release-as`                       | `$.release-as` or `$.packages[path].release-as`                             |
    | `release-labels`                   | `$.release-label` or `$.packages[path].release-label`                       |
    | `release-type`                     | `$.release-type` or `$.packages[path].release-type`                         |
    | `separate-pull-requests`           | `$.separate-pull-requests` or `$.packages[path].separate-pull-requests`       |
    | `skip-changelog`                   | `$.skip-changelog` or `$.packages[path].skip-changelog`                     |
    | `skip-github-release`              | `$.skip-github-release` or `$.packages[path].skip-github-release`           |
    | `skip-snapshot`                    | `$.skip-snapshot` or `$.packages[path].skip-snapshot`                       |
    | `snapshot-labels`                  | `$.snapshot-label` or `$.packages[path].snapshot-label`                     |
    | `tag-separator`                    | `$.tag-separator` or `$.packages[path].tag-separator`                       |
    | `version-file`                     | `$.version-file` or `$.packages[path].version-file`                         |
    | `versioning-strategy`              | `$.versioning-strategy` or `$.packages[path].versioning-strategy`           |
  6. Configure Advanced Release Settings with Manifests

    main

    For complex repositories (e.g., monorepos or custom release logic), use a manifest config. You must specify the paths to your configuration and manifest files using config-file and manifest-file inputs.

    steps:
      - uses: googleapis/release-please-action@v4
        with:
          token: ${{ secrets.MY_RELEASE_PLEASE_TOKEN }}
          # Path to release-please-config.json
          config-file: release-please-config.json
          # Path to .release-please-manifest.json
          manifest-file: .release-please-manifest.json
  7. Migrate command configurations from v3 to v4

    main

    When upgrading from version 3 to version 4, the command option is replaced by specific configuration flags in the release-please manifest. Use the following mapping to update your setup:

    • If you used github-release (tagging only): Set skip-github-pull-request: true.
    • If you used release-pr (opening PRs only): Set skip-github-release: true.
    • If you used manifest (using a manifest file): Do not set the release-type option; this is now the default behavior.
    • If you used manifest-pr (using a manifest and opening PRs only): Set skip-github-release: true and do not set the release-type option.
    | Command          | New Configuration                                                | Description                                                                                                                                                                                           |
    | ---------------- | ---------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
    | `github-release` | `skip-github-pull-request: true`                                 | This command was used for only tagging releases. Now we tell release-please to skip opening release PRs.                                                                                                   |
    | `release-pr`     | `skip-github-release: true`                                      | This command was used for only opening release PRs. Now we tell release-please to skip tagging releases.                                                                                                   |
    | `manifest`       | do not set `release-type` option                                | This command told release-please to use a manifest config file. This is now the default behavior unless you explicitly set a `release-type`.                                                               |
    | `manifest-pr`    | `skip-github-release: true` and do not set `release-type` option | This command told release-please to use a manifest config file and only open the pull request.                                                                                                           |
  8. Set up Basic Configuration for Release Please Action

    main

    To automate releases using Conventional Commits, create a .github/workflows/release-please.yml file. This basic setup uses a release-type to define the strategy.

    Prerequisites:

    • Ensure your commits follow the Conventional Commits convention.
    • Create a Personal Access Token (PAT) and store it as a GitHub Action secret (e.g., MY_RELEASE_PLEASE_TOKEN). While the action defaults to secrets.GITHUB_TOKEN, using a PAT is often necessary for certain workflows.

    Permissions Required:

    • contents: write
    • issues: write
    • pull-requests: write
    on:
      push:
        branches:
          - main
    
    permissions:
      contents: write
      issues: write
      pull-requests: write
    
    name: release-please
    
    jobs:
      release-please:
        runs-on: ubuntu-latest
        steps:
          - uses: googleapis/release-please-action@v4
            with:
              # Use your PAT stored in secrets
              token: ${{ secrets.MY_RELEASE_PLEASE_TOKEN }}
              # Defines the release strategy
              release-type: simple
  9. Configure Workflow Permissions for Release Please

    main

    To allow Release Please to manage releases, tags, and pull requests, your GitHub Actions workflow file must explicitly define the following permissions:

    • contents: write: Required for creating release tags and updating files.
    • issues: write: Required for managing issues.
    • pull-requests: write: Required for creating and managing release pull requests.

    Additionally, if your repository is part of an organization, you may need to enable the setting 'Allow GitHub Actions to create and approve pull requests' under Settings > Actions > General in your repository settings.

    permissions:
      contents: write
      issues: write
      pull-requests: write
  10. How release-please-action manages manifests

    main

    The action determines how to manage your project's versioning and releases using one of two modes based on the release-type input:

    1. Manifest-from-Config Mode: If release-type is provided, the action builds a manifest dynamically from your configuration. This is useful for quick setups or when you want to define release parameters directly in the action workflow.

    2. Manifest-from-File Mode: If release-type is NOT provided, the action loads the manifest from the files specified by config-file (default: release-please-config.json) and manifest-file (default: .release-please-manifest.json). This is the standard mode for complex or multi-package repositories where state is persisted in the repository.

    In both modes, the action can override the changelogHost for all paths if the changelog-host input is provided and differs from the default GitHub server URL.

  11. Attach files to the GitHub release

    main

    Use the gh CLI tool (available on all GitHub runners) and the tag_name output to upload release artifacts to the newly created GitHub release.

    on:
      push:
        branches:
          - main
    name: release-please
    jobs:
      release-please:
        runs-on: ubuntu-latest
        steps:
          - uses: googleapis/release-please-action@v4
            id: release
            with:
              release-type: node
          - name: Upload Release Artifact
            if: ${{ steps.release.outputs.release_created }}
            env:
              GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
            run: gh release upload ${{ steps.release.outputs.tag_name }} ./artifact/some-build-artifact.zip
  12. Create major and minor version tags

    main

    For GitHub Actions or libraries where users pin to major/minor versions (e.g., v2 or v2.8), you can use the major, minor, and release_created outputs to manually create and push these tags via a shell script in your workflow.

    on:
      push:
        branches:
          - main
    name: release-please
    jobs:
      release-please:
        runs-on: ubuntu-latest
        steps:
          - uses: googleapis/release-please-action@v4
            id: release
            with:
              release-type: node
          - uses: actions/checkout@v4
          - name: tag major and minor versions
            if: ${{ steps.release.outputs.release_created }}
            run: |
              git config user.name github-actions[bot]
              git config user.email 41898282+github-actions[bot]@users.noreply.github.com
              git remote add gh-token "https://${{ secrets.GITHUB_TOKEN }}@github.com/googleapis/release-please-action.git"
              git tag -d v${{ steps.release.outputs.major }} || true
              git tag -d v${{ steps.release.outputs.major }}.${{ steps.release.outputs.minor }} || true
              git push origin :v${{ steps.release.outputs.major }} || true
              git push origin :v${{ steps.release.outputs.major }}.${{ steps.release.outputs.minor }} || true
              git tag -a v${{ steps.release.outputs.major }} -m "Release v${{ steps.release.outputs.major }}"
              git tag -a v${{ steps.release.outputs.major }}.${{ steps.release.outputs.minor }} -m "Release v${{ steps.release.outputs.major }}.${{ steps.release.outputs.minor }}"
              git push origin v${{ steps.release.outputs.major }}
              git push origin v${{ steps.release.outputs.major }}.${{ steps.release.outputs.minor }}