fix: Handle missing initial tag in autotag step

This commit is contained in:
Patrick de Ruiter 2025-12-26 01:52:00 +01:00
parent 0789d09501
commit 3e581d7fe8
Signed by: pderuiter
GPG Key ID: 5EBA7F21CF583321

View File

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