Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion internal/hash/hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ func Name(t *ast.Task) (string, error) {

func Hash(t *ast.Task) (string, error) {
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 changes: 23 additions & 0 deletions task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1851,6 +1851,29 @@ func TestRunOnceSharedDeps(t *testing.T) {
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) {
t.Parallel()

Expand Down
8 changes: 4 additions & 4 deletions taskfile/ast/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

// Task represents a task
type Task struct {
Task string
Task string `hash:"ignore"`
Cmds []*Cmd
Deps []*Dep
Label string
Expand All @@ -36,18 +36,18 @@ type Task struct {
Interactive bool
Internal bool
Method string
Prefix string
Prefix string `hash:"ignore"`
IgnoreError bool
Run string
Platforms []*Platform
Watch bool
Location *Location
// Populated during merging
Namespace string
Namespace string `hash:"ignore"`
IncludeVars *Vars
IncludedTaskfileVars *Vars

FullName string
FullName string `hash:"ignore"`
}

func (t *Task) Name() string {
Expand Down
11 changes: 11 additions & 0 deletions testdata/run_when_changed/Taskfile.yml
Original file line number Diff line number Diff line change
@@ -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 changes: 7 additions & 0 deletions testdata/run_when_changed/library/Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: '3'

tasks:
login:
run: when_changed
cmds:
- echo "login server={{.SERVER}} user={{.USER}}"
18 changes: 18 additions & 0 deletions testdata/run_when_changed/service-a/Taskfile.yml
Original file line number Diff line number Diff line change
@@ -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 changes: 18 additions & 0 deletions testdata/run_when_changed/service-b/Taskfile.yml
Original file line number Diff line number Diff line change
@@ -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
Loading