feat: Simplify latest release tag fetching and bump strategy in release workflow

This commit is contained in:
2026-05-20 16:36:53 +02:00
parent fabac77877
commit 726520c9de
+27 -46
View File
@@ -53,57 +53,38 @@ jobs:
if [ "$EVENT_NAME" = "push" ] && [ -n "$REF_NAME" ]; then if [ "$EVENT_NAME" = "push" ] && [ -n "$REF_NAME" ]; then
TAG="$REF_NAME" TAG="$REF_NAME"
else else
TAG="$(python3 - <<'PY' # Fetch latest release tag via GitHub API (fall back to v3.0.0)
import json
import os
import re
import urllib.request
repo = os.environ["REPO"]
token = os.environ.get("GH_TOKEN", "")
bump = os.environ.get("BUMP_TYPE", "patch").strip().lower()
req = urllib.request.Request(
f"https://api.github.com/repos/{repo}/releases/latest",
headers={
"Authorization": f"Bearer {token}",
"Accept": "application/vnd.github+json",
"User-Agent": "legendary-octo-garbanzo-release-workflow",
},
)
latest_tag="v3.0.0" latest_tag="v3.0.0"
try: if meta_json=$(curl -fsSL -H "Authorization: Bearer $GH_TOKEN" -H "Accept: application/vnd.github+json" "https://api.github.com/repos/$REPO/releases/latest" 2>/dev/null); then
with urllib.request.urlopen(req, timeout=20) as resp: tag_name=$(printf "%s" "$meta_json" | sed -n 's/.*"tag_name"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' | head -n1)
data = json.loads(resp.read().decode("utf-8")) if [ -n "$tag_name" ]; then
latest_tag = (data.get("tag_name") or latest_tag).strip() latest_tag="$tag_name"
except Exception: fi
pass fi
m = re.match(r"^v(\d+)\.(\d+)\.(\d+)$", latest_tag) if [[ "$latest_tag" =~ ^v([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then
if not m: major=${BASH_REMATCH[1]}
major, minor, patch = 3, 0, 0 minor=${BASH_REMATCH[2]}
else: patch=${BASH_REMATCH[3]}
major, minor, patch = map(int, m.groups()) else
major=3; minor=0; patch=0
fi
# Bump strategy: major / minor / patch # Bump strategy: major / minor / patch
if bump == "major": if [ "${BUMP_TYPE:-}" = "major" ]; then
major += 1 major=$((major + 1)); minor=0; patch=0
minor = 0 elif [ "${BUMP_TYPE:-}" = "minor" ]; then
patch = 0 minor=$((minor + 1)); patch=0
elif bump == "minor": else
minor += 1 patch=$((patch + 1))
patch = 0 fi
else:
patch += 1
if bump == "development": if [ "${BUMP_TYPE:-}" = "development" ]; then
# use dev suffix for development releases TAG="v${major}.${minor}.${patch}-dev"
print(f"v{major}.{minor}.{patch}-dev") else
else: TAG="v${major}.${minor}.${patch}"
print(f"v{major}.{minor}.{patch}") fi
PY fi
)"
fi fi
if ! echo "$TAG" | grep -Eq '^v[0-9]+\.[0-9]+\.[0-9]+(-dev(\.[0-9]+)?)?$'; then if ! echo "$TAG" | grep -Eq '^v[0-9]+\.[0-9]+\.[0-9]+(-dev(\.[0-9]+)?)?$'; then