1
0
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:
Timothy Rule
2025-11-22 21:17:13 +01:00
committed by GitHub
parent 799bc85498
commit 386dcbc1a0
7 changed files with 82 additions and 5 deletions

View File

@@ -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
}

View File

@@ -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()

View File

@@ -13,7 +13,7 @@ import (
// Task represents a task
type Task struct {
Task string
Task string `hash:"ignore"`
Cmds []*Cmd
Deps []*Dep
Label string
@@ -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 {

11
testdata/run_when_changed/Taskfile.yml vendored Normal file
View 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

View File

@@ -0,0 +1,7 @@
version: '3'
tasks:
login:
run: when_changed
cmds:
- echo "login server={{.SERVER}} user={{.USER}}"

View 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

View 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