Skip to content

Commit 5ad2873

Browse files
Copilotpelikhan
andauthored
Record compiler ref in lock metadata for --action-tag compiles (#39687)
* Record compile ref for action-tag Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com> * Add CLI regression coverage for compiler version metadata Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com> Co-authored-by: Peli de Halleux <pelikhan@users.noreply.github.com>
1 parent d017ec3 commit 5ad2873

3 files changed

Lines changed: 76 additions & 0 deletions

File tree

pkg/cli/compile_integration_test.go

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2247,3 +2247,65 @@ func TestCompileWithActionsRepoDefaultFallback(t *testing.T) {
22472247

22482248
t.Logf("Default actions repo test passed - default repo baked into lock file: %s", lockFilePath)
22492249
}
2250+
2251+
func TestCompileWithActionRefOverrideIncludesCompilerVersionMetadata(t *testing.T) {
2252+
tests := []struct {
2253+
name string
2254+
args []string
2255+
}{
2256+
{
2257+
name: "action-tag",
2258+
args: []string{"--action-tag", "v9.9.9"},
2259+
},
2260+
{
2261+
name: "gh-aw-ref",
2262+
args: []string{"--gh-aw-ref", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"},
2263+
},
2264+
}
2265+
2266+
for _, tt := range tests {
2267+
t.Run(tt.name, func(t *testing.T) {
2268+
setup := setupIntegrationTest(t)
2269+
defer setup.cleanup()
2270+
2271+
srcPath := filepath.Join(projectRoot, "pkg/cli/workflows/test-actions-repo.md")
2272+
dstPath := filepath.Join(setup.workflowsDir, "test-actions-repo.md")
2273+
2274+
srcContent, err := os.ReadFile(srcPath)
2275+
if err != nil {
2276+
t.Fatalf("Failed to read source workflow file %s: %v", srcPath, err)
2277+
}
2278+
if err := os.WriteFile(dstPath, srcContent, 0o644); err != nil {
2279+
t.Fatalf("Failed to write workflow to test dir: %v", err)
2280+
}
2281+
2282+
cmdArgs := append([]string{"compile"}, tt.args...)
2283+
cmdArgs = append(cmdArgs, dstPath)
2284+
cmd := exec.Command(setup.binaryPath, cmdArgs...)
2285+
output, err := cmd.CombinedOutput()
2286+
if err != nil {
2287+
t.Fatalf("CLI compile command failed: %v\nOutput: %s", err, string(output))
2288+
}
2289+
2290+
lockFilePath := filepath.Join(setup.workflowsDir, "test-actions-repo.lock.yml")
2291+
lockContent, err := os.ReadFile(lockFilePath)
2292+
if err != nil {
2293+
t.Fatalf("Failed to read lock file: %v", err)
2294+
}
2295+
2296+
metadataLine := ""
2297+
for line := range strings.SplitSeq(string(lockContent), "\n") {
2298+
if strings.Contains(line, "gh-aw-metadata:") {
2299+
metadataLine = line
2300+
break
2301+
}
2302+
}
2303+
if metadataLine == "" {
2304+
t.Fatal("Could not find gh-aw-metadata in lock file")
2305+
}
2306+
if !strings.Contains(metadataLine, `"compiler_version":"`) || strings.Contains(metadataLine, `"compiler_version":""`) {
2307+
t.Fatalf("Expected non-empty compiler_version in metadata, got: %s", metadataLine)
2308+
}
2309+
})
2310+
}
2311+
}

pkg/workflow/compiler_yaml.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ func (c *Compiler) generateWorkflowHeader(yaml *strings.Builder, data *WorkflowD
109109
agentInfo.EngineVersions = collectEngineVersionsForMetadata(data)
110110
agentInfo.AgentImageRunner = resolveAgentImageRunnerIdentifier(data.RawFrontmatter)
111111
metadata := GenerateLockMetadata(LockHashInfo{FrontmatterHash: frontmatterHash, BodyHash: bodyHash}, data.StopTime, c.effectiveStrictMode(data.RawFrontmatter), agentInfo)
112+
if metadata.CompilerVersion == "" && c.GetActionTag() != "" {
113+
metadata.CompilerVersion = c.GetVersion()
114+
}
112115
metadataJSON, err := metadata.ToJSON()
113116
if err != nil {
114117
// Fallback to legacy format if JSON serialization fails

pkg/workflow/compiler_yaml_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1399,18 +1399,28 @@ func TestLockMetadataVersionInReleaseBuilds(t *testing.T) {
13991399
name string
14001400
isRelease bool
14011401
version string
1402+
actionTag string
14021403
expectVersion bool
14031404
}{
14041405
{
14051406
name: "dev build should not include version",
14061407
isRelease: false,
14071408
version: "dev",
1409+
actionTag: "",
14081410
expectVersion: false,
14091411
},
14101412
{
14111413
name: "release build should include version",
14121414
isRelease: true,
14131415
version: "v0.1.2",
1416+
actionTag: "",
1417+
expectVersion: true,
1418+
},
1419+
{
1420+
name: "action-tag compile should include current ref",
1421+
isRelease: false,
1422+
version: "401bd13",
1423+
actionTag: "v9.9.9",
14141424
expectVersion: true,
14151425
},
14161426
}
@@ -1437,6 +1447,7 @@ Test prompt.
14371447

14381448
// Compile the workflow
14391449
compiler := NewCompiler()
1450+
compiler.SetActionTag(tt.actionTag)
14401451
err := compiler.CompileWorkflow(workflowPath)
14411452
if err != nil {
14421453
t.Fatalf("Failed to compile workflow: %v", err)

0 commit comments

Comments
 (0)