mirror of
https://github.com/go-task/task.git
synced 2025-11-23 22:24:45 +02:00
fix: adjust run: when_changed to work correctly with imported tasks (#2511)
This commit is contained in:
@@ -20,5 +20,5 @@ func Name(t *ast.Task) (string, error) {
|
|||||||
|
|
||||||
func Hash(t *ast.Task) (string, error) {
|
func Hash(t *ast.Task) (string, error) {
|
||||||
h, err := hashstructure.Hash(t, hashstructure.FormatV2, nil)
|
h, err := hashstructure.Hash(t, hashstructure.FormatV2, nil)
|
||||||
return fmt.Sprintf("%s:%d", t.Task, h), err
|
return fmt.Sprintf("%s:%s:%d", t.Location.Taskfile, t.LocalName(), h), err
|
||||||
}
|
}
|
||||||
|
|||||||
23
task_test.go
23
task_test.go
@@ -1851,6 +1851,29 @@ func TestRunOnceSharedDeps(t *testing.T) {
|
|||||||
assert.Contains(t, buff.String(), `task: [service-b:build] echo "build b"`)
|
assert.Contains(t, buff.String(), `task: [service-b:build] echo "build b"`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestRunWhenChanged(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
const dir = "testdata/run_when_changed"
|
||||||
|
|
||||||
|
var buff bytes.Buffer
|
||||||
|
e := task.NewExecutor(
|
||||||
|
task.WithDir(dir),
|
||||||
|
task.WithStdout(&buff),
|
||||||
|
task.WithStderr(&buff),
|
||||||
|
task.WithForceAll(true),
|
||||||
|
task.WithSilent(true),
|
||||||
|
)
|
||||||
|
require.NoError(t, e.Setup())
|
||||||
|
require.NoError(t, e.Run(t.Context(), &task.Call{Task: "start"}))
|
||||||
|
expectedOutputOrder := strings.TrimSpace(`
|
||||||
|
login server=fubar user=fubar
|
||||||
|
login server=foo user=foo
|
||||||
|
login server=bar user=bar
|
||||||
|
`)
|
||||||
|
assert.Contains(t, buff.String(), expectedOutputOrder)
|
||||||
|
}
|
||||||
|
|
||||||
func TestDeferredCmds(t *testing.T) {
|
func TestDeferredCmds(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import (
|
|||||||
|
|
||||||
// Task represents a task
|
// Task represents a task
|
||||||
type Task struct {
|
type Task struct {
|
||||||
Task string
|
Task string `hash:"ignore"`
|
||||||
Cmds []*Cmd
|
Cmds []*Cmd
|
||||||
Deps []*Dep
|
Deps []*Dep
|
||||||
Label string
|
Label string
|
||||||
@@ -36,18 +36,18 @@ type Task struct {
|
|||||||
Interactive bool
|
Interactive bool
|
||||||
Internal bool
|
Internal bool
|
||||||
Method string
|
Method string
|
||||||
Prefix string
|
Prefix string `hash:"ignore"`
|
||||||
IgnoreError bool
|
IgnoreError bool
|
||||||
Run string
|
Run string
|
||||||
Platforms []*Platform
|
Platforms []*Platform
|
||||||
Watch bool
|
Watch bool
|
||||||
Location *Location
|
Location *Location
|
||||||
// Populated during merging
|
// Populated during merging
|
||||||
Namespace string
|
Namespace string `hash:"ignore"`
|
||||||
IncludeVars *Vars
|
IncludeVars *Vars
|
||||||
IncludedTaskfileVars *Vars
|
IncludedTaskfileVars *Vars
|
||||||
|
|
||||||
FullName string
|
FullName string `hash:"ignore"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Task) Name() string {
|
func (t *Task) Name() string {
|
||||||
|
|||||||
11
testdata/run_when_changed/Taskfile.yml
vendored
Normal file
11
testdata/run_when_changed/Taskfile.yml
vendored
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
version: '3'
|
||||||
|
|
||||||
|
includes:
|
||||||
|
service-a: ./service-a
|
||||||
|
service-b: ./service-b
|
||||||
|
|
||||||
|
tasks:
|
||||||
|
start:
|
||||||
|
cmds:
|
||||||
|
- task: service-a:start
|
||||||
|
- task: service-b:start
|
||||||
7
testdata/run_when_changed/library/Taskfile.yml
vendored
Normal file
7
testdata/run_when_changed/library/Taskfile.yml
vendored
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
version: '3'
|
||||||
|
|
||||||
|
tasks:
|
||||||
|
login:
|
||||||
|
run: when_changed
|
||||||
|
cmds:
|
||||||
|
- echo "login server={{.SERVER}} user={{.USER}}"
|
||||||
18
testdata/run_when_changed/service-a/Taskfile.yml
vendored
Normal file
18
testdata/run_when_changed/service-a/Taskfile.yml
vendored
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
version: '3'
|
||||||
|
|
||||||
|
includes:
|
||||||
|
library:
|
||||||
|
taskfile: ../library/Taskfile.yml
|
||||||
|
dir: ../library
|
||||||
|
|
||||||
|
tasks:
|
||||||
|
start:
|
||||||
|
cmds:
|
||||||
|
- task: library:login
|
||||||
|
vars:
|
||||||
|
SERVER: fubar
|
||||||
|
USER: fubar
|
||||||
|
- task: library:login
|
||||||
|
vars:
|
||||||
|
SERVER: foo
|
||||||
|
USER: foo
|
||||||
18
testdata/run_when_changed/service-b/Taskfile.yml
vendored
Normal file
18
testdata/run_when_changed/service-b/Taskfile.yml
vendored
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
version: '3'
|
||||||
|
|
||||||
|
includes:
|
||||||
|
library:
|
||||||
|
taskfile: ../library/Taskfile.yml
|
||||||
|
dir: ../library
|
||||||
|
|
||||||
|
tasks:
|
||||||
|
start:
|
||||||
|
cmds:
|
||||||
|
- task: library:login
|
||||||
|
vars:
|
||||||
|
SERVER: fubar
|
||||||
|
USER: fubar
|
||||||
|
- task: library:login
|
||||||
|
vars:
|
||||||
|
SERVER: bar
|
||||||
|
USER: bar
|
||||||
Reference in New Issue
Block a user