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

Function buildCustomScriptFilesStep

pkg/workflow/compiler_safe_outputs_job.go:915–947  ·  view source on GitHub ↗

buildCustomScriptFilesStep generates a run step that writes inline safe-output script files to the setup action destination folder so they can be required by the handler manager. Users write only the handler body; the compiler wraps it with config destructuring, the handler function, and module.expo

(scripts map[string]*SafeScriptConfig)

Source from the content-addressed store, hash-verified

913// the handler function, and module.exports boilerplate.
914// Each script is written using a heredoc to avoid shell quoting issues.
915func buildCustomScriptFilesStep(scripts map[string]*SafeScriptConfig) ([]string, error) {
916 if len(scripts) == 0 {
917 return nil, nil
918 }
919
920 // Sort script names for deterministic output
921 scriptNames := sliceutil.SortedKeys(scripts)
922
923 var steps []string
924 steps = append(steps, " - name: Configure Safe Outputs Custom Scripts\n")
925 steps = append(steps, " run: |\n")
926
927 for _, scriptName := range scriptNames {
928 scriptConfig := scripts[scriptName]
929 normalizedName := stringutil.NormalizeSafeOutputIdentifier(scriptName)
930 filename := safeOutputScriptFilename(normalizedName)
931 filePath := SetupActionDestinationShell + "/" + filename
932 scriptContent := generateSafeOutputScriptContent(scriptName, scriptConfig)
933 delimiter := GenerateHeredocDelimiterFromContent("SAFE_OUTPUT_SCRIPT_"+strings.ToUpper(normalizedName), scriptContent)
934
935 if err := ValidateHeredocContent(scriptContent, delimiter); err != nil {
936 return nil, fmt.Errorf("safe-output script %q: %w", scriptName, err)
937 }
938
939 steps = append(steps, fmt.Sprintf(" cat > \"%s\" << '%s'\n", filePath, delimiter))
940 for line := range strings.SplitSeq(scriptContent, "\n") {
941 steps = append(steps, " "+line+"\n")
942 }
943 steps = append(steps, " "+delimiter+"\n")
944 }
945
946 return steps, nil
947}

Calls 7

SortedKeysFunction · 0.92
safeOutputScriptFilenameFunction · 0.85
ValidateHeredocContentFunction · 0.85
ErrorfMethod · 0.45