generateSetupStep creates a setup step for a given runtime requirement
(req *RuntimeRequirement, data *WorkflowData)
| 56 | |
| 57 | // generateSetupStep creates a setup step for a given runtime requirement |
| 58 | func generateSetupStep(req *RuntimeRequirement, data *WorkflowData) GitHubActionStep { |
| 59 | runtime := req.Runtime |
| 60 | version := req.Version |
| 61 | runtimeStepGeneratorLog.Printf("Generating setup step for runtime: %s, version=%s, if=%s", runtime.ID, version, req.IfCondition) |
| 62 | runtimeSetupLog.Printf("Generating setup step for runtime: %s, version=%s, if=%s", runtime.ID, version, req.IfCondition) |
| 63 | |
| 64 | if runtime.ID == "gh-aw" { |
| 65 | if version == "" { |
| 66 | version = getDefaultGhAWRuntimeVersion() |
| 67 | } |
| 68 | |
| 69 | allExtraFields := make(map[string]string) |
| 70 | // runtime.ExtraWithFields are already YAML-formatted by runtime definitions. |
| 71 | maps.Copy(allExtraFields, runtime.ExtraWithFields) |
| 72 | // req.ExtraFields come from user input and need YAML formatting. |
| 73 | for k, v := range req.ExtraFields { |
| 74 | allExtraFields[k] = formatYAMLValue(v) |
| 75 | } |
| 76 | |
| 77 | step, err := generateGhAwSetupStep(ghAwSetupStepConfig{ |
| 78 | actionMode: actionModeForRuntimeSetup(IsRelease()), |
| 79 | ifCondition: req.IfCondition, |
| 80 | cliVersion: version, |
| 81 | actionRepo: runtime.ActionRepo, |
| 82 | fallbackActionRefTag: version, |
| 83 | workflowData: data, |
| 84 | withFields: allExtraFields, |
| 85 | }) |
| 86 | if err != nil { |
| 87 | runtimeStepGeneratorLog.Printf("Failed to resolve pinned setup-cli action reference for %s@%s: %v", runtime.ActionRepo, version, err) |
| 88 | } |
| 89 | return step |
| 90 | } |
| 91 | |
| 92 | // Use default version if none specified. |
| 93 | if version == "" { |
| 94 | if runtime.ID == "gh-aw" { |
| 95 | version = getDefaultGhAWRuntimeVersion() |
| 96 | } else { |
| 97 | version = runtime.DefaultVersion |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | // Use SHA-pinned action reference for security if available |
| 102 | actionRef := getActionPin(runtime.ActionRepo) |
| 103 | |
| 104 | // If no pin exists (custom action repo), use the action repo with its version |
| 105 | if actionRef == "" { |
| 106 | if runtime.ActionVersion != "" { |
| 107 | actionRef = fmt.Sprintf("%s@%s", runtime.ActionRepo, runtime.ActionVersion) |
| 108 | } else { |
| 109 | // Fallback to just the repo name (shouldn't happen in practice) |
| 110 | actionRef = runtime.ActionRepo |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | step := GitHubActionStep{ |
| 115 | " - name: Setup " + runtime.Name, |
no test coverage detected