From bc240160ec2d5860191543fe0623480937c231d7 Mon Sep 17 00:00:00 2001 From: Randell Callahan Date: Mon, 7 Nov 2022 08:38:47 -0700 Subject: [PATCH] batches: Workspace file upload for local runs (#861) --- CHANGELOG.md | 2 ++ cmd/src/batch_common.go | 17 +++++++++++++++++ internal/batches/ui/exec_ui.go | 4 ++++ internal/batches/ui/json_lines.go | 12 ++++++++++++ internal/batches/ui/tui.go | 10 ++++++++++ 5 files changed, 45 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a3f8a3cc14..d40ca1db83 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,8 @@ All notable changes to `src-cli` are documented in this file. ### Added +- Mounted file are now uploaded to the Sourcegraph instance when running `src batch preview` and `src batch apply`. [#861](https://github.com/sourcegraph/src-cli/pull/861) + ### Changed ### Fixed diff --git a/cmd/src/batch_common.go b/cmd/src/batch_common.go index 8bfee5a05e..c828401a5b 100644 --- a/cmd/src/batch_common.go +++ b/cmd/src/batch_common.go @@ -481,6 +481,23 @@ func executeBatchSpec(ctx context.Context, ui ui.ExecUI, opts executeBatchSpecOp previewURL := cfg.Endpoint + url ui.CreatingBatchSpecSuccess(previewURL) + hasWorkspaceFiles := false + for _, step := range batchSpec.Steps { + if len(step.Mount) > 0 { + hasWorkspaceFiles = true + break + } + } + if hasWorkspaceFiles { + ui.UploadingWorkspaceFiles() + if err = svc.UploadBatchSpecWorkspaceFiles(ctx, batchSpecDir, string(id), batchSpec.Steps); err != nil { + // Since failing to upload workspace files should not stop processing, just warn + ui.UploadingWorkspaceFilesWarning(errors.Wrap(err, "uploading workspace files")) + } else { + ui.UploadingWorkspaceFilesSuccess() + } + } + if !opts.applyBatchSpec { ui.PreviewBatchSpec(previewURL) return diff --git a/internal/batches/ui/exec_ui.go b/internal/batches/ui/exec_ui.go index ecedfcfcac..e6e8bdeeec 100644 --- a/internal/batches/ui/exec_ui.go +++ b/internal/batches/ui/exec_ui.go @@ -48,4 +48,8 @@ type ExecUI interface { ApplyingBatchSpecSuccess(batchChangeURL string) ExecutionError(error) + + UploadingWorkspaceFiles() + UploadingWorkspaceFilesWarning(error) + UploadingWorkspaceFilesSuccess() } diff --git a/internal/batches/ui/json_lines.go b/internal/batches/ui/json_lines.go index 54795ec6ba..f584a25a51 100644 --- a/internal/batches/ui/json_lines.go +++ b/internal/batches/ui/json_lines.go @@ -335,6 +335,18 @@ func (ui *stepsExecutionJSONLines) StepFailed(step int, err error, exitCode int) ) } +func (ui *JSONLines) UploadingWorkspaceFiles() { + // No workspace file upload required for executor mode. +} + +func (ui *JSONLines) UploadingWorkspaceFilesWarning(err error) { + // No workspace file upload required for executor mode. +} + +func (ui *JSONLines) UploadingWorkspaceFilesSuccess() { + // No workspace file upload required for executor mode. +} + func logOperationStart(op batcheslib.LogEventOperation, metadata interface{}) { logEvent(batcheslib.LogEvent{Operation: op, Status: batcheslib.LogEventStatusStarted, Metadata: metadata}) } diff --git a/internal/batches/ui/tui.go b/internal/batches/ui/tui.go index f5a8bade25..3d4ad1b21d 100644 --- a/internal/batches/ui/tui.go +++ b/internal/batches/ui/tui.go @@ -23,6 +23,8 @@ var ( batchPendingColor = output.StylePending batchSuccessColor = output.StyleSuccess batchSuccessEmoji = output.EmojiSuccess + batchWarningColor = output.StyleWarning + batchWarningEmoji = output.EmojiWarning ) var _ ExecUI = &TUI{} @@ -263,6 +265,10 @@ func (ui *TUI) UploadingWorkspaceFiles() { ui.pending = batchCreatePending(ui.Out, "Uploading workspace files") } +func (ui *TUI) UploadingWorkspaceFilesWarning(err error) { + batchCompleteWarning(ui.pending, err.Error()) +} + func (ui *TUI) UploadingWorkspaceFilesSuccess() { batchCompletePending(ui.pending, "Uploading workspace files") } @@ -439,3 +445,7 @@ func batchCreatePending(out *output.Output, message string) output.Pending { func batchCompletePending(p output.Pending, message string) { p.Complete(output.Line(batchSuccessEmoji, batchSuccessColor, message)) } + +func batchCompleteWarning(p output.Pending, message string) { + p.Complete(output.Line(batchWarningEmoji, batchWarningColor, message)) +}