Skip to content

Commit

Permalink
Correct task output hashing.
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanhammond committed Apr 28, 2023
1 parent daa6ee7 commit 161ff15
Show file tree
Hide file tree
Showing 8 changed files with 135 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"$schema": "https://turbo.build/schema.json",
"globalDependencies": ["foo.txt"],
"globalEnv": ["SOME_ENV_VAR"],
"pipeline": {
"build": {
"env": ["NODE_ENV"],
"outputs": []
},
"my-app#build": {
"dependsOn": ["^build"],
"outputs": ["banana.txt", "apple.json"]
},

"something": {},
"//#something": {},

"maybefails": {}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"$schema": "https://turbo.build/schema.json",
"globalDependencies": ["foo.txt"],
"globalEnv": ["SOME_ENV_VAR"],
"pipeline": {
"build": {
"env": ["NODE_ENV"],
"outputs": []
},
"util#build": {
"env": ["NODE_ENV"],
"outputs": []
},
"my-app#build": {
"dependsOn": ["^build"],
"outputs": ["banana.txt", "apple.json"]
},

"something": {},
"//#something": {},

"maybefails": {}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"$schema": "https://turbo.build/schema.json",
"globalDependencies": ["foo.txt"],
"globalEnv": ["SOME_ENV_VAR"],
"pipeline": {
"build": {
"env": ["NODE_ENV"],
"outputs": []
},
"util#build": {
"env": ["NODE_ENV", "CASCADE"],
"outputs": []
},
"my-app#build": {
"dependsOn": ["^build"],
"outputs": ["banana.txt", "apple.json"]
},

"something": {},
"//#something": {},

"maybefails": {}
}
}
61 changes: 55 additions & 6 deletions cli/integration_tests/edit_turbo_json/task.t
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,78 @@ Baseline task hashes
$ ${TURBO} build --dry=json | jq -r '.tasks | sort_by(.taskId)[] | {taskId, hash}'
{
"taskId": "another#build",
"hash": "4c4f0e076ebc3a2a"
"hash": "8d90a05aa60bd604"
}
{
"taskId": "my-app#build",
"hash": "9431e2a02286769a"
"hash": "bcfea334449257fe"
}
{
"taskId": "util#build",
"hash": "e6ceb7aa9a6948f8"
"hash": "e64dab76e045fbb4"
}

Change only my-app#build
$ cp "$TESTDIR/fixture-configs/b-change-only-my-app.json" "$(pwd)/turbo.json" && git commit -am "no comment" --quiet
$ ${TURBO} build --dry=json | jq -r '.tasks | sort_by(.taskId)[] | {taskId, hash}'
{
"taskId": "another#build",
"hash": "4c4f0e076ebc3a2a"
"hash": "8d90a05aa60bd604"
}
{
"taskId": "my-app#build",
"hash": "WAT"
"hash": "943c0f8cc9e90a1e"
}
{
"taskId": "util#build",
"hash": "e6ceb7aa9a6948f8"
"hash": "e64dab76e045fbb4"
}

Change my-app#build dependsOn
$ cp "$TESTDIR/fixture-configs/c-my-app-depends-on.json" "$(pwd)/turbo.json" && git commit -am "no comment" --quiet
$ ${TURBO} build --dry=json | jq -r '.tasks | sort_by(.taskId)[] | {taskId, hash}'
{
"taskId": "another#build",
"hash": "8d90a05aa60bd604"
}
{
"taskId": "my-app#build",
"hash": "61dafe4314e0156a"
}
{
"taskId": "util#build",
"hash": "e64dab76e045fbb4"
}

Non-materially modifying the dep graph does nothing.
$ cp "$TESTDIR/fixture-configs/d-depends-on-util.json" "$(pwd)/turbo.json" && git commit -am "no comment" --quiet
$ ${TURBO} build --dry=json | jq -r '.tasks | sort_by(.taskId)[] | {taskId, hash}'
{
"taskId": "another#build",
"hash": "8d90a05aa60bd604"
}
{
"taskId": "my-app#build",
"hash": "61dafe4314e0156a"
}
{
"taskId": "util#build",
"hash": "e64dab76e045fbb4"
}


Change util#build impacts itself and my-app
$ cp "$TESTDIR/fixture-configs/e-depends-on-util-but-modified.json" "$(pwd)/turbo.json" && git commit -am "no comment" --quiet
$ ${TURBO} build --dry=json | jq -r '.tasks | sort_by(.taskId)[] | {taskId, hash}'
{
"taskId": "another#build",
"hash": "8d90a05aa60bd604"
}
{
"taskId": "my-app#build",
"hash": "f976edb1e8ddf783"
}
{
"taskId": "util#build",
"hash": "1f378ad2e5831e1f"
}
11 changes: 3 additions & 8 deletions cli/internal/fs/turbo_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,14 +286,9 @@ type TaskOutputs struct {
}

// Sort contents of task outputs
func (to TaskOutputs) Sort() TaskOutputs {
var inclusions []string
var exclusions []string
copy(inclusions, to.Inclusions)
copy(exclusions, to.Exclusions)
sort.Strings(inclusions)
sort.Strings(exclusions)
return TaskOutputs{Inclusions: inclusions, Exclusions: exclusions}
func (to *TaskOutputs) Sort() {
sort.Strings(to.Inclusions)
sort.Strings(to.Exclusions)
}

// readTurboConfig reads turbo.json from a provided path
Expand Down
9 changes: 5 additions & 4 deletions cli/internal/fs/turbo_json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,11 @@ func Test_TaskOutputsSort(t *testing.T) {
inclusions := []string{"foo/**", "bar"}
exclusions := []string{"special-file", ".hidden/**"}
taskOutputs := TaskOutputs{Inclusions: inclusions, Exclusions: exclusions}
sortedOutputs := taskOutputs.Sort()
assertIsSorted(t, sortedOutputs.Inclusions, "Inclusions")
assertIsSorted(t, sortedOutputs.Exclusions, "Exclusions")
assert.False(t, cmp.DeepEqual(taskOutputs, sortedOutputs)().Success())
taskOutputs.Sort()
assertIsSorted(t, taskOutputs.Inclusions, "Inclusions")
assertIsSorted(t, taskOutputs.Exclusions, "Exclusions")

assert.True(t, cmp.DeepEqual(taskOutputs, TaskOutputs{Inclusions: []string{"bar", "foo/**"}, Exclusions: []string{".hidden/**", "special-file"}})().Success())
}

// Helpers
Expand Down
4 changes: 3 additions & 1 deletion cli/internal/nodes/packagetask.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ func (pt *PackageTask) HashableOutputs() fs.TaskOutputs {
inclusionOutputs := []string{fmt.Sprintf(".turbo/turbo-%v.log", pt.Task)}
inclusionOutputs = append(inclusionOutputs, pt.TaskDefinition.Outputs.Inclusions...)

return fs.TaskOutputs{
hashable := fs.TaskOutputs{
Inclusions: inclusionOutputs,
Exclusions: pt.TaskDefinition.Outputs.Exclusions,
}
hashable.Sort()
return hashable
}
2 changes: 1 addition & 1 deletion cli/internal/taskhash/taskhash.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ func (th *Tracker) CalculateTaskHash(packageTask *nodes.PackageTask, dependencyS
hashOfFiles: hashOfFiles,
externalDepsHash: packageTask.Pkg.ExternalDepsHash,
task: packageTask.Task,
outputs: outputs.Sort(),
outputs: outputs,
passThruArgs: args,
envMode: packageTask.EnvMode,
passthroughEnv: packageTask.TaskDefinition.PassthroughEnv,
Expand Down

0 comments on commit 161ff15

Please sign in to comment.