From f2872f0cc758d86a1b414cba7d198e376ee94905 Mon Sep 17 00:00:00 2001 From: Vault Automation Date: Tue, 9 Sep 2025 16:11:09 -0600 Subject: [PATCH] [VAULT-39158] actions(build-hcp-image): various small fixes (#9207) (#9230) * [VAULT-39158] actions(build-hcp-image): various small fixes Various small fixes to correctly trigger custom image builds and wait for them to be available. Signed-off-by: Ryan Cragun Co-authored-by: Ryan Cragun --- .../cmd/github_find_workflow_artifact.go | 2 +- .../internal/cmd/github_list_changed_files.go | 2 +- .../pipeline/internal/cmd/github_list_runs.go | 2 +- .../pipeline/internal/pkg/github/workflows.go | 45 +++++++++++-------- .../internal/pkg/hcp/wait_for_image.go | 3 ++ 5 files changed, 33 insertions(+), 21 deletions(-) diff --git a/tools/pipeline/internal/cmd/github_find_workflow_artifact.go b/tools/pipeline/internal/cmd/github_find_workflow_artifact.go index d9c2379982..250b24bf78 100644 --- a/tools/pipeline/internal/cmd/github_find_workflow_artifact.go +++ b/tools/pipeline/internal/cmd/github_find_workflow_artifact.go @@ -37,7 +37,7 @@ func runFindGithubWorkflowArtifactCmd(cmd *cobra.Command, args []string) error { res, err := findWorkflowArtifact.Run(context.TODO(), githubCmdState.Github) if err != nil { - return fmt.Errorf("listing github workflow failures: %w", err) + return fmt.Errorf("finding workflow artifact: %w", err) } switch rootCfg.format { diff --git a/tools/pipeline/internal/cmd/github_list_changed_files.go b/tools/pipeline/internal/cmd/github_list_changed_files.go index f9eec10de1..3d19b72a6b 100644 --- a/tools/pipeline/internal/cmd/github_list_changed_files.go +++ b/tools/pipeline/internal/cmd/github_list_changed_files.go @@ -36,7 +36,7 @@ func runListGithubChangedFilesCmd(cmd *cobra.Command, args []string) error { res, err := listGithubChangedFiles.Run(context.TODO(), githubCmdState.Github) if err != nil { - return fmt.Errorf("listing github workflow failures: %w", err) + return fmt.Errorf("listing changed files: %w", err) } switch rootCfg.format { diff --git a/tools/pipeline/internal/cmd/github_list_runs.go b/tools/pipeline/internal/cmd/github_list_runs.go index 4be5e86509..7f08747580 100644 --- a/tools/pipeline/internal/cmd/github_list_runs.go +++ b/tools/pipeline/internal/cmd/github_list_runs.go @@ -55,7 +55,7 @@ func runListGithubWorkflowsCmd(cmd *cobra.Command, args []string) error { res, err := listGithubWorkflowRuns.Run(context.TODO(), githubCmdState.Github) if err != nil { - return fmt.Errorf("listing github workflow failures: %w", err) + return fmt.Errorf("listing github workflow runs: %w", err) } switch rootCfg.format { diff --git a/tools/pipeline/internal/pkg/github/workflows.go b/tools/pipeline/internal/pkg/github/workflows.go index 72a4267656..e05b28d33c 100644 --- a/tools/pipeline/internal/pkg/github/workflows.go +++ b/tools/pipeline/internal/pkg/github/workflows.go @@ -56,31 +56,40 @@ func getWorkflowRuns( id int64, opts *gh.ListWorkflowRunsOptions, ) ([]*WorkflowRun, error) { - slog.Default().DebugContext(slogctx.Append(ctx, - slog.String("owner", owner), - slog.String("repo", repo), - slog.Int64("id", id), - ), "getting github actions workflow runs") - var runs []*WorkflowRun opts.ListOptions = gh.ListOptions{PerPage: PerPageMax} - for { - wfrs, res, err := client.Actions.ListWorkflowRunsByID(ctx, owner, repo, id, opts) - if err != nil { - return nil, err - } + // By default our status will be "success" which elimates in_progress runs. + // Instead, we'll try both so that we're sure to include what's actually + // running along with historical runs. + for _, status := range []string{"success", "in_progress"} { + for { + opts.Status = status + slog.Default().DebugContext(slogctx.Append(ctx, + slog.String("owner", owner), + slog.String("repo", repo), + slog.Int64("id", id), + slog.String("query-status", opts.Status), + ), "getting github actions workflow runs") - for _, r := range wfrs.WorkflowRuns { - runs = append(runs, &WorkflowRun{Run: r}) - } + wfrs, res, err := client.Actions.ListWorkflowRunsByID(ctx, owner, repo, id, opts) + if err != nil { + return nil, err + } - if res.NextPage == 0 { - return runs, nil - } + for _, r := range wfrs.WorkflowRuns { + runs = append(runs, &WorkflowRun{Run: r}) + } - opts.ListOptions.Page = res.NextPage + if res.NextPage == 0 { + break + } + + opts.ListOptions.Page = res.NextPage + } } + + return runs, nil } // getWorkflowRunArtifacts gets the artifacts associated with a workflow run diff --git a/tools/pipeline/internal/pkg/hcp/wait_for_image.go b/tools/pipeline/internal/pkg/hcp/wait_for_image.go index a9f4c20abf..2e75f0b541 100644 --- a/tools/pipeline/internal/pkg/hcp/wait_for_image.go +++ b/tools/pipeline/internal/pkg/hcp/wait_for_image.go @@ -65,8 +65,11 @@ func (r *WaitForImageReq) Run(ctx context.Context, client *Client) (*WaitForImag return err }, + retry.UntilSucceeded(), retry.Context(ctx), + retry.WrapContextErrorWithLastError(true), retry.Delay(r.Delay), + retry.DelayType(retry.FixedDelay), ) return res, err