Skip to content

fix: use PR head branch for rules-ref instead of merge ref#168

Merged
scottschreckengaust merged 1 commit intomainfrom
fix/pr-branch-detection-in-codebuild
Apr 2, 2026
Merged

fix: use PR head branch for rules-ref instead of merge ref#168
scottschreckengaust merged 1 commit intomainfrom
fix/pr-branch-detection-in-codebuild

Conversation

@Kalindi-Dev
Copy link
Copy Markdown
Contributor

Summary

Fix the CodeBuild evaluation pipeline failing on PR builds because --rules-ref receives 155/merge (a virtual GitHub merge ref) instead of the actual PR source branch name. The evaluator's setup_rules() tries to git clone --branch 155/merge which fails because that ref doesn't exist as a cloneable branch.

Changes

  • Pass github.head_ref into the CodeBuild buildspec as GH_HEAD_REF environment variable
  • Update the CURRENT_BRANCH fallback chain from ${GH_REF_NAME:-} to ${GH_HEAD_REF:-${GH_REF_NAME:-}} so PR builds use the actual source branch name
Event Before After
PR #155 from fix/some-feature 155/merge (fails to clone) fix/some-feature
Push to main main main (unchanged)
Tag v0.1.7 v0.1.7 v0.1.7 (unchanged)

User experience

Before: Every PR-triggered CodeBuild run fails at Stage 1 with RuntimeError: Failed to clone AIDLC rules repo: fatal: Remote branch 155/merge not found in upstream origin.

After: PR builds correctly resolve the source branch and clone the rules at the PR's head ref.

Checklist

  • I have reviewed the contributing guidelines
  • I have performed a self-review of this change
  • Changes have been tested
  • Changes are documented

Test Plan

  • Trigger a CodeBuild run from a PR and verify CURRENT_BRANCH resolves to the PR head branch (not N/merge)
  • Verify push-to-main builds still resolve CURRENT_BRANCH correctly
  • Verify tag builds still resolve CURRENT_BRANCH correctly

Acknowledgment

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of the project license.

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.
Copy link
Copy Markdown
Contributor

@harmjeff harmjeff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SSimple 1 line change

Copy link
Copy Markdown
Member

@scottschreckengaust scottschreckengaust left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@scottschreckengaust scottschreckengaust added this pull request to the merge queue Apr 2, 2026
Merged via the queue into main with commit c4dfc59 Apr 2, 2026
16 of 21 checks passed
@scottschreckengaust scottschreckengaust deleted the fix/pr-branch-detection-in-codebuild branch April 2, 2026 15:42
Kalindi-Dev added a commit that referenced this pull request Apr 2, 2026
Re-apply the GH_HEAD_REF fix from #168 which was overwritten when
#172 was merged. Without this, PR-triggered CodeBuild runs fail
because CURRENT_BRANCH resolves to '155/merge' instead of the
actual PR source branch.
github-merge-queue bot pushed a commit that referenced this pull request Apr 2, 2026
Re-apply the GH_HEAD_REF fix from #168 which was overwritten when
#172 was merged. Without this, PR-triggered CodeBuild runs fail
because CURRENT_BRANCH resolves to '155/merge' instead of the
actual PR source branch.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants