MCPcopy Create free account
hub / github.com/github/gh-aw / generateSafeOutputsSetup

Function generateSafeOutputsSetup

pkg/workflow/mcp_setup_generator.go:260–329  ·  view source on GitHub ↗
(c *Compiler, yaml *strings.Builder, safeOutputConfig string, workflowData *WorkflowData)

Source from the content-addressed store, hash-verified

258}
259
260func generateSafeOutputsSetup(c *Compiler, yaml *strings.Builder, safeOutputConfig string, workflowData *WorkflowData) {
261 if !HasSafeOutputsEnabled(workflowData.SafeOutputs) {
262 return
263 }
264 yaml.WriteString(" - name: Generate Safe Outputs Config\n")
265 sanitizedConfig, envKeys, envValues := buildSafeOutputsConfigRuntimeData(safeOutputConfig)
266 if len(envKeys) > 0 {
267 yaml.WriteString(" env:\n")
268 writeStepEnvVars(yaml, envKeys, envValues)
269 }
270 yaml.WriteString(" run: |\n")
271 yaml.WriteString(" mkdir -p \"${RUNNER_TEMP}/gh-aw/safeoutputs\"\n")
272 yaml.WriteString(" mkdir -p /tmp/gh-aw/safeoutputs\n")
273 yaml.WriteString(" mkdir -p /tmp/gh-aw/mcp-logs/safeoutputs\n")
274 if workflowData.SafeOutputs != nil && workflowData.SafeOutputs.UploadArtifact != nil {
275 yaml.WriteString(" mkdir -p \"${RUNNER_TEMP}/gh-aw/safeoutputs/upload-artifacts\"\n")
276 }
277 if workflowData.SafeOutputs != nil && workflowData.SafeOutputs.UploadAssets != nil {
278 yaml.WriteString(" mkdir -p \"${RUNNER_TEMP}/gh-aw/safeoutputs/assets\"\n")
279 }
280
281 delimiter := GenerateHeredocDelimiterFromContent("SAFE_OUTPUTS_CONFIG", sanitizedConfig)
282 if safeOutputConfig != "" {
283 yaml.WriteString(" cat > \"${RUNNER_TEMP}/gh-aw/safeoutputs/config.json\" << '" + delimiter + "'\n")
284 yaml.WriteString(" " + sanitizedConfig + "\n")
285 yaml.WriteString(" " + delimiter + "\n")
286 }
287
288 toolsMetaJSON, err := generateToolsMetaJSON(workflowData, c.markdownPath)
289 if err != nil {
290 mcpSetupGeneratorLog.Printf("Error generating tools meta JSON: %v", err)
291 toolsMetaJSON = `{"description_suffixes":{},"repo_params":{},"dynamic_tools":[]}`
292 }
293
294 var enabledTypes []string
295 if safeOutputConfig != "" {
296 var configMap map[string]any
297 if err := json.Unmarshal([]byte(safeOutputConfig), &configMap); err == nil {
298 for typeName := range configMap {
299 enabledTypes = append(enabledTypes, typeName)
300 }
301 }
302 }
303 // Propagate mentions config to the collection pass so that allowed @-mentions
304 // (e.g. "@copilot") are not backtick-escaped before publish-side handlers run.
305 var mentionsBlock map[string]any
306 if workflowData.SafeOutputs != nil && workflowData.SafeOutputs.Mentions != nil {
307 mentionsBlock = buildMentionsHandlerConfig(workflowData.SafeOutputs.Mentions)
308 }
309 validationConfigJSON, err := GetValidationConfigJSON(enabledTypes, mentionsBlock)
310 if err != nil {
311 mcpSetupGeneratorLog.Printf("CRITICAL: Error generating validation config JSON: %v - validation will not work correctly", err)
312 validationConfigJSON = "{}"
313 }
314
315 yaml.WriteString(" - name: Generate Safe Outputs Tools\n")
316 yaml.WriteString(" env:\n")
317 yaml.WriteString(" GH_AW_TOOLS_META_JSON: |\n")

Callers 1

generateMCPSetupMethod · 0.85

Calls 10

HasSafeOutputsEnabledFunction · 0.85
writeStepEnvVarsFunction · 0.85
generateToolsMetaJSONFunction · 0.85
GetValidationConfigJSONFunction · 0.85
getCachedActionPinFunction · 0.85
PrintfMethod · 0.45

Tested by

no test coverage detected