Skip to content

Proactively ignore .dockerbuild artifacts in logs download#24386

Merged
pelikhan merged 1 commit intomainfrom
copilot/ignore-dockerbuild-files-in-logs
Apr 3, 2026
Merged

Proactively ignore .dockerbuild artifacts in logs download#24386
pelikhan merged 1 commit intomainfrom
copilot/ignore-dockerbuild-files-in-logs

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 3, 2026

gh run download aborts when it encounters .dockerbuild artifacts (not valid zip archives), potentially missing other valid artifacts downstream. The existing workaround only retried a hardcoded set of "critical" artifacts.

Approach

Instead of reacting to the error, proactively list all artifacts via the GitHub API before downloading, filter out .dockerbuild entries, and download the remainder individually.

Changes

  • listRunArtifactNames — queries repos/.../actions/runs/{id}/artifacts with --paginate to enumerate artifact names before any download begins
  • isDockerBuildArtifact — predicate: strings.HasSuffix(name, ".dockerbuild")
  • downloadArtifactsByName — downloads a filtered list of artifacts individually via gh run download --name <name>; failures are non-fatal per artifact
  • downloadRunArtifacts — now partitions artifact names into .dockerbuild vs downloadable before downloading:
    • If .dockerbuild artifacts found: warns and calls downloadArtifactsByName for the rest — bulk download is never attempted
    • If none found (or API listing fails): falls through to the existing bulk download path, preserving the non-zip error fallback as a safety net
    • Splits the "nothing downloaded" condition into two distinct cases: all-dockerbuild (no downloadable names exist) vs all-downloads-failed (empty output dir after attempts)

@pelikhan pelikhan marked this pull request as ready for review April 3, 2026 21:44
Copilot AI review requested due to automatic review settings April 3, 2026 21:44
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the workflow run artifact download flow to avoid .dockerbuild artifacts (non-zip) aborting gh run download, by pre-listing artifacts via the GitHub API and selectively downloading only valid artifacts.

Changes:

  • Add detection for .dockerbuild artifacts and pre-list artifact names via gh api.
  • When .dockerbuild artifacts are present, skip them and download remaining artifacts individually by name.
  • Add unit tests for the .dockerbuild artifact name predicate.
Show a summary per file
File Description
pkg/cli/logs_download.go Adds artifact pre-listing and conditional per-artifact downloads to bypass .dockerbuild extraction failures.
pkg/cli/logs_download_test.go Adds tests for .dockerbuild artifact name detection.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comments suppressed due to low confidence (1)

pkg/cli/logs_download.go:701

  • In the individual-download (.dockerbuild) branch, returning ErrNoArtifacts solely because the output directory is still empty can misclassify “all downloads failed” as “run has no artifacts”. Since ErrNoArtifacts is used by callers to skip/soft-handle runs, it would be safer to distinguish “no downloadable artifacts exist” from “downloads attempted but failed” (e.g., return a real error when at least one download attempt failed).
		if err := downloadArtifactsByName(runID, outputDir, downloadableNames, verbose, owner, repo, hostname); err != nil {
			return err
		}
		if fileutil.IsDirEmpty(outputDir) {
			// Downloads were attempted but none succeeded; treat as no artifacts.
			return ErrNoArtifacts
		}
  • Files reviewed: 2/2 changed files
  • Comments generated: 2

Comment on lines +548 to +556
cmd := workflow.ExecGH(args...)
cmdOutput, cmdErr := cmd.CombinedOutput()
if cmdErr != nil {
logsDownloadLog.Printf("Failed to download artifact %q: %v (%s)", name, cmdErr, string(cmdOutput))
if verbose {
fmt.Fprintln(os.Stderr, console.FormatWarningMessage(fmt.Sprintf("Failed to download artifact %q: %v", name, cmdErr)))
}
// Non-fatal: continue downloading other artifacts
} else {
Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

downloadArtifactsByName currently treats every per-artifact failure as non-fatal and always returns nil. In the .dockerbuild path, if all downloads fail, downloadRunArtifacts returns ErrNoArtifacts, which can incorrectly mask real failures (e.g., auth/permission issues, transient network errors) as “no artifacts” and cause callers to skip runs. Consider making authentication/permission failures fatal (consistent with the bulk path) and/or having downloadArtifactsByName return an aggregated error (or at least the last error) when nothing was successfully downloaded.

This issue also appears on line 695 of the same file.

Copilot uses AI. Check for mistakes.
Comment on lines +509 to +510
output, err := cmd.Output()
if err != nil {
Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

listRunArtifactNames uses cmd.Output(), so if gh api fails the returned error won’t include stderr/API error details. Elsewhere in this codebase API calls typically use workflow.RunGHCombined to capture stderr for diagnostics (e.g., pkg/cli/logs_github_api.go:37). Consider switching to CombinedOutput/RunGHCombined and including the output in the wrapped error so failures to pre-list artifacts are actionable when troubleshooting.

Suggested change
output, err := cmd.Output()
if err != nil {
output, err := cmd.CombinedOutput()
if err != nil {
trimmedOutput := strings.TrimSpace(string(output))
if trimmedOutput != "" {
return nil, fmt.Errorf("failed to list artifacts for run %d: %w: %s", runID, err, trimmedOutput)
}

Copilot uses AI. Check for mistakes.
@pelikhan pelikhan merged commit 50f9435 into main Apr 3, 2026
67 checks passed
@pelikhan pelikhan deleted the copilot/ignore-dockerbuild-files-in-logs branch April 3, 2026 21:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants