Skip to content

Resolve --gh-aw-ref branch/tag to commit SHA at compile time#38689

Open
dsyme wants to merge 2 commits into
mainfrom
resolve-gh-aw-ref-to-sha
Open

Resolve --gh-aw-ref branch/tag to commit SHA at compile time#38689
dsyme wants to merge 2 commits into
mainfrom
resolve-gh-aw-ref-to-sha

Conversation

@dsyme

@dsyme dsyme commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator

Summary

When gh aw compile --gh-aw-ref BRANCH|TAG is used, the compiler previously baked the mutable branch or tag name directly into the compiled .lock.yml files. This means the ref could silently drift if the branch moves or the tag is recreated.

This change resolves the supplied ref to its commit SHA at compile time, so the baked-in ref is immutable.

Changes

  • pkg/workflow/action_resolver.go — new ResolveGhAwRef(ctx, ref) function:

    • If ref is already a 40-char hex SHA, returns it unchanged (no network call)
    • Otherwise calls gh api /repos/github/gh-aw/commits/{ref} --jq .sha, which accepts branches and tag names
    • Returns a clear error if the API call fails or returns an unexpected value
  • cmd/gh-aw/main.go--gh-aw-ref handler calls ResolveGhAwRef before building CompileConfig, failing fast with a descriptive error if the ref can't be resolved. Updated flag description to document SHA resolution behaviour.

  • DEVGUIDE.md — updated the --gh-aw-ref section to document that branch/tag names are resolved to SHAs at compile time.

Before / After

# Before: bakes "main" (mutable) into .lock.yml
gh aw compile --gh-aw-ref main

# After: resolves "main" to its current commit SHA, bakes that in
gh aw compile --gh-aw-ref main
# → compiles as if --action-mode release --action-tag abc123def456...

Branch refresh requested by pr-sous-chef for run https://github.com/github/gh-aw/actions/runs/27381978065

Generated by 👨‍🍳 PR Sous Chef · 42.5 AIC · ⌖ 1.06 AIC · ⊞ 17.3K ·

Copilot AI review requested due to automatic review settings June 11, 2026 18:19

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This pull request makes gh aw compile --gh-aw-ref <BRANCH|TAG> resolve the provided ref to an immutable 40-character commit SHA at compile time, preventing compiled .lock.yml files from silently drifting as branches move or tags are recreated.

Changes:

  • Added workflow.ResolveGhAwRef(ctx, ref) to resolve branch/tag refs to full commit SHAs (skipping resolution when already given a full SHA).
  • Updated the compile command’s --gh-aw-ref handling to resolve early and fail fast on resolution errors.
  • Updated DEVGUIDE.md and CLI flag help text to document SHA-resolution behavior.
Show a summary per file
File Description
pkg/workflow/action_resolver.go Adds ResolveGhAwRef to resolve github/gh-aw refs to full SHAs via gh api.
cmd/gh-aw/main.go Uses ResolveGhAwRef when --gh-aw-ref is provided; updates help text accordingly.
DEVGUIDE.md Documents that branch/tag refs are resolved to SHAs at compile time for immutability.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 3/3 changed files
  • Comments generated: 3

Comment on lines +165 to +167
resolverLog.Printf("Resolving --gh-aw-ref %q to commit SHA via GitHub API", ref)
apiPath := fmt.Sprintf("/repos/github/gh-aw/commits/%s", ref)
callCtx, cancel := context.WithTimeout(ctx, 30*time.Second)
Comment on lines +169 to +173
cmd := ExecGHContext(callCtx, "api", apiPath, "--jq", ".sha")
output, err := cmd.Output()
if err != nil {
return "", fmt.Errorf("failed to resolve gh-aw ref %q to SHA: %w", ref, err)
}
Comment on lines +160 to +164
func ResolveGhAwRef(ctx context.Context, ref string) (string, error) {
if gitutil.IsValidFullSHA(ref) {
resolverLog.Printf("--gh-aw-ref %q is already a full SHA, no resolution needed", ref)
return ref, nil
}
@github-actions

Copy link
Copy Markdown
Contributor

✅ smoke-ci: safeoutputs CLI comment + comment-memory run (27368233860)

Generated by 🧪 Smoke CI for issue #38689 ·

@github-actions

Copy link
Copy Markdown
Contributor

Comment Memory

CI lights the path
Green checks bloom at dawn
Quiet bots still sing

Note

This comment is managed by comment memory.

It stores persistent context for this thread in the code block at the top of this comment.
Edit only the text inside the backtick fences; workflow metadata and the footer are regenerated automatically.

Learn more about comment memory

Generated by 🧪 Smoke CI for issue #38689 ·

@github-actions

Copy link
Copy Markdown
Contributor

@copilot review all comments and address unresolved review feedback. Please refresh the branch and rerun checks once that is done.

Generated by 👨‍🍳 PR Sous Chef · 65.7 AIC · ⌖ 1.82 AIC · ⊞ 17.3K ·

@github-actions

Copy link
Copy Markdown
Contributor

@copilot review all comments and address unresolved review feedback.

Generated by 👨‍🍳 PR Sous Chef · 42.5 AIC · ⌖ 1.06 AIC · ⊞ 17.3K ·

@github-actions

Copy link
Copy Markdown
Contributor

Please rerun checks after the branch refresh and summarize any remaining blockers.

Generated by 👨‍🍳 PR Sous Chef · 42.5 AIC · ⌖ 1.06 AIC · ⊞ 17.3K ·

@github-actions

Copy link
Copy Markdown
Contributor

``
@copilot review all comments and address unresolved review feedback.

Generated by 👨‍🍳 PR Sous Chef · 28.5 AIC · ⌖ 1.01 AIC · ⊞ 17.3K ·

@github-actions

Copy link
Copy Markdown
Contributor

``
Please refresh the branch, re-run checks, and summarize any remaining blockers.

Generated by 👨‍🍳 PR Sous Chef · 28.5 AIC · ⌖ 1.01 AIC · ⊞ 17.3K ·

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants