From 146bd27df84bc4c9ff13a871a3184bfe780b575f Mon Sep 17 00:00:00 2001 From: Kalindi Vijesh Parekh Date: Thu, 2 Apr 2026 09:40:18 -0400 Subject: [PATCH] fix: use PR head branch for rules-ref instead of merge ref MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For pull_request events, CodeBuild runs in detached HEAD so git symbolic-ref fails. The fallback was GH_REF_NAME which resolves to '155/merge' — a virtual GitHub ref that cannot be cloned as a branch. Pass github.head_ref into the buildspec as GH_HEAD_REF and prefer it in the fallback chain so the evaluator clones the actual PR source branch. --- .github/workflows/codebuild.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/codebuild.yml b/.github/workflows/codebuild.yml index 5c15adeb..0509ead7 100644 --- a/.github/workflows/codebuild.yml +++ b/.github/workflows/codebuild.yml @@ -173,6 +173,7 @@ jobs: variables: GH_TOKEN: ${{ github.token }} GH_REF_NAME: ${{ github.ref_name }} + GH_HEAD_REF: ${{ github.head_ref }} GH_EVENT_NAME: ${{ github.event_name }} phases: install: @@ -190,7 +191,7 @@ jobs: build: commands: - DEFAULT_BRANCH=$(gh repo view --json defaultBranchRef --jq '.defaultBranchRef.name' 2>/dev/null || echo "main") - - CURRENT_BRANCH=$(git symbolic-ref --short HEAD 2>/dev/null || echo "${GH_REF_NAME:-}") + - CURRENT_BRANCH=$(git symbolic-ref --short HEAD 2>/dev/null || echo "${GH_HEAD_REF:-${GH_REF_NAME:-}}") - CURRENT_TAG=$(git describe --tags --exact-match 2>/dev/null || echo "") - IS_RELEASE=$([[ -n "$CURRENT_TAG" ]] && echo "true" || echo "false") - IS_PRE_RELEASE=$([[ "$CURRENT_BRANCH" == "$DEFAULT_BRANCH" ]] && echo "true" || echo "false")