Improve version extraction in release workflow

Add file existence check and debug output. Use grep/sed to capture the
first three-part version and fall back to stripping a prerelease suffix.
Validate the final version matches major.minor.patch and fail with debug
output if extraction fails
This commit is contained in:
kmmiio99o 2025-10-18 12:49:59 +02:00
parent 101e5728d8
commit 6cade8b8f4

View file

@ -33,13 +33,32 @@ jobs:
- name: Extract base version
id: extract
run: |
# Extract base (non-prerelease) version like 1.1.4 from src/modules.d.ts
# Use a strict regex to capture exactly three numeric components (major.minor.patch)
version=$(sed -nE 's/.*"([0-9]+\.[0-9]+\.[0-9]+)".*/\1/p' src/modules.d.ts | head -n1)
if [ -z "$version" ]; then
echo "Failed to extract version" >&2
# Extract base version (major.minor.patch) from src/modules.d.ts using pure shell (grep/sed)
# Capture the first three-part version and ignore any prerelease suffix (e.g. "-1")
if [ ! -f src/modules.d.ts ]; then
echo "src/modules.d.ts not found" >&2
exit 1
fi
# Print the file for debugging in workflow logs
echo '--- src/modules.d.ts ---' >&2
sed -n '1,200p' src/modules.d.ts >&2 || true
# Primary extraction: match "X.Y.Z" (three numeric components) within quotes
version=$(grep -m1 -oE '"[0-9]+\.[0-9]+\.[0-9]+' src/modules.d.ts | tr -d '"' | head -n1 || true)
# Fallback: capture quoted version possibly with prerelease suffix and strip suffix
if [ -z "$version" ]; then
raw=$(grep -m1 -oE '"[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?"' src/modules.d.ts | tr -d '"' | head -n1 || true)
version=$(printf '%s' "$raw" | sed -E 's/^([0-9]+\.[0-9]+\.[0-9]+).*/\1/')
fi
# Validate final result is exactly major.minor.patch
if ! printf '%s' "$version" | grep -xE '^[0-9]+\.[0-9]+\.[0-9]+$' >/dev/null; then
echo "Failed to extract a valid base version from src/modules.d.ts" >&2
sed -n '1,200p' src/modules.d.ts >&2 || true
exit 1
fi
echo "version=$version" >> $GITHUB_OUTPUT
shell: bash