Skip to content

Commit

Permalink
batches: Workspace file upload for local runs (#861)
Browse files Browse the repository at this point in the history
  • Loading branch information
Piszmog authored Nov 7, 2022
1 parent 7063f48 commit bc24016
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions cmd/src/batch_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions internal/batches/ui/exec_ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,8 @@ type ExecUI interface {
ApplyingBatchSpecSuccess(batchChangeURL string)

ExecutionError(error)

UploadingWorkspaceFiles()
UploadingWorkspaceFilesWarning(error)
UploadingWorkspaceFilesSuccess()
}
12 changes: 12 additions & 0 deletions internal/batches/ui/json_lines.go
Original file line number Diff line number Diff line change
Expand Up @@ -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})
}
Expand Down
10 changes: 10 additions & 0 deletions internal/batches/ui/tui.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ var (
batchPendingColor = output.StylePending
batchSuccessColor = output.StyleSuccess
batchSuccessEmoji = output.EmojiSuccess
batchWarningColor = output.StyleWarning
batchWarningEmoji = output.EmojiWarning
)

var _ ExecUI = &TUI{}
Expand Down Expand Up @@ -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")
}
Expand Down Expand Up @@ -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))
}

0 comments on commit bc24016

Please sign in to comment.