diff --git a/.github/workflows/tag-main-branch.yml b/.github/workflows/tag-main-branch.yml index d95af455..38c10b15 100644 --- a/.github/workflows/tag-main-branch.yml +++ b/.github/workflows/tag-main-branch.yml @@ -29,7 +29,7 @@ jobs: id: get_latest_tag run: | # Get the latest tag - latest_tag=$(git describe --tags `git rev-list --tags --max-count=1`) + latest_tag=$(git describe --tags `git rev-list --tags --max-count=1` 2>/dev/null || echo "none") echo "Latest tag: $latest_tag" echo "latest_tag=$latest_tag" >> $GITHUB_ENV @@ -37,19 +37,22 @@ jobs: id: get_next_version run: | latest_tag=$env.latest_tag - if [[ $latest_tag =~ ^v([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then + if [[ "$latest_tag" == "none" ]]; then + echo "No tags found. Starting with v0.0.1" + next_tag="v0.0.1" + elif [[ $latest_tag =~ ^v([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then major=${BASH_REMATCH[1]} minor=${BASH_REMATCH[2]} patch=${BASH_REMATCH[3]} next_patch=$((patch + 1)) next_tag="v${major}.${minor}.${next_patch}" - echo "Next tag version: $next_tag" - echo "next_tag=$next_tag" >> $GITHUB_ENV else - # Default to v0.0.1 if no valid tag found - echo "No valid tag found, starting with v0.0.1" - echo "next_tag=v0.0.1" >> $GITHUB_ENV + echo "Latest tag format is invalid, cannot determine next version." + exit 1 fi + echo "Next tag version: $next_tag" + echo "next_tag=$next_tag" >> $GITHUB_ENV + - name: Create and push new tag env: