diff --git a/.gitea/workflows/build.yaml b/.gitea/workflows/build.yaml index d8a1679..a73d5db 100644 --- a/.gitea/workflows/build.yaml +++ b/.gitea/workflows/build.yaml @@ -153,28 +153,35 @@ jobs: - name: Run autotag id: autotag run: | - # Download autotag - AUTOTAG_VERSION="1.3.9" - curl -sL "https://github.com/autotag-dev/autotag/releases/download/v${AUTOTAG_VERSION}/autotag_linux_amd64" -o /tmp/autotag - chmod +x /tmp/autotag + # Check if any tags exist + CURRENT_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "") - # Get current version - CURRENT_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0") - echo "Current tag: $CURRENT_TAG" + if [ -z "$CURRENT_TAG" ]; then + echo "No existing tags found, starting at v0.1.0" + NEW_TAG="v0.1.0" + else + echo "Current tag: $CURRENT_TAG" - # Calculate next version based on commits - # autotag looks for #major, #minor in commit messages, defaults to patch - NEW_TAG=$(/tmp/autotag -n -b main 2>/dev/null || echo "") + # Download autotag + AUTOTAG_VERSION="1.3.9" + curl -sL "https://github.com/autotag-dev/autotag/releases/download/v${AUTOTAG_VERSION}/autotag_linux_amd64" -o /tmp/autotag + chmod +x /tmp/autotag - if [ -z "$NEW_TAG" ]; then - echo "No new tag needed or autotag failed, using fallback" - # Fallback: increment patch version - CURRENT_VERSION="${CURRENT_TAG#v}" - MAJOR=$(echo $CURRENT_VERSION | cut -d. -f1) - MINOR=$(echo $CURRENT_VERSION | cut -d. -f2) - PATCH=$(echo $CURRENT_VERSION | cut -d. -f3) - NEW_PATCH=$((PATCH + 1)) - NEW_TAG="v${MAJOR}.${MINOR}.${NEW_PATCH}" + # Calculate next version based on commits + # autotag looks for #major, #minor in commit messages, defaults to patch + NEW_TAG=$(/tmp/autotag -n -b main 2>&1 || echo "") + + # Check if autotag returned an error or empty result + if [ -z "$NEW_TAG" ] || echo "$NEW_TAG" | grep -qi "error"; then + echo "Autotag failed or returned error, using fallback" + # Fallback: increment patch version + CURRENT_VERSION="${CURRENT_TAG#v}" + MAJOR=$(echo $CURRENT_VERSION | cut -d. -f1) + MINOR=$(echo $CURRENT_VERSION | cut -d. -f2) + PATCH=$(echo $CURRENT_VERSION | cut -d. -f3) + NEW_PATCH=$((PATCH + 1)) + NEW_TAG="v${MAJOR}.${MINOR}.${NEW_PATCH}" + fi fi echo "New tag will be: $NEW_TAG"