Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,18 @@ jobs:
SHORT_SHA="$(git rev-parse --short HEAD)"
echo "version=0.0.0-main.${SHORT_SHA}" >> "$GITHUB_OUTPUT"
else
BRANCH="$(echo '${{ github.ref_name }}' | sed 's|[^a-zA-Z0-9._-]|-|g' | cut -c1-50)"
# Sanitize the branch name into a valid SemVer prerelease identifier:
RAW_BRANCH="${{ github.ref_name }}"
# 1) replace any char that is not alphanumeric, dot or hyphen with a hyphen (e.g. "/" -> "-")
BRANCH="$(echo "$RAW_BRANCH" | sed 's|[^a-zA-Z0-9._-]|-|g')"
# 2) collapse consecutive dots into a single dot to avoid empty SemVer identifiers (e.g. "a..b" -> "a.b")
BRANCH="$(echo "$BRANCH" | sed -E 's/[.]+/./g')"
# 3) strip leading/trailing dots or hyphens, which are invalid at the start/end of a SemVer identifier
BRANCH="$(echo "$BRANCH" | sed -E 's/^[.-]+//; s/[.-]+$//')"
# 4) truncate to 50 chars to keep the resulting version reasonably short
BRANCH="$(echo "$BRANCH" | cut -c1-50)"
# 5) strip trailing dots/hyphens again in case truncation cut right after a separator
BRANCH="$(echo "$BRANCH" | sed -E 's/[.-]+$//')"
SHORT_SHA="$(git rev-parse --short HEAD)"
echo "version=0.0.0-snapshot.${BRANCH}.${SHORT_SHA}" >> "$GITHUB_OUTPUT"
fi
Expand Down