fix: skip optional remote includes on offline cache miss (#3081)
This commit is contained in:
parent
218dc43ad7
commit
7e4cccde96
6 changed files with 101 additions and 0 deletions
50
task_test.go
50
task_test.go
|
|
@ -1323,6 +1323,56 @@ func TestIncludesRemote(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestIncludesRemoteOptionalOfflineCacheMiss(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
dir string
|
||||
wantErr string
|
||||
}{
|
||||
{
|
||||
name: "optional include is skipped",
|
||||
dir: "testdata/includes_remote_optional_offline",
|
||||
},
|
||||
{
|
||||
name: "non-optional include still fails",
|
||||
dir: "testdata/includes_remote_nonoptional_offline",
|
||||
wantErr: "was not found in the cache",
|
||||
},
|
||||
{
|
||||
name: "non-optional nested include still fails",
|
||||
dir: "testdata/includes_remote_optional_parent_offline",
|
||||
wantErr: "was not found in the cache",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var buff bytes.Buffer
|
||||
e := task.NewExecutor(
|
||||
task.WithDir(tt.dir),
|
||||
task.WithStdout(&buff),
|
||||
task.WithStderr(&buff),
|
||||
task.WithOffline(true),
|
||||
task.WithRemoteCacheDir(t.TempDir()),
|
||||
)
|
||||
|
||||
err := e.Setup()
|
||||
if tt.wantErr != "" {
|
||||
require.Error(t, err)
|
||||
assert.Contains(t, err.Error(), tt.wantErr)
|
||||
return
|
||||
}
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, e.Run(t.Context(), &task.Call{Task: "local"}))
|
||||
assert.Contains(t, buff.String(), "Hello from local")
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestIncludeCycle(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
|
|
|
|||
|
|
@ -211,6 +211,15 @@ func (r *Reader) include(ctx context.Context, node Node) error {
|
|||
return err
|
||||
}
|
||||
|
||||
// Checked before recursing so a nested include's cache miss isn't mistaken for this one's.
|
||||
if include.Optional && r.offline {
|
||||
if remote, ok := includeNode.(RemoteNode); ok {
|
||||
if _, err := NewCacheNode(remote, r.tempDir).Read(); errors.Is(err, os.ErrNotExist) {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Recurse into the included Taskfile
|
||||
if err := r.include(ctx, includeNode); err != nil {
|
||||
return err
|
||||
|
|
|
|||
10
testdata/includes_remote_nonoptional_offline/Taskfile.yml
vendored
Normal file
10
testdata/includes_remote_nonoptional_offline/Taskfile.yml
vendored
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
version: "3"
|
||||
|
||||
includes:
|
||||
remote:
|
||||
taskfile: https://github.com/go-task/task.git//Taskfile.yml
|
||||
|
||||
tasks:
|
||||
local:
|
||||
cmds:
|
||||
- echo "Hello from local"
|
||||
11
testdata/includes_remote_optional_offline/Taskfile.yml
vendored
Normal file
11
testdata/includes_remote_optional_offline/Taskfile.yml
vendored
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
version: "3"
|
||||
|
||||
includes:
|
||||
remote:
|
||||
taskfile: https://github.com/go-task/task.git//Taskfile.yml
|
||||
optional: true
|
||||
|
||||
tasks:
|
||||
local:
|
||||
cmds:
|
||||
- echo "Hello from local"
|
||||
11
testdata/includes_remote_optional_parent_offline/Taskfile.yml
vendored
Normal file
11
testdata/includes_remote_optional_parent_offline/Taskfile.yml
vendored
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
version: "3"
|
||||
|
||||
includes:
|
||||
opt:
|
||||
taskfile: ./opt.yml
|
||||
optional: true
|
||||
|
||||
tasks:
|
||||
local:
|
||||
cmds:
|
||||
- echo "Hello from local"
|
||||
10
testdata/includes_remote_optional_parent_offline/opt.yml
vendored
Normal file
10
testdata/includes_remote_optional_parent_offline/opt.yml
vendored
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
version: "3"
|
||||
|
||||
includes:
|
||||
remote:
|
||||
taskfile: https://github.com/go-task/task.git//Taskfile.yml
|
||||
|
||||
tasks:
|
||||
nested:
|
||||
cmds:
|
||||
- echo "Hello from nested"
|
||||
Loading…
Reference in a new issue