0

I've been upgrading our workflow to add an automatic version bump. The problem is that I accidentally added these steps with a typo in the .bumpversion.cfg file and from that moment, the workflow is sure that the releases start at tag 1.0.0. I've created 2 releases with this scenario (1.0.0 and 1.0.1). Once I was on to this, I deleted the two releases (and tags), but now the workflow can't find the latest release tag.

One important piece of info is that the repo is a Node app, so there is already a package.json and such there.

I tried:

  1. bumping manually the versions in my files
  2. bumping with bump2version to the version I expected
  3. bumping with bump2version to the next version

As you'll see, the command is missing the current version. The error in the workflow is:

An error occurred while running semantic-release: Error: Command failed with exit code 2: bump2version --allow-dirty --current-version  --new-version 1.0.0 patch

the create release step is:

name: Create new release
on:
  workflow_dispatch:
  push:
    branches:
      - main
jobs:
  release:
    runs-on: ubuntu-latest
    if: "github.event_name == 'push' && github.ref == 'refs/heads/main' && !startsWith(github.event.head_commit.message, 'chore')"
    steps:
      - name: Checkout code
        uses: actions/checkout@v3
        with:
          fetch-depth: 0
          token: ${{ secrets.ADMIN_TOKEN }}

      - name: setup nodejs
        uses: actions/setup-node@v3
        with:
          node-version: '16'

      - name: release using semantic-release
        env:
          GITHUB_TOKEN: ${{ secrets.ADMIN_TOKEN }}
          GIT_AUTHOR_NAME: secrets.automation.dev
          GIT_AUTHOR_EMAIL: secrets.automation.dev@il.ibm.com
          GIT_COMMITTER_NAME: secrets.automation.dev
          GIT_COMMITTER_EMAIL: secrets.automation.dev@il.ibm.com
        run: |
          sudo apt-get update
          sudo apt-get install python
          pip install --user bumpversion
          npm install @semantic-release/changelog
          npm install @semantic-release/exec
          npm install @semantic-release/git
          npm install @semantic-release/github
          npx semantic-release

The .bumpversion.cfg is:

[bumpversion]
current_version = 1.0.40
commit = True
message = Update version {current_version} -> {new_version}

[bumpversion:file:package.json]
search = {current_version}
replace = {new_version}

The .releaserc file is:

{
  "debug": true,
  "branches": [ "main" ],
  "plugins": [
    ["@semantic-release/commit-analyzer", {
        "preset": "angular",
        "releaseRules": [
            {"type": "release","release": "patch"}
    ]}],
    "@semantic-release/release-notes-generator",
    "@semantic-release/changelog",
    [
      "@semantic-release/exec",
      {
        "prepareCmd": "bump2version --allow-dirty --current-version ${lastRelease.version} --new-version ${nextRelease.version} patch"
      }
    ],
    [
      "@semantic-release/git",
      {
        "message": "chore(release): ${nextRelease.version} [skip ci] release notes\n\n${nextRelease.notes}"
      }
    ],
    "@semantic-release/github"
  ]
}

Killerz0ne
  • 254
  • 1
  • 2
  • 12

1 Answers1

0

I used 2 things to fix the issue:

  1. I followed the excellent fix by @alvaropinot from this issue thread. Basically, I had to force-tag the commit I expected to be with the latest tag and push the tags:
git tag -f v1.0.40 356a7b4
git push -f --tags

  1. For @semantic-release/npm to work, I had to rename a secret from "NPM_AUTH_TOKEN" to "NPM_TOKEN".
  2. After that, I revamped my semantic-release workflow to use @semantic-release/npm:
name: Create a new release
on:
  workflow_dispatch:
  push:
    branches:
      - main
jobs:
  release:
    runs-on: Ubuntu-20.04
    if: "github.event_name == 'push' && github.ref == 'refs/heads/main' && !startsWith(github.event.head_commit.message, 'chore')"
    steps:
      - name: Checkout code
        uses: actions/checkout@v3
        with:
          fetch-depth: 0
          token: ${{ secrets.ADMIN_TOKEN }}

      - name: setup nodejs
        uses: actions/setup-node@v3
        with:
          node-version: '16'

      - name: release using semantic-release
        env:
          GITHUB_TOKEN: ${{ secrets.ADMIN_TOKEN }}
          GIT_AUTHOR_NAME: ***
          GIT_AUTHOR_EMAIL: ***
          GIT_COMMITTER_NAME: ***
          GIT_COMMITTER_EMAIL: ***
          NPM_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
        run: |
          sudo apt-get update
          sudo apt-get install python
          pip install --user bumpversion
          npm install @semantic-release/changelog
          npm install @semantic-release/git
          npm install @semantic-release/github
          npm install @semantic-release/npm
          npx semantic-release

and the .releaserc file now looks like:

{
  "debug": true,
  "branches": [
    "main"
  ],
  "verifyConditions": [
    "@semantic-release/changelog",
    "@semantic-release/npm",
    "@semantic-release/git"
  ],
  "analyzeCommits":[
    ["@semantic-release/commit-analyzer", {
        "preset": "angular",
        "releaseRules": [
            {"type": "release","release": "patch"}
    ]}],
  ],
   "generateNotes": [
      "@semantic-release/release-notes-generator"
  ],
  "prepare": [
    "@semantic-release/changelog",
    "@semantic-release/npm",
    "@semantic-release/git"
  ],
  "publish": [
    [
      "@semantic-release/npm",
      {
        "pkgRoot": "dist"
      }
    ],
    {
      "path": "@semantic-release/github"
    }
  ]
}
Killerz0ne
  • 254
  • 1
  • 2
  • 12