getActionRef returns the action reference string based on action mode and version. If a resolver is provided and mode is release or action, attempts to resolve the SHA for a SHA-pinned reference. Falls back to a version tag reference if SHA resolution fails or resolver is nil.
(ctx context.Context, actionMode workflow.ActionMode, version string, resolver workflow.SHAResolver)
| 22 | // If a resolver is provided and mode is release or action, attempts to resolve the SHA for a SHA-pinned reference. |
| 23 | // Falls back to a version tag reference if SHA resolution fails or resolver is nil. |
| 24 | func getActionRef(ctx context.Context, actionMode workflow.ActionMode, version string, resolver workflow.SHAResolver) string { |
| 25 | if actionMode.IsRelease() && version != "" && version != "dev" { |
| 26 | if resolver != nil { |
| 27 | sha, err := resolver.ResolveSHA(ctx, "github/gh-aw-actions/setup-cli", version) |
| 28 | if err == nil && sha != "" { |
| 29 | return fmt.Sprintf("@%s # %s", sha, version) |
| 30 | } |
| 31 | copilotSetupLog.Printf("Failed to resolve SHA for setup-cli@%s: %v, falling back to version tag", version, err) |
| 32 | } |
| 33 | return "@" + version |
| 34 | } |
| 35 | if actionMode.IsAction() && version != "" && version != "dev" { |
| 36 | if resolver != nil { |
| 37 | sha, err := resolver.ResolveSHA(ctx, "github/gh-aw-actions/setup-cli", version) |
| 38 | if err == nil && sha != "" { |
| 39 | return fmt.Sprintf("@%s # %s", sha, version) |
| 40 | } |
| 41 | copilotSetupLog.Printf("Failed to resolve SHA for gh-aw-actions/setup-cli@%s: %v, falling back to version tag", version, err) |
| 42 | } |
| 43 | return "@" + version |
| 44 | } |
| 45 | return "@main" |
| 46 | } |
| 47 | |
| 48 | // generateCopilotSetupStepsYAML generates the copilot-setup-steps.yml content based on action mode |
| 49 | func generateCopilotSetupStepsYAML(ctx context.Context, actionMode workflow.ActionMode, version string, resolver workflow.SHAResolver) string { |