Recognize vX.X.X-rc.N tags in version.sh and automatically mark them as pre-releases when creating Forgejo releases via create-release.sh. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
42 lines
1.3 KiB
Shell
Executable file
42 lines
1.3 KiB
Shell
Executable file
#!/bin/sh
|
|
# Extract version info from git tags
|
|
# Outputs two lines:
|
|
# Line 1: Version name (e.g., 1.2.3, 1.2.3-rc.1, or 1.2.3-dev-abc1234)
|
|
# Line 2: Version code (total commit count, monotonically increasing integer)
|
|
#
|
|
# Usage: sh scripts/version.sh
|
|
# VERSION_NAME=$(sh scripts/version.sh | head -1)
|
|
# VERSION_CODE=$(sh scripts/version.sh | tail -1)
|
|
|
|
set -e
|
|
|
|
# Ensure tags are available (handles shallow clones in CI)
|
|
git fetch --tags --quiet 2>/dev/null || true
|
|
|
|
# Get the short SHA of the current commit
|
|
SHORT_SHA=$(git rev-parse --short HEAD)
|
|
|
|
# Try to get a version tag on the current commit (release or pre-release)
|
|
CURRENT_TAG=$(git tag --points-at HEAD 2>/dev/null | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+(-rc\.[0-9]+)?$' | head -1 || true)
|
|
|
|
if [ -n "$CURRENT_TAG" ]; then
|
|
# Current commit is tagged — use the tag directly
|
|
VERSION_NAME=$(echo "$CURRENT_TAG" | sed 's/^v//')
|
|
else
|
|
# Find the latest version tag in history
|
|
LATEST_TAG=$(git describe --tags --match 'v[0-9]*.[0-9]*.[0-9]*' --abbrev=0 2>/dev/null || true)
|
|
|
|
if [ -n "$LATEST_TAG" ]; then
|
|
BASE_VERSION=$(echo "$LATEST_TAG" | sed 's/^v//')
|
|
else
|
|
BASE_VERSION="0.0.0"
|
|
fi
|
|
|
|
VERSION_NAME="${BASE_VERSION}-dev-${SHORT_SHA}"
|
|
fi
|
|
|
|
# Version code: total number of commits (monotonically increasing)
|
|
VERSION_CODE=$(git rev-list --count HEAD)
|
|
|
|
echo "$VERSION_NAME"
|
|
echo "$VERSION_CODE"
|