fix(release): add tag detection fallback for workflow_call input issues
This commit is contained in:
@@ -36,36 +36,52 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
|
|
||||||
- name: Resolve release version
|
- name: Fetch and detect release tag
|
||||||
id: resolve-version
|
id: detect-tag
|
||||||
env:
|
|
||||||
REQUESTED_TAG: ${{ inputs.tag }}
|
|
||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
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
|
if [[ -n "$requested_tag" ]]; then
|
||||||
# Explicit tag was provided via input or workflow_call
|
# Normalize to v-prefixed format
|
||||||
normalized="${requested_tag#v}"
|
normalized="${requested_tag#v}"
|
||||||
tag="v${normalized}"
|
tag="v${normalized}"
|
||||||
elif [[ "$GITHUB_REF" == refs/tags/* ]]; then
|
|
||||||
# Running from a tag push
|
|
||||||
tag="${GITHUB_REF#refs/tags/}"
|
|
||||||
normalized="${tag#v}"
|
|
||||||
else
|
else
|
||||||
# Try to find tags at HEAD (fetch latest first in case called from prepare-release)
|
echo "Error: Could not resolve release version" >&2
|
||||||
git fetch origin --tags --quiet 2>/dev/null || true
|
echo " - inputs.tag: '$INPUT_TAG'" >&2
|
||||||
|
echo " - detected_tag: '${DETECTED_TAG}'" >&2
|
||||||
if tag_at_head="$(git describe --exact-match --tags HEAD 2>/dev/null)" && [[ -n "$tag_at_head" ]]; then
|
echo " - GITHUB_REF: '$GITHUB_REF'" >&2
|
||||||
# Current HEAD is at a tag
|
exit 1
|
||||||
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
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "tag=${tag}" >> "$GITHUB_OUTPUT"
|
echo "tag=${tag}" >> "$GITHUB_OUTPUT"
|
||||||
|
|||||||
Reference in New Issue
Block a user