Skip to content

Commit c64ff74

Browse files
Copilotpelikhan
andcommitted
Set GH_AW_WORKFLOW_ID at job level in consolidated safe_outputs job
- Added job-level Env map with GH_AW_WORKFLOW_ID in buildConsolidatedSafeOutputsJob - Removed duplicate GH_AW_WORKFLOW_ID from create_pull_request step config (now inherited from job level) - Updated integration tests to check job.Env for GH_AW_WORKFLOW_ID in consolidated jobs - Tests now properly verify job-level env vars instead of looking for them in step content Co-authored-by: pelikhan <[email protected]>
1 parent 5982578 commit c64ff74

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

pkg/workflow/compiler_safe_outputs_consolidated.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -504,9 +504,12 @@ func (c *Compiler) buildConsolidatedSafeOutputsJob(data *WorkflowData, mainJobNa
504504
RunsOn: c.formatSafeOutputsRunsOn(data.SafeOutputs),
505505
Permissions: permissions.RenderToYAML(),
506506
TimeoutMinutes: 15, // Slightly longer timeout for consolidated job with multiple steps
507-
Steps: steps,
508-
Outputs: outputs,
509-
Needs: needs,
507+
Env: map[string]string{
508+
"GH_AW_WORKFLOW_ID": fmt.Sprintf("%q", mainJobName),
509+
},
510+
Steps: steps,
511+
Outputs: outputs,
512+
Needs: needs,
510513
}
511514

512515
consolidatedSafeOutputsLog.Printf("Built consolidated safe outputs job with %d steps", len(safeOutputStepNames))
@@ -638,9 +641,8 @@ func (c *Compiler) buildCreatePullRequestStepConfig(data *WorkflowData, mainJobN
638641
cfg := data.SafeOutputs.CreatePullRequests
639642

640643
var customEnvVars []string
641-
// Pass the workflow ID for branch naming (required by create_pull_request.cjs)
642-
customEnvVars = append(customEnvVars, fmt.Sprintf(" GH_AW_WORKFLOW_ID: %q\n", mainJobName))
643644
// Pass the base branch from GitHub context (required by create_pull_request.cjs)
645+
// Note: GH_AW_WORKFLOW_ID is now set at the job level and inherited by all steps
644646
customEnvVars = append(customEnvVars, " GH_AW_BASE_BRANCH: ${{ github.ref_name }}\n")
645647
customEnvVars = append(customEnvVars, buildTitlePrefixEnvVar("GH_AW_PR_TITLE_PREFIX", cfg.TitlePrefix)...)
646648
customEnvVars = append(customEnvVars, buildLabelsEnvVar("GH_AW_PR_LABELS", cfg.Labels)...)

pkg/workflow/safe_outputs_integration_test.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -592,8 +592,19 @@ func TestConsolidatedSafeOutputsJobIntegration(t *testing.T) {
592592
// Convert steps to string for verification
593593
stepsContent := strings.Join(job.Steps, "")
594594

595-
// Verify expected environment variables and step content
595+
// For consolidated job, GH_AW_WORKFLOW_ID should be at job level, not in steps
596+
// Check job.Env for this variable
597+
if job.Env == nil || job.Env["GH_AW_WORKFLOW_ID"] == "" {
598+
t.Errorf("GH_AW_WORKFLOW_ID should be set at job level in consolidated job for %s.\nJob.Env: %v",
599+
tt.name, job.Env)
600+
}
601+
602+
// Verify other expected environment variables and step content (excluding GH_AW_WORKFLOW_ID)
596603
for _, expectedContent := range tt.expectedStepsContaining {
604+
if expectedContent == "GH_AW_WORKFLOW_ID" {
605+
// Skip GH_AW_WORKFLOW_ID check in steps since it's now at job level
606+
continue
607+
}
597608
if !strings.Contains(stepsContent, expectedContent) {
598609
t.Errorf("Expected content %q not found in consolidated job for %s.\nJob steps:\n%s",
599610
expectedContent, tt.name, stepsContent)
@@ -855,10 +866,9 @@ func TestConsolidatedSafeOutputsJobWithCustomEnv(t *testing.T) {
855866
}
856867
}
857868

858-
// Verify GH_AW_WORKFLOW_ID is present
859-
// Known issue: GH_AW_WORKFLOW_ID may be missing from consolidated job for certain configurations
860-
if !strings.Contains(stepsContent, "GH_AW_WORKFLOW_ID") {
861-
t.Log("Known issue: GH_AW_WORKFLOW_ID not present in consolidated job - this should be fixed")
869+
// Verify GH_AW_WORKFLOW_ID is present at job level
870+
if job.Env == nil || job.Env["GH_AW_WORKFLOW_ID"] == "" {
871+
t.Error("GH_AW_WORKFLOW_ID should be set at job level in consolidated job")
862872
}
863873

864874
t.Logf("✓ Consolidated job with custom env vars built successfully with %d steps: %v", len(stepNames), stepNames)

0 commit comments

Comments
 (0)