@@ -498,18 +498,22 @@ func (c *Compiler) buildConsolidatedSafeOutputsJob(data *WorkflowData, mainJobNa
498498 needs = append (needs , constants .ActivationJobName )
499499 }
500500
501+ // Extract workflow filename (without extension) for GH_AW_WORKFLOW_ID
502+ workflowFilename := strings .TrimSuffix (filepath .Base (markdownPath ), ".md" )
503+
504+ // Build job-level environment variables that are common to all safe output steps
505+ jobEnv := c .buildJobLevelSafeOutputEnvVars (data , workflowFilename )
506+
501507 job := & Job {
502508 Name : "safe_outputs" ,
503509 If : jobCondition .Render (),
504510 RunsOn : c .formatSafeOutputsRunsOn (data .SafeOutputs ),
505511 Permissions : permissions .RenderToYAML (),
506512 TimeoutMinutes : 15 , // Slightly longer timeout for consolidated job with multiple steps
507- Env : map [string ]string {
508- "GH_AW_WORKFLOW_ID" : fmt .Sprintf ("%q" , mainJobName ),
509- },
510- Steps : steps ,
511- Outputs : outputs ,
512- Needs : needs ,
513+ Env : jobEnv ,
514+ Steps : steps ,
515+ Outputs : outputs ,
516+ Needs : needs ,
513517 }
514518
515519 consolidatedSafeOutputsLog .Printf ("Built consolidated safe outputs job with %d steps" , len (safeOutputStepNames ))
@@ -581,6 +585,67 @@ func (c *Compiler) buildConsolidatedSafeOutputStep(data *WorkflowData, config Sa
581585 return steps
582586}
583587
588+ // buildJobLevelSafeOutputEnvVars builds environment variables that should be set at the job level
589+ // for the consolidated safe_outputs job. These are variables that are common to all safe output steps.
590+ func (c * Compiler ) buildJobLevelSafeOutputEnvVars (data * WorkflowData , workflowFilename string ) map [string ]string {
591+ envVars := make (map [string ]string )
592+
593+ // Set GH_AW_WORKFLOW_ID to the workflow filename (without extension)
594+ // This is used for branch naming in create_pull_request and other operations
595+ envVars ["GH_AW_WORKFLOW_ID" ] = fmt .Sprintf ("%q" , workflowFilename )
596+
597+ // Add workflow metadata that's common to all steps
598+ envVars ["GH_AW_WORKFLOW_NAME" ] = fmt .Sprintf ("%q" , data .Name )
599+
600+ if data .Source != "" {
601+ envVars ["GH_AW_WORKFLOW_SOURCE" ] = fmt .Sprintf ("%q" , data .Source )
602+ sourceURL := buildSourceURL (data .Source )
603+ if sourceURL != "" {
604+ envVars ["GH_AW_WORKFLOW_SOURCE_URL" ] = fmt .Sprintf ("%q" , sourceURL )
605+ }
606+ }
607+
608+ if data .TrackerID != "" {
609+ envVars ["GH_AW_TRACKER_ID" ] = fmt .Sprintf ("%q" , data .TrackerID )
610+ }
611+
612+ // Add engine metadata that's common to all steps
613+ if data .EngineConfig != nil {
614+ if data .EngineConfig .ID != "" {
615+ envVars ["GH_AW_ENGINE_ID" ] = fmt .Sprintf ("%q" , data .EngineConfig .ID )
616+ }
617+ if data .EngineConfig .Version != "" {
618+ envVars ["GH_AW_ENGINE_VERSION" ] = fmt .Sprintf ("%q" , data .EngineConfig .Version )
619+ }
620+ if data .EngineConfig .Model != "" {
621+ envVars ["GH_AW_ENGINE_MODEL" ] = fmt .Sprintf ("%q" , data .EngineConfig .Model )
622+ }
623+ }
624+
625+ // Add safe output job environment variables (staged/target repo)
626+ if c .trialMode || data .SafeOutputs .Staged {
627+ envVars ["GH_AW_SAFE_OUTPUTS_STAGED" ] = "\" true\" "
628+ }
629+
630+ // Set GH_AW_TARGET_REPO_SLUG - prefer trial target repo (applies to all steps)
631+ // Note: Individual steps with target-repo config will override this in their step-level env
632+ if c .trialMode && c .trialLogicalRepoSlug != "" {
633+ envVars ["GH_AW_TARGET_REPO_SLUG" ] = fmt .Sprintf ("%q" , c .trialLogicalRepoSlug )
634+ }
635+
636+ // Add messages config if present (applies to all steps)
637+ if data .SafeOutputs .Messages != nil {
638+ messagesJSON , err := serializeMessagesConfig (data .SafeOutputs .Messages )
639+ if err != nil {
640+ consolidatedSafeOutputsLog .Printf ("Warning: failed to serialize messages config: %v" , err )
641+ } else if messagesJSON != "" {
642+ envVars ["GH_AW_SAFE_OUTPUT_MESSAGES" ] = fmt .Sprintf ("%q" , messagesJSON )
643+ }
644+ }
645+
646+ return envVars
647+ }
648+
584649// buildDetectionSuccessCondition builds the condition to check if detection passed
585650func buildDetectionSuccessCondition () ConditionNode {
586651 return BuildEquals (
@@ -603,7 +668,7 @@ func (c *Compiler) buildCreateIssueStepConfig(data *WorkflowData, mainJobName st
603668 if cfg .Expires > 0 {
604669 customEnvVars = append (customEnvVars , fmt .Sprintf (" GH_AW_ISSUE_EXPIRES: \" %d\" \n " , cfg .Expires ))
605670 }
606- customEnvVars = append (customEnvVars , c .buildStandardSafeOutputEnvVars (data , cfg .TargetRepoSlug )... )
671+ customEnvVars = append (customEnvVars , c .buildStepLevelSafeOutputEnvVars (data , cfg .TargetRepoSlug )... )
607672
608673 condition := BuildSafeOutputType ("create_issue" )
609674
@@ -622,7 +687,7 @@ func (c *Compiler) buildCreateDiscussionStepConfig(data *WorkflowData, mainJobNa
622687 cfg := data .SafeOutputs .CreateDiscussions
623688
624689 var customEnvVars []string
625- customEnvVars = append (customEnvVars , c .buildStandardSafeOutputEnvVars (data , "" )... )
690+ customEnvVars = append (customEnvVars , c .buildStepLevelSafeOutputEnvVars (data , "" )... )
626691
627692 condition := BuildSafeOutputType ("create_discussion" )
628693
@@ -676,7 +741,7 @@ func (c *Compiler) buildCreatePullRequestStepConfig(data *WorkflowData, mainJobN
676741 if cfg .Expires > 0 && cfg .TargetRepoSlug == "" {
677742 customEnvVars = append (customEnvVars , fmt .Sprintf (" GH_AW_PR_EXPIRES: \" %d\" \n " , cfg .Expires ))
678743 }
679- customEnvVars = append (customEnvVars , c .buildStandardSafeOutputEnvVars (data , cfg .TargetRepoSlug )... )
744+ customEnvVars = append (customEnvVars , c .buildStepLevelSafeOutputEnvVars (data , cfg .TargetRepoSlug )... )
680745
681746 condition := BuildSafeOutputType ("create_pull_request" )
682747
@@ -723,7 +788,7 @@ func (c *Compiler) buildAddCommentStepConfig(data *WorkflowData, mainJobName str
723788 customEnvVars = append (customEnvVars , " GH_AW_CREATED_PULL_REQUEST_URL: ${{ steps.create_pull_request.outputs.pull_request_url }}\n " )
724789 customEnvVars = append (customEnvVars , " GH_AW_CREATED_PULL_REQUEST_NUMBER: ${{ steps.create_pull_request.outputs.pull_request_number }}\n " )
725790 }
726- customEnvVars = append (customEnvVars , c .buildStandardSafeOutputEnvVars (data , cfg .TargetRepoSlug )... )
791+ customEnvVars = append (customEnvVars , c .buildStepLevelSafeOutputEnvVars (data , cfg .TargetRepoSlug )... )
727792
728793 condition := BuildSafeOutputType ("add_comment" )
729794
@@ -742,7 +807,7 @@ func (c *Compiler) buildCloseDiscussionStepConfig(data *WorkflowData, mainJobNam
742807 cfg := data .SafeOutputs .CloseDiscussions
743808
744809 var customEnvVars []string
745- customEnvVars = append (customEnvVars , c .buildStandardSafeOutputEnvVars (data , "" )... )
810+ customEnvVars = append (customEnvVars , c .buildStepLevelSafeOutputEnvVars (data , "" )... )
746811
747812 condition := BuildSafeOutputType ("close_discussion" )
748813
@@ -761,7 +826,7 @@ func (c *Compiler) buildCloseIssueStepConfig(data *WorkflowData, mainJobName str
761826 cfg := data .SafeOutputs .CloseIssues
762827
763828 var customEnvVars []string
764- customEnvVars = append (customEnvVars , c .buildStandardSafeOutputEnvVars (data , "" )... )
829+ customEnvVars = append (customEnvVars , c .buildStepLevelSafeOutputEnvVars (data , "" )... )
765830
766831 condition := BuildSafeOutputType ("close_issue" )
767832
@@ -780,7 +845,7 @@ func (c *Compiler) buildClosePullRequestStepConfig(data *WorkflowData, mainJobNa
780845 cfg := data .SafeOutputs .ClosePullRequests
781846
782847 var customEnvVars []string
783- customEnvVars = append (customEnvVars , c .buildStandardSafeOutputEnvVars (data , "" )... )
848+ customEnvVars = append (customEnvVars , c .buildStepLevelSafeOutputEnvVars (data , "" )... )
784849
785850 condition := BuildSafeOutputType ("close_pull_request" )
786851
@@ -807,7 +872,7 @@ func (c *Compiler) buildCreatePRReviewCommentStepConfig(data *WorkflowData, main
807872 if cfg .Target != "" {
808873 customEnvVars = append (customEnvVars , fmt .Sprintf (" GH_AW_PR_REVIEW_COMMENT_TARGET: %q\n " , cfg .Target ))
809874 }
810- customEnvVars = append (customEnvVars , c .buildStandardSafeOutputEnvVars (data , "" )... )
875+ customEnvVars = append (customEnvVars , c .buildStepLevelSafeOutputEnvVars (data , "" )... )
811876
812877 condition := BuildSafeOutputType ("create_pull_request_review_comment" )
813878
@@ -827,7 +892,7 @@ func (c *Compiler) buildCreateCodeScanningAlertStepConfig(data *WorkflowData, ma
827892
828893 var customEnvVars []string
829894 customEnvVars = append (customEnvVars , fmt .Sprintf (" GH_AW_WORKFLOW_FILENAME: %q\n " , workflowFilename ))
830- customEnvVars = append (customEnvVars , c .buildStandardSafeOutputEnvVars (data , "" )... )
895+ customEnvVars = append (customEnvVars , c .buildStepLevelSafeOutputEnvVars (data , "" )... )
831896
832897 condition := BuildSafeOutputType ("create_code_scanning_alert" )
833898
@@ -853,7 +918,7 @@ func (c *Compiler) buildAddLabelsStepConfig(data *WorkflowData, mainJobName stri
853918 if cfg .Target != "" {
854919 customEnvVars = append (customEnvVars , fmt .Sprintf (" GH_AW_LABELS_TARGET: %q\n " , cfg .Target ))
855920 }
856- customEnvVars = append (customEnvVars , c .buildStandardSafeOutputEnvVars (data , cfg .TargetRepoSlug )... )
921+ customEnvVars = append (customEnvVars , c .buildStepLevelSafeOutputEnvVars (data , cfg .TargetRepoSlug )... )
857922
858923 condition := BuildSafeOutputType ("add_labels" )
859924
@@ -872,7 +937,7 @@ func (c *Compiler) buildAddReviewerStepConfig(data *WorkflowData, mainJobName st
872937 cfg := data .SafeOutputs .AddReviewer
873938
874939 var customEnvVars []string
875- customEnvVars = append (customEnvVars , c .buildStandardSafeOutputEnvVars (data , "" )... )
940+ customEnvVars = append (customEnvVars , c .buildStepLevelSafeOutputEnvVars (data , "" )... )
876941
877942 condition := BuildSafeOutputType ("add_reviewer" )
878943
@@ -891,7 +956,7 @@ func (c *Compiler) buildAssignMilestoneStepConfig(data *WorkflowData, mainJobNam
891956 cfg := data .SafeOutputs .AssignMilestone
892957
893958 var customEnvVars []string
894- customEnvVars = append (customEnvVars , c .buildStandardSafeOutputEnvVars (data , "" )... )
959+ customEnvVars = append (customEnvVars , c .buildStepLevelSafeOutputEnvVars (data , "" )... )
895960
896961 condition := BuildSafeOutputType ("assign_milestone" )
897962
@@ -910,7 +975,7 @@ func (c *Compiler) buildAssignToAgentStepConfig(data *WorkflowData, mainJobName
910975 cfg := data .SafeOutputs .AssignToAgent
911976
912977 var customEnvVars []string
913- customEnvVars = append (customEnvVars , c .buildStandardSafeOutputEnvVars (data , "" )... )
978+ customEnvVars = append (customEnvVars , c .buildStepLevelSafeOutputEnvVars (data , "" )... )
914979
915980 condition := BuildSafeOutputType ("assign_to_agent" )
916981
@@ -930,7 +995,7 @@ func (c *Compiler) buildAssignToUserStepConfig(data *WorkflowData, mainJobName s
930995 cfg := data .SafeOutputs .AssignToUser
931996
932997 var customEnvVars []string
933- customEnvVars = append (customEnvVars , c .buildStandardSafeOutputEnvVars (data , "" )... )
998+ customEnvVars = append (customEnvVars , c .buildStepLevelSafeOutputEnvVars (data , "" )... )
934999
9351000 condition := BuildSafeOutputType ("assign_to_user" )
9361001
@@ -949,7 +1014,7 @@ func (c *Compiler) buildUpdateIssueStepConfig(data *WorkflowData, mainJobName st
9491014 cfg := data .SafeOutputs .UpdateIssues
9501015
9511016 var customEnvVars []string
952- customEnvVars = append (customEnvVars , c .buildStandardSafeOutputEnvVars (data , cfg .TargetRepoSlug )... )
1017+ customEnvVars = append (customEnvVars , c .buildStepLevelSafeOutputEnvVars (data , cfg .TargetRepoSlug )... )
9531018
9541019 condition := BuildSafeOutputType ("update_issue" )
9551020
@@ -968,7 +1033,7 @@ func (c *Compiler) buildUpdatePullRequestStepConfig(data *WorkflowData, mainJobN
9681033 cfg := data .SafeOutputs .UpdatePullRequests
9691034
9701035 var customEnvVars []string
971- customEnvVars = append (customEnvVars , c .buildStandardSafeOutputEnvVars (data , cfg .TargetRepoSlug )... )
1036+ customEnvVars = append (customEnvVars , c .buildStepLevelSafeOutputEnvVars (data , cfg .TargetRepoSlug )... )
9721037
9731038 condition := BuildSafeOutputType ("update_pull_request" )
9741039
@@ -987,7 +1052,7 @@ func (c *Compiler) buildUpdateDiscussionStepConfig(data *WorkflowData, mainJobNa
9871052 cfg := data .SafeOutputs .UpdateDiscussions
9881053
9891054 var customEnvVars []string
990- customEnvVars = append (customEnvVars , c .buildStandardSafeOutputEnvVars (data , cfg .TargetRepoSlug )... )
1055+ customEnvVars = append (customEnvVars , c .buildStepLevelSafeOutputEnvVars (data , cfg .TargetRepoSlug )... )
9911056
9921057 // Add target environment variable if set
9931058 if cfg .Target != "" {
@@ -1044,7 +1109,7 @@ func (c *Compiler) buildPushToPullRequestBranchStepConfig(data *WorkflowData, ma
10441109 maxPatchSize = data .SafeOutputs .MaximumPatchSize
10451110 }
10461111 customEnvVars = append (customEnvVars , fmt .Sprintf (" GH_AW_MAX_PATCH_SIZE: %d\n " , maxPatchSize ))
1047- customEnvVars = append (customEnvVars , c .buildStandardSafeOutputEnvVars (data , "" )... )
1112+ customEnvVars = append (customEnvVars , c .buildStepLevelSafeOutputEnvVars (data , "" )... )
10481113
10491114 condition := BuildSafeOutputType ("push_to_pull_request_branch" )
10501115
@@ -1067,7 +1132,7 @@ func (c *Compiler) buildUploadAssetsStepConfig(data *WorkflowData, mainJobName s
10671132 cfg := data .SafeOutputs .UploadAssets
10681133
10691134 var customEnvVars []string
1070- customEnvVars = append (customEnvVars , c .buildStandardSafeOutputEnvVars (data , "" )... )
1135+ customEnvVars = append (customEnvVars , c .buildStepLevelSafeOutputEnvVars (data , "" )... )
10711136
10721137 condition := BuildSafeOutputType ("upload_asset" )
10731138
@@ -1086,7 +1151,7 @@ func (c *Compiler) buildUpdateReleaseStepConfig(data *WorkflowData, mainJobName
10861151 cfg := data .SafeOutputs .UpdateRelease
10871152
10881153 var customEnvVars []string
1089- customEnvVars = append (customEnvVars , c .buildStandardSafeOutputEnvVars (data , "" )... )
1154+ customEnvVars = append (customEnvVars , c .buildStepLevelSafeOutputEnvVars (data , "" )... )
10901155
10911156 condition := BuildSafeOutputType ("update_release" )
10921157
@@ -1109,7 +1174,7 @@ func (c *Compiler) buildLinkSubIssueStepConfig(data *WorkflowData, mainJobName s
11091174 customEnvVars = append (customEnvVars , " GH_AW_CREATED_ISSUE_NUMBER: ${{ steps.create_issue.outputs.issue_number }}\n " )
11101175 customEnvVars = append (customEnvVars , " GH_AW_TEMPORARY_ID_MAP: ${{ steps.create_issue.outputs.temporary_id_map }}\n " )
11111176 }
1112- customEnvVars = append (customEnvVars , c .buildStandardSafeOutputEnvVars (data , "" )... )
1177+ customEnvVars = append (customEnvVars , c .buildStepLevelSafeOutputEnvVars (data , "" )... )
11131178
11141179 condition := BuildSafeOutputType ("link_sub_issue" )
11151180
@@ -1128,7 +1193,7 @@ func (c *Compiler) buildHideCommentStepConfig(data *WorkflowData, mainJobName st
11281193 cfg := data .SafeOutputs .HideComment
11291194
11301195 var customEnvVars []string
1131- customEnvVars = append (customEnvVars , c .buildStandardSafeOutputEnvVars (data , "" )... )
1196+ customEnvVars = append (customEnvVars , c .buildStepLevelSafeOutputEnvVars (data , "" )... )
11321197
11331198 condition := BuildSafeOutputType ("hide_comment" )
11341199
@@ -1147,7 +1212,7 @@ func (c *Compiler) buildCreateAgentTaskStepConfig(data *WorkflowData, mainJobNam
11471212 cfg := data .SafeOutputs .CreateAgentTasks
11481213
11491214 var customEnvVars []string
1150- customEnvVars = append (customEnvVars , c .buildStandardSafeOutputEnvVars (data , "" )... )
1215+ customEnvVars = append (customEnvVars , c .buildStepLevelSafeOutputEnvVars (data , "" )... )
11511216
11521217 condition := BuildSafeOutputType ("create_agent_task" )
11531218
@@ -1166,7 +1231,7 @@ func (c *Compiler) buildUpdateProjectStepConfig(data *WorkflowData, mainJobName
11661231 cfg := data .SafeOutputs .UpdateProjects
11671232
11681233 var customEnvVars []string
1169- customEnvVars = append (customEnvVars , c .buildStandardSafeOutputEnvVars (data , "" )... )
1234+ customEnvVars = append (customEnvVars , c .buildStepLevelSafeOutputEnvVars (data , "" )... )
11701235
11711236 condition := BuildSafeOutputType ("update_project" )
11721237
0 commit comments