feat: Simplify latest release tag fetching and bump strategy in release workflow
This commit is contained in:
@@ -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
|
latest_tag="v3.0.0"
|
||||||
import os
|
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
|
||||||
import re
|
tag_name=$(printf "%s" "$meta_json" | sed -n 's/.*"tag_name"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' | head -n1)
|
||||||
import urllib.request
|
if [ -n "$tag_name" ]; then
|
||||||
|
latest_tag="$tag_name"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
repo = os.environ["REPO"]
|
if [[ "$latest_tag" =~ ^v([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then
|
||||||
token = os.environ.get("GH_TOKEN", "")
|
major=${BASH_REMATCH[1]}
|
||||||
bump = os.environ.get("BUMP_TYPE", "patch").strip().lower()
|
minor=${BASH_REMATCH[2]}
|
||||||
|
patch=${BASH_REMATCH[3]}
|
||||||
req = urllib.request.Request(
|
else
|
||||||
f"https://api.github.com/repos/{repo}/releases/latest",
|
major=3; minor=0; patch=0
|
||||||
headers={
|
fi
|
||||||
"Authorization": f"Bearer {token}",
|
|
||||||
"Accept": "application/vnd.github+json",
|
|
||||||
"User-Agent": "legendary-octo-garbanzo-release-workflow",
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
latest_tag = "v3.0.0"
|
|
||||||
try:
|
|
||||||
with urllib.request.urlopen(req, timeout=20) as resp:
|
|
||||||
data = json.loads(resp.read().decode("utf-8"))
|
|
||||||
latest_tag = (data.get("tag_name") or latest_tag).strip()
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
|
|
||||||
m = re.match(r"^v(\d+)\.(\d+)\.(\d+)$", latest_tag)
|
|
||||||
if not m:
|
|
||||||
major, minor, patch = 3, 0, 0
|
|
||||||
else:
|
|
||||||
major, minor, patch = map(int, m.groups())
|
|
||||||
|
|
||||||
# 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
|
||||||
|
|||||||
Reference in New Issue
Block a user