From 1c557b87cb13c49ee386b6bc97f152e087dd0e1f Mon Sep 17 00:00:00 2001 From: Ashwin Bharambe Date: Fri, 31 Oct 2025 09:39:11 -0700 Subject: [PATCH] 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. --- scripts/uv-run-with-index.sh | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/scripts/uv-run-with-index.sh b/scripts/uv-run-with-index.sh index 00d6ac591..e6eb2c0f9 100755 --- a/scripts/uv-run-with-index.sh +++ b/scripts/uv-run-with-index.sh @@ -8,9 +8,19 @@ set -euo pipefail # Detect current branch and target branch -BRANCH=$(git rev-parse --abbrev-ref HEAD 2>/dev/null || echo "") -# For feature branches, check what branch they're merging into -TARGET_BRANCH=$(git rev-parse --abbrev-ref HEAD@{upstream} 2>/dev/null | sed 's|origin/||' || echo "") +# In GitHub Actions, use GITHUB_REF/GITHUB_BASE_REF +if [[ -n "${GITHUB_REF:-}" ]]; then + 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] Target branch: '$TARGET_BRANCH'" >&2