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

Function buildArtifactDownloadSteps

pkg/workflow/artifacts.go:26–79  ·  view source on GitHub ↗

buildArtifactDownloadSteps creates steps to download a GitHub Actions artifact. pinAction is used to resolve the download-artifact action reference; callers inside a Compiler method should pass c.getActionPin to honour the per-compilation GHES compat flag.

(config ArtifactDownloadConfig, pinAction func(string) string)

Source from the content-addressed store, hash-verified

24// pinAction is used to resolve the download-artifact action reference; callers inside
25// a Compiler method should pass c.getActionPin to honour the per-compilation GHES compat flag.
26func buildArtifactDownloadSteps(config ArtifactDownloadConfig, pinAction func(string) string) []string {
27 artifactsLog.Printf("Building artifact download steps: artifact=%s, path=%s, setupEnv=%v",
28 config.ArtifactName, config.DownloadPath, config.SetupEnvStep)
29
30 var steps []string
31
32 // Use provided step name or generate default
33 stepName := config.StepName
34 if stepName == "" {
35 stepName = fmt.Sprintf("Download %s artifact", config.ArtifactName)
36 artifactsLog.Printf("Using default step name: %s", stepName)
37 }
38
39 // Add step to download artifact
40 steps = append(steps, fmt.Sprintf(" - name: %s\n", stepName))
41 // Add step ID if specified (used to condition the env-setup step on download success)
42 if config.StepID != "" {
43 steps = append(steps, fmt.Sprintf(" id: %s\n", config.StepID))
44 artifactsLog.Printf("Added step ID: %s", config.StepID)
45 }
46 // Add conditional if specified
47 if config.IfCondition != "" {
48 steps = append(steps, fmt.Sprintf(" if: %s\n", config.IfCondition))
49 artifactsLog.Printf("Added conditional: %s", config.IfCondition)
50 }
51 steps = append(steps, " continue-on-error: true\n")
52 steps = append(steps, fmt.Sprintf(" uses: %s\n", pinAction("actions/download-artifact")))
53 steps = append(steps, " with:\n")
54 steps = append(steps, fmt.Sprintf(" name: %s\n", config.ArtifactName))
55 steps = append(steps, fmt.Sprintf(" path: %s\n", config.DownloadPath))
56
57 // Add environment variable setup if requested
58 if config.SetupEnvStep {
59 artifactsLog.Printf("Adding environment variable setup step: %s=%s%s",
60 config.EnvVarName, config.DownloadPath, config.ArtifactFilename)
61 steps = append(steps, " - name: Setup agent output environment variable\n")
62 steps = append(steps, " id: setup-agent-output-env\n")
63 // Only set the env var when the artifact was actually downloaded
64 if config.StepID != "" {
65 steps = append(steps, fmt.Sprintf(" if: steps.%s.outcome == 'success'\n", config.StepID))
66 artifactsLog.Printf("Added env-setup conditional on step outcome: %s", config.StepID)
67 }
68 steps = append(steps, " run: |\n")
69 steps = append(steps, fmt.Sprintf(" mkdir -p %s\n", config.DownloadPath))
70 steps = append(steps, fmt.Sprintf(" find \"%s\" -type f -print\n", config.DownloadPath))
71 // When downloading a single artifact by name with download-artifact@v4,
72 // artifacts are extracted directly to {download-path}, not {download-path}/{artifact-name}/
73 // The actual filename is specified in ArtifactFilename
74 artifactPath := fmt.Sprintf("%s%s", config.DownloadPath, config.ArtifactFilename)
75 steps = append(steps, fmt.Sprintf(" echo \"%s=%s\" >> \"$GITHUB_OUTPUT\"\n", config.EnvVarName, artifactPath))
76 }
77
78 return steps
79}

Calls 1

PrintfMethod · 0.45

Tested by

no test coverage detected