fix(release): add tag detection fallback for workflow_call input issues
This commit is contained in:
@@ -36,36 +36,52 @@ jobs:
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Resolve release version
|
||||
id: resolve-version
|
||||
env:
|
||||
REQUESTED_TAG: ${{ inputs.tag }}
|
||||
- name: Fetch and detect release tag
|
||||
id: detect-tag
|
||||
run: |
|
||||
set -euo pipefail
|
||||
|
||||
requested_tag="$(printf '%s' "${REQUESTED_TAG:-}" | sed 's/^[[:space:]]\+//; s/[[:space:]]\+$//')"
|
||||
# Fetch all tags from origin to ensure we have the latest
|
||||
git fetch origin --tags --force --quiet 2>/dev/null || true
|
||||
|
||||
# Try to find the most recent tag (in case it was just created by prepare-release)
|
||||
latest_tag="$(git describe --tags --abbrev=0 2>/dev/null || echo '')"
|
||||
|
||||
if [[ -n "$latest_tag" ]]; then
|
||||
echo "detected_tag=$latest_tag" >> "$GITHUB_OUTPUT"
|
||||
fi
|
||||
|
||||
- name: Resolve release version
|
||||
id: resolve-version
|
||||
env:
|
||||
INPUT_TAG: ${{ inputs.tag }}
|
||||
DETECTED_TAG: ${{ steps.detect-tag.outputs.detected_tag }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
|
||||
# Try to use explicit input first
|
||||
requested_tag="$(printf '%s' "${INPUT_TAG}" | sed 's/^[[:space:]]\+//; s/[[:space:]]\+$//')"
|
||||
|
||||
# Fall back to detected tag if input is empty
|
||||
if [[ -z "$requested_tag" && -n "${DETECTED_TAG}" ]]; then
|
||||
requested_tag="$DETECTED_TAG"
|
||||
fi
|
||||
|
||||
# Try GITHUB_REF if still empty
|
||||
if [[ -z "$requested_tag" && "$GITHUB_REF" == refs/tags/* ]]; then
|
||||
requested_tag="${GITHUB_REF#refs/tags/}"
|
||||
fi
|
||||
|
||||
if [[ -n "$requested_tag" ]]; then
|
||||
# Explicit tag was provided via input or workflow_call
|
||||
# Normalize to v-prefixed format
|
||||
normalized="${requested_tag#v}"
|
||||
tag="v${normalized}"
|
||||
elif [[ "$GITHUB_REF" == refs/tags/* ]]; then
|
||||
# Running from a tag push
|
||||
tag="${GITHUB_REF#refs/tags/}"
|
||||
normalized="${tag#v}"
|
||||
else
|
||||
# Try to find tags at HEAD (fetch latest first in case called from prepare-release)
|
||||
git fetch origin --tags --quiet 2>/dev/null || true
|
||||
|
||||
if tag_at_head="$(git describe --exact-match --tags HEAD 2>/dev/null)" && [[ -n "$tag_at_head" ]]; then
|
||||
# Current HEAD is at a tag
|
||||
tag="$tag_at_head"
|
||||
normalized="${tag#v}"
|
||||
else
|
||||
echo "A release tag is required when the workflow is not running from a tag push" >&2
|
||||
echo "Provide a tag via the 'tag' input or ensure HEAD is at a tagged commit." >&2
|
||||
exit 1
|
||||
fi
|
||||
echo "Error: Could not resolve release version" >&2
|
||||
echo " - inputs.tag: '$INPUT_TAG'" >&2
|
||||
echo " - detected_tag: '${DETECTED_TAG}'" >&2
|
||||
echo " - GITHUB_REF: '$GITHUB_REF'" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "tag=${tag}" >> "$GITHUB_OUTPUT"
|
||||
|
||||
Reference in New Issue
Block a user