Skip to content

Commit c4dfc59

Browse files
authored
fix: use PR head branch for rules-ref instead of merge ref (#168)
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.
1 parent 2e7c277 commit c4dfc59

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

.github/workflows/codebuild.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ jobs:
173173
variables:
174174
GH_TOKEN: ${{ github.token }}
175175
GH_REF_NAME: ${{ github.ref_name }}
176+
GH_HEAD_REF: ${{ github.head_ref }}
176177
GH_EVENT_NAME: ${{ github.event_name }}
177178
phases:
178179
install:
@@ -190,7 +191,7 @@ jobs:
190191
build:
191192
commands:
192193
- DEFAULT_BRANCH=$(gh repo view --json defaultBranchRef --jq '.defaultBranchRef.name' 2>/dev/null || echo "main")
193-
- CURRENT_BRANCH=$(git symbolic-ref --short HEAD 2>/dev/null || echo "${GH_REF_NAME:-}")
194+
- CURRENT_BRANCH=$(git symbolic-ref --short HEAD 2>/dev/null || echo "${GH_HEAD_REF:-${GH_REF_NAME:-}}")
194195
- CURRENT_TAG=$(git describe --tags --exact-match 2>/dev/null || echo "")
195196
- IS_RELEASE=$([[ -n "$CURRENT_TAG" ]] && echo "true" || echo "false")
196197
- IS_PRE_RELEASE=$([[ "$CURRENT_BRANCH" == "$DEFAULT_BRANCH" ]] && echo "true" || echo "false")

0 commit comments

Comments
 (0)