GitHub Actions

Environment variables

The Authenticationarrow-up-right environment variables can be configured with Secret Variablesarrow-up-right.

In this example a publish type NPM_TOKENarrow-up-right is required to publish a package to the npm registry. GitHub Actions automatically populatearrow-up-right a GITHUB_TOKENarrow-up-right environment variable which can be used in Workflows.

Node project configuration

GitHub Actionsarrow-up-right support Workflowsarrow-up-right, allowing to run tests on multiple Node versions and publish a release only when all test pass.

Note: The publish pipeline must run on a Node version that meets our version requirement.

.github/workflows/release.yml configuration for Node projects

The following is a minimal configuration for semantic-releasearrow-up-right with a build running on the latest LTS version of Node when a new commit is pushed to a master branch. See Configuring a Workflowarrow-up-right for additional configuration options.

name: Release
on:
  push:
    branches:
      - master
jobs:
  release:
    name: Release
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2
        with:
          fetch-depth: 0
      - name: Setup Node.js
        uses: actions/setup-node@v2
        with:
          node-version: 'lts/*'
      - name: Install dependencies
        run: npm ci
      - name: Release
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
        run: npx semantic-release

Pushing package.json changes to a master branch

To keep package.json updated in the master branch, @semantic-release/gitarrow-up-right plugin can be used.

Note: Automatically populated GITHUB_TOKEN cannot be used if branch protection is enabled for the target branch. It is not advised to mitigate this limitation by overriding an automatically populated GITHUB_TOKEN variable with a Personal Access Tokensarrow-up-right, as it poses a security risk. Since Secret Variables are available for Workflows triggered by any branch, it becomes a potential vector of attack, where a Workflow triggered from a non-protected branch can expose and use a token with elevated permissions, yielding branch protection insignificant. One can use Personal Access Tokens in trusted environments, where all developers should have the ability to perform administrative actions in the given repository and branch protection is enabled solely for convenience purposes, to remind about required reviews or CI checks.

If the risk is acceptable, some extra configuration is needed. The actions/checkout persist-credentialsarrow-up-right option needs to be false, otherwise the generated GITHUB_TOKEN will interfere with the custom one. Example:

Trigger semantic-release on demand

Using GUI:

You can use Manual Triggersarrow-up-right for GitHub Actions.

Using HTTP:

Use repository_dispatcharrow-up-right event to have control on when to generate a release by making an HTTP request, e.g.:

To trigger a release, call (with a Personal Access Tokensarrow-up-right stored in GITHUB_TOKEN environment variable):

Using 3rd party apps:

If you'd like to use a GitHub app to manage this instead of creating a personal access token, you could consider using a project like:

Last updated

Was this helpful?