4

We’ve been using a branching strategy (previously along with release-it) like this:

  • main Our production branch, of course.
  • release/DEV-123-branch-name With our epics in Jira we’ve been creating an associated release/* branch. Any stories within those epics get a feature/* branch which, when completed, gets merged to the epic’s release/* branch. Every time a feature/* branch is merged into a release/* branch, we manually cut a new prerelease with release-it. The target release version number is predetermined by us for each release/* branch.
  • feature/DEV-456-branch-name feature/* branches is where all of the actual work happens. They are branched from release/* branches and merged back in via PR.

I’m trying to automate our release process with semantic-release and running into some issues. But I first want to ask, is this scenario even possible using semantic-release:

  • Automatically release a prerelease from every branch that matches release/*.
  • If there are multiple release/* branches, have each be aware of the prerelease versions in the other release/* branches and set target release version accordingly.

Can semantic-release pull something like this off? Can it manage multiple pre-releases in multiple matching branches?

This is my release.config.js file as it stands now:

/* eslint-disable no-template-curly-in-string */
module.exports = {
    branches: [
        'main',
        // version number branches will release that version
        '+([0-9])?(.{+([0-9]),x}).x',
        {
            channel: 'alpha',
            name: 'alpha/*',
            prerelease: true,
        },
    ],
    plugins: [
        '@semantic-release/commit-analyzer',
        '@semantic-release/release-notes-generator',
        '@semantic-release/npm',
        '@semantic-release/github',
        [
            '@semantic-release/git', {
                assets: [
                    'CHANGELOG.md',
                    'README.md',
                    'dist',
                    'package.json',
                    'yarn.lock',
                ],
                message: 'chore(release): ${lastRelease.version}→${nextRelease.version} [skip ci]\n\n${nextRelease.notes}',
            },
        ],
        [
            'semantic-release-slack-bot',
            {
                branchesConfig: [
                    {
                        notifyOnFail: true,
                        notifyOnSuccess: true,
                        pattern: 'main',
                    },
                    {
                        notifyOnFail: true,
                        notifyOnSuccess: true,
                        pattern: 'alpha/*',
                    },
                ],
                notifyOnFail: false,
                notifyOnSuccess: false,
            },
        ],
    ],
};

… and my GitHub workflow file:

name: Release
on:
  push:
    branches:
      - main
      - 'alpha/**'
jobs:
  release:
    name: Release
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2
        with:
          fetch-depth: 0
          persist-credentials: false
      - name: Setup Node.js
        uses: actions/setup-node@v2
        with:
          node-version: 14.17.x
      - name: Install dependencies
        run: yarn install --frozen-lockfile
      - name: Release
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
        run: npx semantic-release

That config is resulting in the following errors when the action runs:

2022-05-26T20:12:24.2348523Z [8:12:24 PM] [semantic-release] › ✖  EPRERELEASEBRANCH A pre-release branch configuration is invalid in the `branches` configuration.
2022-05-26T20:12:24.3094679Z Each pre-release branch in the branches configuration (https://github.com/semantic-release/semantic-release/blob/master/docs/usage/configuration.md#branches) must have a prerelease property valid per the Semantic Versioning Specification (https://semver.org/#spec-item-9). If the prerelease property is set to true, then the name property is used instead.
2022-05-26T20:12:24.3095492Z 
2022-05-26T20:12:24.3097305Z Your configuration for the problematic branch is { name: 'alpha/DEV-333-cl-implement-semantic-release-for-automating-releases-and-prereleases', channel: 'alpha', prerelease: true, tags: [ { gitTag: 'v0.1.1', version: '0.1.1', channels: [Array] }, { gitTag: 'v0.2.0', version: '0.2.0', channels: [Array] }, { gitTag: 'v0.3.0', version: '0.3.0', channels: [Array] }, { gitTag: 'v0.3.1', version: '0.3.1', channels: [Array] }, { gitTag: 'v0.4.0', version: '0.4.0', channels: [Array] }, ... 29 more items ] }.

This is for a component-library. Our reasoning for multiple pre-release branches is so that the app that uses this package can point to pre-release versions of our package to start incorporating those changes in the app before an official production release is done in our component-library.

Brandon Durham
  • 7,096
  • 13
  • 64
  • 101

1 Answers1

0

You are using / in your branch matcher which is a prohibited character.

I know this is old but I found it so it should be answered. Use something like . instead of / so your tags and npm releases are both valid.

        {
            name: 'alpha.*',
            prerelease: true,
        }

Then agree to name your branches alpha.{var} instead of alpha/{var}.

DJSpud
  • 101
  • 2