Skip to main content

Examples

Using the branches filter

In case you want to reduce the amount of the release workflow runs, you can configure a workflow to run only for pull requests that target specific branches. Example:

name: release

on:
...
pull_request:
types: [closed]
branches:
- master
- 'release/**'

Multiple users scenario

In case there are multiple users who have access to trigger the release automation action, you can define npm and Optic tokens for different users in GitHub secrets. Following is an example of a way to use different tokens depending on the user who merged the pull request.

  • Use only default tokens: e.g. npm-token: ${{ secrets.NPM_TOKEN }}
  • Use only user-related tokens: e.g. npm-token: ${{ secrets[format('NPM_TOKEN_{0}', github.actor)] }}
  • Use both user-related and default token: e.g. npm-token: ${{ secrets[format('NPM_TOKEN_{0}', github.actor)] || secrets.NPM_TOKEN }}
# ...
jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: nearform-actions/optic-release-automation-action@v4
with:
npm-token: ${{ secrets[format('NPM_TOKEN_{0}', github.actor)] || secrets.NPM_TOKEN }}
optic-token: ${{ secrets[format('OPTIC_TOKEN_{0}', github.actor)] || secrets.OPTIC_TOKEN }}
semver: ${{ github.event.inputs.semver }}
npm-tag: ${{ github.event.inputs.tag }}

Not all symbols that can be used in GitHub usernames are valid in secret names. One such example is the hyphen symbol (-). In such cases, this approach will not work.

Adding a build step to your workflow

When your project needs a build step, you can provide it to this action! The build-command option accepts a string that will be executed as a shell command (you can use yarn or your preferred build tool).

It is important to be aware that you are responsible for:

  1. The context where the command is executed.
    The command will be executed using the current GitHub runner configuration (e.g. the one set on runs-on). You can customize it by executing additional steps before the nearform-actions/optic-release-automation-action step execution as shown in the next example.
  2. The command to build the project, starting from the installation to the cleanup if needed.
    You can set any automations like git hooks or pre/post scripts to execute within the build-command step.

The build's output will be committed to the release/${new semver version} branch, unless the project's .gitignore blocks it. In that case, the build's output will be packed into the npm package during the release process.

Here an example using npm to build the project:

# ...
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Optionally configure your preferred runtime
uses: actions/setup-node@v3
with:
node-version: 14 # setting a specific version of node as an example

- uses: nearform-actions/optic-release-automation-action@v4
with:
npm-token: ${{ secrets.NPM_TOKEN }}
optic-token: ${{ secrets.OPTIC_TOKEN }}
semver: ${{ github.event.inputs.semver }}
build-command: |
npm install
npm run build