Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
573cc58
Upload mounted files
Piszmog Aug 9, 2022
2a326ce
Temporarily point to local sourcegraph code
Piszmog Aug 9, 2022
3a214d9
Add mount upload progress
Piszmog Aug 9, 2022
9f63867
Specify the directory where the files are located
Piszmog Aug 9, 2022
1a1b4f3
Remove unneeded tests
Piszmog Aug 9, 2022
5d8f987
Do not update the path of the mount
Piszmog Aug 9, 2022
d402823
Allow mount files to be ran in executor
Piszmog Aug 9, 2022
1794e7f
Add functions to upload files
Piszmog Aug 9, 2022
9d2554d
Save the directory of the batch spec
Piszmog Aug 9, 2022
bb9f6f4
Use mount directory for caching
Piszmog Aug 9, 2022
e836e7a
Specify the mount directory
Piszmog Aug 9, 2022
0552186
Remove unused parameter
Piszmog Aug 9, 2022
ded8b16
Remove unused parameter
Piszmog Aug 9, 2022
5596cf8
Use the batch spec directory for caching
Piszmog Aug 9, 2022
dc21e08
Get the mount directory
Piszmog Aug 9, 2022
e2411fc
Merge remote-tracking branch 'origin/main' into rc/remote-mounting
Piszmog Aug 10, 2022
b56d8d1
Set the mount directory
Piszmog Aug 11, 2022
bd2e771
Be able to upload multiple files
Piszmog Aug 11, 2022
7326479
Add test for uploading files
Piszmog Aug 15, 2022
f6bc5ed
Add mock implementation for api client
Piszmog Aug 15, 2022
ff1b30d
Run go mod tidy
Piszmog Aug 15, 2022
7803bea
Fixes based on unit tests
Piszmog Aug 15, 2022
cab0852
Remove TODO
Piszmog Aug 15, 2022
c8b8608
Remove special logic for caching mounts
Piszmog Aug 15, 2022
948809b
Pass the file mod time
Piszmog Aug 15, 2022
dcc6607
Update caching to support local and remote
Piszmog Aug 15, 2022
90c9892
Remove mount directory
Piszmog Aug 15, 2022
fb1903d
Rename from batchSpecDir to workingDirectory to fit with remote and l…
Piszmog Aug 18, 2022
af61c2d
Update dependencies
Piszmog Aug 18, 2022
69119aa
Fix issue with mix pointer and receiver functions
Piszmog Aug 18, 2022
d2f6fcb
Add doc
Piszmog Aug 18, 2022
81d8e0c
Remove unused property
Piszmog Aug 18, 2022
b952437
Merge remote-tracking branch 'origin/main' into rc/remote-mounting
Piszmog Aug 18, 2022
aec025b
Update changelog
Piszmog Aug 18, 2022
63dfdf0
Update dependency
Piszmog Sep 7, 2022
371d0d6
Merge remote-tracking branch 'origin/main' into rc/remote-mounting
Piszmog Sep 7, 2022
b1c89e0
Update dependencies
Piszmog Sep 7, 2022
090a434
Merge remote-tracking branch 'origin/main' into rc/remote-mounting
Piszmog Sep 21, 2022
ba39dc9
Rename mount to workspaceFiles
Piszmog Sep 21, 2022
8db3a00
Merge main
Piszmog Sep 21, 2022
84311e3
Merge main
Piszmog Sep 21, 2022
40b4f15
Rename mount to workspaceFiles
Piszmog Sep 21, 2022
825a30b
Update tests for file upload
Piszmog Sep 21, 2022
00ab6aa
Rename mount to workspace files
Piszmog Sep 21, 2022
547f31c
Rename mount to workspace files
Piszmog Sep 21, 2022
671d5a8
Update tests
Piszmog Sep 21, 2022
eac16c9
Fix tests
Piszmog Sep 21, 2022
3729313
Remove unused service
Piszmog Sep 21, 2022
25db814
Remove unused service
Piszmog Sep 21, 2022
56ffa64
Remove unused service
Piszmog Sep 21, 2022
e87525a
Update to write files in chunks
Piszmog Sep 22, 2022
4632368
Update tests
Piszmog Sep 22, 2022
ca9824e
Handle uploading a directory
Piszmog Sep 22, 2022
7e9c4d6
Update tests to be more regardless
Piszmog Sep 22, 2022
5904767
Pass the working directory when running the steps
Piszmog Sep 22, 2022
9661574
Fix verbage in changelog
Piszmog Sep 22, 2022
e0710fe
Remove redundant call
Piszmog Sep 22, 2022
108b89d
Handle errors in goroutine and limit size of files
Piszmog Sep 22, 2022
ae89519
Add test for file limit
Piszmog Sep 22, 2022
9bc77b6
Remove SG flags
Piszmog Sep 26, 2022
9d21a2c
Pass context down from caller
Piszmog Sep 26, 2022
4f83e69
Rename UploadBatchSpecWorkspaceFile to UploadBatchSpecWorkspaceFiles
Piszmog Sep 26, 2022
f9d593f
Deduplicate files
Piszmog Sep 26, 2022
a7a96c9
Return the directory of the batch spec when parsing
Piszmog Sep 26, 2022
5e46aba
Rename parameter to workingDir from dir
Piszmog Sep 26, 2022
0aff90f
Rename attribute to be consistent
Piszmog Sep 26, 2022
d5b1864
Accept status code 2xx and 3xx
Piszmog Sep 26, 2022
c47787a
Sort status code
Piszmog Sep 26, 2022
84c9041
Only log when there are workspace files to upload
Piszmog Sep 26, 2022
50fc20b
Get the relative path between working directory and actual path to file
Piszmog Sep 27, 2022
098b052
Update sourcegraph lib dependency
Piszmog Sep 27, 2022
b5e6e84
Replace windows separators with Unix
Piszmog Sep 27, 2022
7b523fb
Manually create temp directory for windows tests
Piszmog Sep 27, 2022
2c68b77
Add specific test for windows
Piszmog Sep 27, 2022
762ee65
Log when a field does not match to help narrow down mismatches
Piszmog Sep 27, 2022
187270f
Properly clone the request body
Piszmog Sep 27, 2022
a3de5db
Use io instead of ioutils
Piszmog Sep 27, 2022
1ca9f3f
Fix test and add a sub directory
Piszmog Sep 27, 2022
2dc0428
Fix test
Piszmog Sep 27, 2022
bfd31da
Merge remote-tracking branch 'origin/main' into rc/remote-mounting
Piszmog Sep 30, 2022
5eca33e
Merge remote-tracking branch 'origin/main' into rc/remote-mounting
Piszmog Oct 4, 2022
c71416b
Update to latest sourcegraph/lib dependency
Piszmog Oct 4, 2022
2c67603
Remove the api flags
Piszmog Oct 4, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion 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

- Mounting files now works when running batch changes server side. [sourcegraph/src-cli#816](https://github.com/sourcegraph/src-cli/pull/816)

### Changed

### Fixed
Expand Down Expand Up @@ -857,4 +859,4 @@ Re-release of 3.29.3 for Sourcegraph 3.30.
### Changed

- The terminal UI has been replaced by the logger-based UI that was previously only visible in verbose-mode (`-v`). [#228](https://github.com/sourcegraph/src-cli/pull/228)
- Deprecated the `-endpoint` flag. Instead, use the `SRC_ENDPOINT` environment variable. [#235](https://github.com/sourcegraph/src-cli/pull/235)
- Deprecated the `-endpoint` flag. Instead, use the `SRC_ENDPOINT` environment variable. [#235](https://github.com/sourcegraph/src-cli/pull/235)
33 changes: 19 additions & 14 deletions cmd/src/batch_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ func executeBatchSpec(ctx context.Context, ui ui.ExecUI, opts executeBatchSpecOp

// Parse flags and build up our service and executor options.
ui.ParsingBatchSpec()
batchSpec, rawSpec, err := parseBatchSpec(ctx, opts.file, svc, false)
batchSpec, batchSpecDir, rawSpec, err := parseBatchSpec(ctx, opts.file, svc)
if err != nil {
var multiErr errors.MultiError
if errors.As(err, &multiErr) {
Expand Down Expand Up @@ -378,15 +378,14 @@ func executeBatchSpec(ctx context.Context, ui ui.ExecUI, opts executeBatchSpecOp
Creator: workspaceCreator,
EnsureImage: imageCache.Ensure,
Parallelism: parallelism,
WorkingDirectory: batchSpecDir,
Timeout: opts.flags.timeout,
TempDir: opts.flags.tempDir,
GlobalEnv: os.Environ(),
IsRemote: false,
},
Logger: logManager,
Cache: executor.NewDiskCache(opts.flags.cacheDir),
GlobalEnv: os.Environ(),
IsRemote: false,
},
)

Expand Down Expand Up @@ -508,13 +507,10 @@ func setReadDeadlineOnCancel(ctx context.Context, f *os.File) {

// parseBatchSpec parses and validates the given batch spec. If the spec has
// validation errors, they are returned.
//
// isRemote argument is a temporary argument used to determine if the batch spec is being parsed for remote
// (server-side) processing. Remote processing does not support mounts yet.
func parseBatchSpec(ctx context.Context, file string, svc *service.Service, isRemote bool) (*batcheslib.BatchSpec, string, error) {
func parseBatchSpec(ctx context.Context, file string, svc *service.Service) (*batcheslib.BatchSpec, string, string, error) {
f, err := batchOpenFileFlag(file)
if err != nil {
return nil, "", err
return nil, "", "", err
}
defer f.Close()

Expand All @@ -526,26 +522,35 @@ func parseBatchSpec(ctx context.Context, file string, svc *service.Service, isRe

data, err := io.ReadAll(f)
if err != nil {
return nil, "", errors.Wrap(err, "reading batch spec")
return nil, "", "", errors.Wrap(err, "reading batch spec")
}

dir, err := getBatchSpecDirectory(file)
if err != nil {
return nil, "", "", errors.Wrap(err, "batch spec path")
}

spec, err := svc.ParseBatchSpec(dir, data)
return spec, dir, string(data), err
}

func getBatchSpecDirectory(file string) (string, error) {
var workingDirectory string
var err error
// if the batch spec is being provided via standard input, set the working directory to the current directory
if file == "" || file == "-" {
workingDirectory, err = os.Getwd()
if err != nil {
return nil, "", errors.Wrap(err, "batch spec path")
return "", errors.Wrap(err, "batch spec path")
}
} else {
p, err := filepath.Abs(file)
if err != nil {
return nil, "", errors.Wrap(err, "batch spec path")
return "", errors.Wrap(err, "batch spec path")
}
workingDirectory = filepath.Dir(p)
}

spec, err := svc.ParseBatchSpec(workingDirectory, data, isRemote)
return spec, string(data), err
return workingDirectory, nil
}

func checkExecutable(cmd string, args ...string) error {
Expand Down
45 changes: 26 additions & 19 deletions cmd/src/batch_exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,17 @@ import (
"path/filepath"
"time"

"github.com/sourcegraph/src-cli/internal/batches/docker"
"github.com/sourcegraph/src-cli/internal/batches/log"
"github.com/sourcegraph/src-cli/internal/batches/repozip"
"github.com/sourcegraph/src-cli/internal/batches/workspace"

"github.com/sourcegraph/sourcegraph/lib/errors"

"github.com/sourcegraph/src-cli/internal/batches/docker"
"github.com/sourcegraph/src-cli/internal/batches/executor"
"github.com/sourcegraph/src-cli/internal/batches/graphql"
"github.com/sourcegraph/src-cli/internal/batches/log"
"github.com/sourcegraph/src-cli/internal/batches/repozip"
"github.com/sourcegraph/src-cli/internal/batches/service"
"github.com/sourcegraph/src-cli/internal/batches/ui"
"github.com/sourcegraph/src-cli/internal/batches/workspace"
"github.com/sourcegraph/src-cli/internal/cmderrors"

batcheslib "github.com/sourcegraph/sourcegraph/lib/batches"
Expand All @@ -30,10 +31,11 @@ const (
)

type executorModeFlags struct {
timeout time.Duration
file string
tempDir string
repoDir string
timeout time.Duration
file string
tempDir string
repoDir string
workspaceFilesDir string
}

func newExecutorModeFlags(flagSet *flag.FlagSet) (f *executorModeFlags) {
Expand All @@ -42,6 +44,7 @@ func newExecutorModeFlags(flagSet *flag.FlagSet) (f *executorModeFlags) {
flagSet.StringVar(&f.file, "f", "", "The workspace execution input file to read.")
flagSet.StringVar(&f.tempDir, "tmp", "", "Directory for storing temporary data.")
flagSet.StringVar(&f.repoDir, "repo", "", "Path of the checked out repo on disk.")
flagSet.StringVar(&f.workspaceFilesDir, "workspaceFiles", "", "Path of workspace files on disk.")

return f
}
Expand Down Expand Up @@ -69,7 +72,7 @@ github.com/sourcegraph/sourcegraph/lib/batches.

Usage:

src batch exec -f FILE -repo DIR [command options]
src batch exec -f FILE -repo DIR -workspaceFiles DIR [command options]

Examples:

Expand Down Expand Up @@ -140,6 +143,12 @@ func executeBatchSpecInWorkspaces(ctx context.Context, flags *executorModeFlags)
}
}

// Grab the absolute path to the workspace files contents.
workspaceFilesDir, err := filepath.Abs(flags.workspaceFilesDir)
if err != nil {
return errors.Wrap(err, "getting absolute path for workspace files dir")
}

// Test if git is available.
if err := checkExecutable("git", "version"); err != nil {
return err
Expand Down Expand Up @@ -177,8 +186,7 @@ func executeBatchSpecInWorkspaces(ctx context.Context, flags *executorModeFlags)
ui.PreparingContainerImagesSuccess()

// Empty for now until we support secrets or env var settings in SSBC.
globalEnv := []string{}
isRemote := true
var globalEnv []string

// Set up the execution UI.
taskExecUI := ui.ExecutingTasks(false, 1)
Expand All @@ -191,19 +199,18 @@ func executeBatchSpecInWorkspaces(ctx context.Context, flags *executorModeFlags)
EnsureImage: imageCache.Ensure,
Task: task,
// TODO: Should be slightly less than the executor timeout. Can we somehow read that?
Timeout: flags.timeout,
TempDir: tempDir,
GlobalEnv: globalEnv,
// Temporarily prevent the ability to sending a batch spec with a mount for server-side processing.
IsRemote: isRemote,
RepoArchive: &repozip.NoopArchive{},
UI: taskExecUI.StepsExecutionUI(task),
Timeout: flags.timeout,
TempDir: tempDir,
WorkingDirectory: workspaceFilesDir,
GlobalEnv: globalEnv,
RepoArchive: &repozip.NoopArchive{},
UI: taskExecUI.StepsExecutionUI(task),
}
results, err := executor.RunSteps(ctx, opts)

// Write all step cache results for all results.
for _, stepRes := range results {
cacheKey := task.CacheKey(globalEnv, isRemote, stepRes.StepIndex)
cacheKey := task.CacheKey(globalEnv, workspaceFilesDir, stepRes.StepIndex)
k, err := cacheKey.Key()
if err != nil {
return errors.Wrap(err, "calculating step cache key")
Expand Down
17 changes: 16 additions & 1 deletion cmd/src/batch_remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Examples:
// may as well validate it at the same time so we don't even have to go to
// the backend if it's invalid.
ui.ParsingBatchSpec()
spec, raw, err := parseBatchSpec(ctx, file, svc, true)
spec, batchSpecDir, raw, err := parseBatchSpec(ctx, file, svc)
if err != nil {
ui.ParsingBatchSpecFailure(err)
return err
Expand Down Expand Up @@ -100,6 +100,21 @@ Examples:
}
ui.SendingBatchSpecSuccess()

hasWorkspaceFiles := false
for _, step := range spec.Steps {
if len(step.Mount) > 0 {
hasWorkspaceFiles = true
break
}
}
if hasWorkspaceFiles {
ui.UploadingWorkspaceFiles()
if err = svc.UploadBatchSpecWorkspaceFiles(ctx, batchSpecDir, batchSpecID, spec.Steps); err != nil {
return err
}
ui.UploadingWorkspaceFilesSuccess()
}

// Wait for the workspaces to be resolved.
ui.ResolvingWorkspaces()
ticker := time.NewTicker(1 * time.Second)
Expand Down
2 changes: 1 addition & 1 deletion cmd/src/batch_repositories.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ Examples:
}

out := output.NewOutput(flagSet.Output(), output.OutputOpts{Verbose: *verbose})
spec, _, err := parseBatchSpec(ctx, file, svc, false)
spec, _, _, err := parseBatchSpec(ctx, file, svc)
if err != nil {
ui := &ui.TUI{Out: out}
ui.ParsingBatchSpecFailure(err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/src/batch_validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ Examples:
return err
}

if _, _, err := parseBatchSpec(ctx, file, svc, false); err != nil {
if _, _, _, err := parseBatchSpec(ctx, file, svc); err != nil {
ui.ParsingBatchSpecFailure(err)
return err
}
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ require (
github.com/sourcegraph/go-diff v0.6.1
github.com/sourcegraph/jsonx v0.0.0-20200629203448-1a936bd500cf
github.com/sourcegraph/scip v0.2.1
github.com/sourcegraph/sourcegraph/lib v0.0.0-20220825181731-397a768a5290
github.com/sourcegraph/sourcegraph/lib v0.0.0-20221004162410-237d5855fa13
github.com/stretchr/testify v1.8.0
golang.org/x/net v0.0.0-20220722155237-a158d28d115b
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4
Expand Down Expand Up @@ -105,7 +105,7 @@ require (
go.uber.org/zap v1.23.0 // indirect
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 // indirect
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect
golang.org/x/sys v0.0.0-20220829200755-d48e67d00261 // indirect
golang.org/x/sys v0.0.0-20220928140112-f11e5e49a4ec // indirect
golang.org/x/term v0.0.0-20220411215600-e5f449aeb171 // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/tools v0.1.12 // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -373,8 +373,8 @@ github.com/sourcegraph/log v0.0.0-20220901143117-fc0516a694c9 h1:JjFyvx9hCD5+Jpu
github.com/sourcegraph/log v0.0.0-20220901143117-fc0516a694c9/go.mod h1:UxiwB6C3xk3xOySJpW1R0MDUyfGuJRFS5Z8C+SA5p2I=
github.com/sourcegraph/scip v0.2.1 h1:t4cTR8TU81Psfmcj3ZYer67JFzsR/Sc7w5rsuckRo1Y=
github.com/sourcegraph/scip v0.2.1/go.mod h1:EYyT39nXdZDNVmgbJAlyIVWbEb1txnAOKpJPSYpvgXk=
github.com/sourcegraph/sourcegraph/lib v0.0.0-20220825181731-397a768a5290 h1:SLCu3Rf1eLZ4sNKl0Bg1oURTgDxEutRCaTQt5dpVqH4=
github.com/sourcegraph/sourcegraph/lib v0.0.0-20220825181731-397a768a5290/go.mod h1:9wnFUNfpORLAOJn4XAO7ZeWnYkf6/CxlWaTU1vlpuKc=
github.com/sourcegraph/sourcegraph/lib v0.0.0-20221004162410-237d5855fa13 h1:HEj9QVz35nIU4plPb7iJSFjcTA14zVnfAdfYZF5jsKg=
github.com/sourcegraph/sourcegraph/lib v0.0.0-20221004162410-237d5855fa13/go.mod h1:e3v3msUOgthv/QCWUzhFdfR3+hwUSn37rtuw49IVJg4=
github.com/sourcegraph/yaml v1.0.1-0.20200714132230-56936252f152 h1:z/MpntplPaW6QW95pzcAR/72Z5TWDyDnSo0EOcyij9o=
github.com/sourcegraph/yaml v1.0.1-0.20200714132230-56936252f152/go.mod h1:GIjDIg/heH5DOkXY3YJ/wNhfHsQHoXGjl8G8amsYQ1I=
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
Expand Down Expand Up @@ -540,8 +540,8 @@ golang.org/x/sys v0.0.0-20211117180635-dee7805ff2e1/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20211213223007-03aa0b5f6827/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220209214540-3681064d5158/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220829200755-d48e67d00261 h1:v6hYoSR9T5oet+pMXwUWkbiVqx/63mlHjefrHmxwfeY=
golang.org/x/sys v0.0.0-20220829200755-d48e67d00261/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220928140112-f11e5e49a4ec h1:BkDtF2Ih9xZ7le9ndzTA7KJow28VbQW3odyk/8drmuI=
golang.org/x/sys v0.0.0-20220928140112-f11e5e49a4ec/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20220411215600-e5f449aeb171 h1:EH1Deb8WZJ0xc0WK//leUHXcX9aLE5SymusoTmMZye8=
golang.org/x/term v0.0.0-20220411215600-e5f449aeb171/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
Expand Down
8 changes: 4 additions & 4 deletions internal/batches/executor/coordinator.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (c *Coordinator) CheckCache(ctx context.Context, batchSpec *batcheslib.Batc
func (c *Coordinator) ClearCache(ctx context.Context, tasks []*Task) error {
for _, task := range tasks {
for i := len(task.Steps) - 1; i > -1; i-- {
key := task.CacheKey(c.opts.GlobalEnv, c.opts.IsRemote, i)
key := task.CacheKey(c.opts.GlobalEnv, c.opts.ExecOpts.WorkingDirectory, i)
if err := c.opts.Cache.Clear(ctx, key); err != nil {
return errors.Wrapf(err, "clearing cache for step %d in %q", i, task.Repository.Name)
}
Expand Down Expand Up @@ -100,7 +100,7 @@ func (c *Coordinator) checkCacheForTask(ctx context.Context, batchSpec *batchesl
return specs, false, nil
}

func (c Coordinator) buildChangesetSpecs(task *Task, batchSpec *batcheslib.BatchSpec, result execution.AfterStepResult) ([]*batcheslib.ChangesetSpec, error) {
func (c *Coordinator) buildChangesetSpecs(task *Task, batchSpec *batcheslib.BatchSpec, result execution.AfterStepResult) ([]*batcheslib.ChangesetSpec, error) {
input := &batcheslib.ChangesetSpecInput{
Repository: batcheslib.Repository{
ID: task.Repository.ID,
Expand Down Expand Up @@ -128,7 +128,7 @@ func (c *Coordinator) loadCachedStepResults(ctx context.Context, task *Task, glo
// We start at the back so that we can find the _last_ cached step,
// then restart execution on the following step.
for i := len(task.Steps) - 1; i > -1; i-- {
key := task.CacheKey(globalEnv, c.opts.IsRemote, i)
key := task.CacheKey(globalEnv, c.opts.ExecOpts.WorkingDirectory, i)

result, found, err := c.opts.Cache.Get(ctx, key)
if err != nil {
Expand Down Expand Up @@ -181,7 +181,7 @@ func (c *Coordinator) ExecuteAndBuildSpecs(ctx context.Context, batchSpec *batch
// Write all step cache results to the cache.
for _, res := range results {
for _, stepRes := range res.stepResults {
cacheKey := res.task.CacheKey(c.opts.GlobalEnv, c.opts.IsRemote, stepRes.StepIndex)
cacheKey := res.task.CacheKey(c.opts.GlobalEnv, c.opts.ExecOpts.WorkingDirectory, stepRes.StepIndex)
if err := c.opts.Cache.Set(ctx, cacheKey, stepRes); err != nil {
return nil, nil, errors.Wrapf(err, "caching result for step %d", stepRes.StepIndex)
}
Expand Down
29 changes: 15 additions & 14 deletions internal/batches/executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,12 @@ type NewExecutorOpts struct {
Logger log.LogManager

// Config
Parallelism int
Timeout time.Duration
TempDir string
IsRemote bool
GlobalEnv []string
Parallelism int
Timeout time.Duration
WorkingDirectory string
TempDir string
IsRemote bool
GlobalEnv []string
}

type executor struct {
Expand Down Expand Up @@ -168,15 +169,15 @@ func (x *executor) do(ctx context.Context, task *Task, ui TaskExecutionUI) (err

// Actually execute the steps.
opts := &RunStepsOpts{
Task: task,
Logger: l,
WC: x.opts.Creator,
EnsureImage: x.opts.EnsureImage,
TempDir: x.opts.TempDir,
IsRemote: x.opts.IsRemote,
GlobalEnv: x.opts.GlobalEnv,
Timeout: x.opts.Timeout,
RepoArchive: repoArchive,
Task: task,
Logger: l,
WC: x.opts.Creator,
EnsureImage: x.opts.EnsureImage,
TempDir: x.opts.TempDir,
GlobalEnv: x.opts.GlobalEnv,
Timeout: x.opts.Timeout,
RepoArchive: repoArchive,
WorkingDirectory: x.opts.WorkingDirectory,

UI: ui.StepsExecutionUI(task),
}
Expand Down
Loading