-
Notifications
You must be signed in to change notification settings - Fork 295
Fix custom safe-output job types not recognized in safe_outputs job
#20682
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,13 @@ | ||
| package workflow | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "fmt" | ||
| "sort" | ||
| "strings" | ||
|
|
||
| "github.com/github/gh-aw/pkg/logger" | ||
| "github.com/github/gh-aw/pkg/stringutil" | ||
| ) | ||
|
|
||
| var consolidatedSafeOutputsStepsLog = logger.New("workflow:compiler_safe_outputs_steps") | ||
|
|
@@ -331,6 +334,14 @@ func (c *Compiler) buildHandlerManagerStep(data *WorkflowData) []string { | |
| // Note: The project handler manager has been removed. | ||
| // All project-related operations are now handled by the unified handler. | ||
|
|
||
| // Add GH_AW_SAFE_OUTPUT_JOBS so the handler manager knows which message types are | ||
| // handled by custom safe-output job steps and should be silently skipped rather than | ||
| // reported as "No handler loaded for message type '...'". | ||
| if customJobsJSON := buildCustomSafeOutputJobsJSON(data); customJobsJSON != "" { | ||
| steps = append(steps, fmt.Sprintf(" GH_AW_SAFE_OUTPUT_JOBS: %q\n", customJobsJSON)) | ||
| consolidatedSafeOutputsStepsLog.Print("Added GH_AW_SAFE_OUTPUT_JOBS env var for custom safe job types") | ||
| } | ||
|
|
||
| // Add custom safe output env vars | ||
| c.addCustomSafeOutputEnvVars(&steps, data) | ||
|
|
||
|
|
@@ -433,3 +444,39 @@ func (c *Compiler) buildHandlerManagerStep(data *WorkflowData) []string { | |
|
|
||
| return steps | ||
| } | ||
|
|
||
| // buildCustomSafeOutputJobsJSON builds a JSON mapping of custom safe output job names to empty | ||
| // strings, for use in the GH_AW_SAFE_OUTPUT_JOBS env var of the handler manager step. | ||
| // This allows the handler manager to silently skip messages handled by custom safe-output job | ||
| // steps rather than reporting them as "No handler loaded for message type '...'". | ||
| func buildCustomSafeOutputJobsJSON(data *WorkflowData) string { | ||
| if data.SafeOutputs == nil || len(data.SafeOutputs.Jobs) == 0 { | ||
| return "" | ||
| } | ||
|
|
||
| // Build mapping of normalized job names to empty strings (no URL output for custom jobs) | ||
| jobMapping := make(map[string]string, len(data.SafeOutputs.Jobs)) | ||
| for jobName := range data.SafeOutputs.Jobs { | ||
| normalizedName := stringutil.NormalizeSafeOutputIdentifier(jobName) | ||
| jobMapping[normalizedName] = "" | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
|
|
||
| // Sort keys for deterministic output | ||
| keys := make([]string, 0, len(jobMapping)) | ||
| for k := range jobMapping { | ||
| keys = append(keys, k) | ||
| } | ||
| sort.Strings(keys) | ||
|
|
||
| ordered := make(map[string]string, len(keys)) | ||
| for _, k := range keys { | ||
| ordered[k] = jobMapping[k] | ||
| } | ||
|
Comment on lines
+464
to
+474
|
||
|
|
||
| jsonBytes, err := json.Marshal(ordered) | ||
| if err != nil { | ||
| consolidatedSafeOutputsStepsLog.Printf("Warning: failed to marshal custom safe output jobs: %v", err) | ||
| return "" | ||
| } | ||
| return string(jsonBytes) | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The log message says "Added GH_AW_SAFE_OUTPUT_JOBS env var for custom safe job types" but uses
consolidatedSafeOutputsStepsLog.Print(debug-level). Consider upgrading to a higher-visibility log or adding a comment explaining this is intentionally debug-only, since this is a new feature that was hard to diagnose when missing.