fix: detect branch from GitHub Actions env vars in wrapper

In CI, git is in detached HEAD state, so git rev-parse returns 'HEAD'.
Use GITHUB_REF and GITHUB_BASE_REF to properly detect release branches
in GitHub Actions workflows.

This ensures pre-commit hooks in CI can correctly identify when running
against release branches and set the appropriate UV index URLs.
This commit is contained in:
Ashwin Bharambe 2025-10-31 09:39:11 -07:00
parent 451f1e5fd2
commit 1c557b87cb

View file

@ -8,9 +8,19 @@
set -euo pipefail set -euo pipefail
# Detect current branch and target branch # Detect current branch and target branch
BRANCH=$(git rev-parse --abbrev-ref HEAD 2>/dev/null || echo "") # In GitHub Actions, use GITHUB_REF/GITHUB_BASE_REF
# For feature branches, check what branch they're merging into if [[ -n "${GITHUB_REF:-}" ]]; then
TARGET_BRANCH=$(git rev-parse --abbrev-ref HEAD@{upstream} 2>/dev/null | sed 's|origin/||' || echo "") BRANCH="${GITHUB_REF#refs/heads/}"
else
BRANCH=$(git rev-parse --abbrev-ref HEAD 2>/dev/null || echo "")
fi
# For PRs, check the target branch
if [[ -n "${GITHUB_BASE_REF:-}" ]]; then
TARGET_BRANCH="${GITHUB_BASE_REF}"
else
TARGET_BRANCH=$(git rev-parse --abbrev-ref HEAD@{upstream} 2>/dev/null | sed 's|origin/||' || echo "")
fi
echo "[uv-run-with-index] Current branch: '$BRANCH'" >&2 echo "[uv-run-with-index] Current branch: '$BRANCH'" >&2
echo "[uv-run-with-index] Target branch: '$TARGET_BRANCH'" >&2 echo "[uv-run-with-index] Target branch: '$TARGET_BRANCH'" >&2