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
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"