jscutlery / semver

Nx plugin to automate semantic versioning and CHANGELOG generation.
MIT License
724 stars 84 forks source link

Error Finding Base Tag 'last-release' During GitHub Action Execution #845

Open mohijalili opened 1 month ago

mohijalili commented 1 month ago

Description

I am encountering an issue when running the semver for the first time and subsequently when triggered by GitHub Actions. Initially, I receive the following message:

[lib1] 🟠 No previous version tag found, fallback to version 0.0.0.
New version will be calculated based on all changes since first commit.
If your project is already versioned, please tag the latest release commit with lib1_x.y.z and run this command again.

After removing the tags and running the action again, I encounter this error:

Run npx nx affected --base=last-release --target=version --baseBranch=main --trackDeps=true --allowEmptyRelease=true --dry-run=true

fatal: ambiguous argument 'last-release': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
nx affected
Run target for affected projects
...
Error: Command failed: git diff --name-only --no-renames --relative "last-release" "HEAD"
fatal: ambiguous argument 'last-release': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
...

GitHub Action Configuration

Below is the configuration of my GitHub Action for semantic release:

name: Semantic Release

on:
  push:
    branches: ['main']
  workflow_dispatch:

jobs:
  release:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 0
      - name: Use Node.js
        uses: actions/setup-node@v4.0.2
        with:
          node-version: 18.10.0
      - name: Setup Git
        run: |
          git config --global user.email ${{ secrets }}
          git config --global user.name ${{secrets }}
          git config --global credential.helper store
      - run: npm ci
      - name: Version
        shell: bash
        run: npx nx affected --base=last-release --target=version --baseBranch=main --trackDeps=true --allowEmptyRelease=true --dry-run=true
      - name: Tag last-release
        shell: bash
        run: |
          git tag -f last-release
          echo "https://${{ secrets }}:${{ secrets }}@github.com/${{ github.repository }}.git" > .git/credentials
          git push origin last-release --force

Each project has the following config:

    "version": {
      "executor": "@jscutlery/semver:version",
      "options": {
        "preset": "angular",
        "baseBranch": "HEAD:main",
        "tagPrefix": "lib1_",
        "push": true,
        "trackDeps": true,
        "commitMessageFormat": "feat({projectName}): release version {version} [skip ci]"
      }
    }

Additional Context

mohijalili commented 1 month ago

Hey @edbzn , Can you help me out?

christiankaseburg commented 1 month ago

Hey, @mohijalili have you tried creating a light weight “last-release” tag based on a specific commit and pushing it from your local to your remote before running your workflow?

For example, create a tag based off the commit you want to start from on your local “git tag last-release COMMIT_HASH”. Then, push it to your remote “git push origin last-release” and start your release on GitHub.

Side note, you should remove the baseBranch, allowEmptyRelease, and dry-run flags from your version job in your workflow before running if you want to create a release.

mohijalili commented 1 month ago

Hey, @mohijalili have you tried creating a light weight “last-release” tag based on a specific commit and pushing it from your local to your remote before running your workflow?

For example, create a tag based off the commit you want to start from on your local “git tag last-release COMMIT_HASH”. Then, push it to your remote “git push origin last-release” and start your release on GitHub.

Side note, you should remove the baseBranch, allowEmptyRelease, and dry-run flags from your version job in your workflow before running if you want to create a release.

@christiankaseburg Yeah, I tried it and, like you said, I ran into two different errors while setting up semver. (you can find it in the initial description) Can you explain why I should remove baseBranch, allowEmptyRelease, and dry-run?