From 9e1e5c0d890653318e4ba6cca6d1082cbf41f362 Mon Sep 17 00:00:00 2001 From: Randell Callahan Date: Wed, 12 Oct 2022 10:44:42 -0600 Subject: [PATCH 1/5] Upload mount files to database when running locally --- cmd/src/batch_common.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/cmd/src/batch_common.go b/cmd/src/batch_common.go index 8bfee5a05e..5e9c68f6e9 100644 --- a/cmd/src/batch_common.go +++ b/cmd/src/batch_common.go @@ -481,6 +481,21 @@ 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 { + return err + } + ui.UploadingWorkspaceFilesSuccess() + } + if !opts.applyBatchSpec { ui.PreviewBatchSpec(previewURL) return From 86e19cfe1d605d00915c7f37a0b3833dc3747951 Mon Sep 17 00:00:00 2001 From: Randell Callahan Date: Wed, 12 Oct 2022 10:44:57 -0600 Subject: [PATCH 2/5] Add interface functions for uploading workspace files --- internal/batches/ui/exec_ui.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/internal/batches/ui/exec_ui.go b/internal/batches/ui/exec_ui.go index ecedfcfcac..29218d08ea 100644 --- a/internal/batches/ui/exec_ui.go +++ b/internal/batches/ui/exec_ui.go @@ -48,4 +48,7 @@ type ExecUI interface { ApplyingBatchSpecSuccess(batchChangeURL string) ExecutionError(error) + + UploadingWorkspaceFiles() + UploadingWorkspaceFilesSuccess() } From efc02acd38e8dcf591152838132ef39646ccc6c6 Mon Sep 17 00:00:00 2001 From: Randell Callahan Date: Wed, 12 Oct 2022 10:45:18 -0600 Subject: [PATCH 3/5] Implement empty functions for JSON TUI for workspace files upload --- internal/batches/ui/json_lines.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/internal/batches/ui/json_lines.go b/internal/batches/ui/json_lines.go index 54795ec6ba..be67ab94de 100644 --- a/internal/batches/ui/json_lines.go +++ b/internal/batches/ui/json_lines.go @@ -335,6 +335,14 @@ 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) 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}) } From b2ad03b078ec9c299a0fa4ac9383b9e35e5f087e Mon Sep 17 00:00:00 2001 From: Randell Callahan Date: Tue, 18 Oct 2022 10:06:58 -0600 Subject: [PATCH 4/5] Log a warning an error occurs when uploading workspace files --- cmd/src/batch_common.go | 6 ++++-- internal/batches/ui/exec_ui.go | 1 + internal/batches/ui/json_lines.go | 4 ++++ internal/batches/ui/tui.go | 10 ++++++++++ 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/cmd/src/batch_common.go b/cmd/src/batch_common.go index 5e9c68f6e9..c828401a5b 100644 --- a/cmd/src/batch_common.go +++ b/cmd/src/batch_common.go @@ -491,9 +491,11 @@ func executeBatchSpec(ctx context.Context, ui ui.ExecUI, opts executeBatchSpecOp if hasWorkspaceFiles { ui.UploadingWorkspaceFiles() if err = svc.UploadBatchSpecWorkspaceFiles(ctx, batchSpecDir, string(id), batchSpec.Steps); err != nil { - return err + // Since failing to upload workspace files should not stop processing, just warn + ui.UploadingWorkspaceFilesWarning(errors.Wrap(err, "uploading workspace files")) + } else { + ui.UploadingWorkspaceFilesSuccess() } - ui.UploadingWorkspaceFilesSuccess() } if !opts.applyBatchSpec { diff --git a/internal/batches/ui/exec_ui.go b/internal/batches/ui/exec_ui.go index 29218d08ea..e6e8bdeeec 100644 --- a/internal/batches/ui/exec_ui.go +++ b/internal/batches/ui/exec_ui.go @@ -50,5 +50,6 @@ type ExecUI interface { ExecutionError(error) UploadingWorkspaceFiles() + UploadingWorkspaceFilesWarning(error) UploadingWorkspaceFilesSuccess() } diff --git a/internal/batches/ui/json_lines.go b/internal/batches/ui/json_lines.go index be67ab94de..f584a25a51 100644 --- a/internal/batches/ui/json_lines.go +++ b/internal/batches/ui/json_lines.go @@ -339,6 +339,10 @@ 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. } 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)) +} From 53360698c8df2aa5cdd535b3f2158a0bc9b312af Mon Sep 17 00:00:00 2001 From: Randell Callahan Date: Tue, 18 Oct 2022 10:09:40 -0600 Subject: [PATCH 5/5] Update changelog for uploading mounted files when running locally for batches --- CHANGELOG.md | 2 ++ 1 file changed, 2 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