这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
394d9ef
Add support for env hashing
jaredpalmer Dec 22, 2021
ae936ed
Improve example
jaredpalmer Dec 22, 2021
69c2c6c
Remove println
jaredpalmer Dec 22, 2021
a0c389c
Merge branch 'main' into add-hashable-env-vars
jaredpalmer Dec 22, 2021
780b761
Merge branch 'main' into add-hashable-env-vars
jaredpalmer Dec 24, 2021
53f9576
Merge branch 'main' into add-hashable-env-vars
jaredpalmer Dec 24, 2021
3f9bddd
Merge branch 'main' into add-hashable-env-vars
jaredpalmer Dec 30, 2021
6b4de36
Refactor
jaredpalmer Dec 31, 2021
b4b6e04
Hash against any env var with TURBO in it, aside from safelist
jaredpalmer Jan 4, 2022
13743c9
Hash env vars in `dependsOn` prefixed w/ $
jaredpalmer Jan 4, 2022
2a7342a
Update docs
jaredpalmer Jan 4, 2022
81d2310
Remove hash env from scheduler for now
jaredpalmer Jan 4, 2022
3b3a40e
Add `globalDependencies` documentation
jaredpalmer Jan 4, 2022
eae8821
Merge branch 'main' into refactor-hashable-env-vars
jaredpalmer Jan 4, 2022
c098af0
Merge branch 'main' into refactor-hashable-env-vars
jaredpalmer Jan 7, 2022
78dabc4
Change hashable TURBO to THASH
jaredpalmer Jan 7, 2022
9287554
Elaborate on env var caching
jaredpalmer Jan 7, 2022
7cb78c3
Use a callout
jaredpalmer Jan 7, 2022
e155a72
Tweak language
jaredpalmer Jan 7, 2022
ee35de5
Merge branch 'main' into refactor-hashable-env-vars
jaredpalmer Jan 7, 2022
bfd30cf
publish 1.0.25-canary.0 to registry
jaredpalmer Jan 7, 2022
f1c1977
Merge branch 'main' into refactor-hashable-env-vars
jaredpalmer Jan 10, 2022
1134cce
Merge branch 'main' into refactor-hashable-env-vars
jaredpalmer Jan 10, 2022
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 cli/cmd/turbo/version.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package main

const turboVersion = "1.0.24"
const turboVersion = "1.0.25-canary.0"
82 changes: 64 additions & 18 deletions cli/internal/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package context

import (
"fmt"
"os"
"path"
"path/filepath"
"sort"
Expand Down Expand Up @@ -36,21 +37,23 @@ const (

// Context of the CLI
type Context struct {
Args []string
PackageInfos map[interface{}]*fs.PackageJSON
ColorCache *ColorCache
PackageNames []string
TopologicalGraph dag.AcyclicGraph
TaskGraph dag.AcyclicGraph
Dir string
RootNode string
RootPackageJSON *fs.PackageJSON
GlobalHash string
TraceFilePath string
Lockfile *fs.YarnLockfile
SCC [][]dag.Vertex
Targets []string
Backend *api.LanguageBackend
Args []string
PackageInfos map[interface{}]*fs.PackageJSON
ColorCache *ColorCache
PackageNames []string
TopologicalGraph dag.AcyclicGraph
TaskGraph dag.AcyclicGraph
Dir string
RootNode string
RootPackageJSON *fs.PackageJSON
GlobalHashableEnvPairs []string
GlobalHashableEnvNames []string
GlobalHash string
TraceFilePath string
Lockfile *fs.YarnLockfile
SCC [][]dag.Vertex
Targets []string
Backend *api.LanguageBackend
// Used to arbitrate access to the graph. We parallelise most build operations
// and Go maps aren't natively threadsafe so this is needed.
mutex sync.Mutex
Expand Down Expand Up @@ -146,12 +149,37 @@ func WithGraph(rootpath string, config *config.Config) Option {
// Calculate the global hash
globalDeps := make(util.Set)

// Calculate global file and env var dependencies
if len(pkg.Turbo.GlobalDependencies) > 0 {
f := globby.GlobFiles(rootpath, pkg.Turbo.GlobalDependencies, []string{})
for _, val := range f {
globalDeps.Add(val)
var globs []string
for _, v := range pkg.Turbo.GlobalDependencies {
if strings.HasPrefix(v, "$") {
trimmed := strings.TrimPrefix(v, "$")
c.GlobalHashableEnvNames = append(c.GlobalHashableEnvNames, trimmed)
c.GlobalHashableEnvPairs = append(c.GlobalHashableEnvPairs, fmt.Sprintf("%v=%v", trimmed, os.Getenv(trimmed)))
} else {
globs = append(globs, v)
}
}

if len(globs) > 0 {
f := globby.GlobFiles(rootpath, globs, []string{})
for _, val := range f {
globalDeps.Add(val)
}
}
}

// get system env vars for hashing purposes, these include any variable that includes "TURBO"
// that is NOT TURBO_TOKEN or TURBO_TEAM or TURBO_BINARY_PATH.
names, pairs := getHashableTurboEnvVarsFromOs()
c.GlobalHashableEnvNames = append(c.GlobalHashableEnvNames, names...)
c.GlobalHashableEnvPairs = append(c.GlobalHashableEnvPairs, pairs...)
// sort them for consistent hashing
sort.Strings(c.GlobalHashableEnvNames)
sort.Strings(c.GlobalHashableEnvPairs)
config.Logger.Debug("global hash env vars", "vars", c.GlobalHashableEnvNames)

if c.Backend.Name != "nodejs-yarn" {
// If we are not in Yarn, add the specfile and lockfile to global deps
globalDeps.Add(c.Backend.Specfile)
Expand All @@ -165,10 +193,12 @@ func WithGraph(rootpath string, config *config.Config) Option {
globalHashable := struct {
globalFileHashMap map[string]string
rootExternalDepsHash string
hashedSortedEnvPairs []string
globalCacheKey string
}{
globalFileHashMap: globalFileHashMap,
rootExternalDepsHash: pkg.ExternalDepsHash,
hashedSortedEnvPairs: c.GlobalHashableEnvPairs,
globalCacheKey: GLOBAL_CACHE_KEY,
}
globalHash, err := fs.HashObject(globalHashable)
Expand Down Expand Up @@ -487,3 +517,19 @@ func getWorkspaceIgnores() []string {
"**/tests/**/*",
}
}

// getHashableTurboEnvVarsFromOs returns a list of environment variables names and
// that are safe to include in the global hash
func getHashableTurboEnvVarsFromOs() ([]string, []string) {
var justNames []string
var pairs []string
for _, e := range os.Environ() {
kv := strings.SplitN(e, "=", 2)
if strings.Contains(kv[0], "THASH") {
justNames = append(justNames, kv[0])
pairs = append(pairs, e)
}
}

return justNames, pairs
}
20 changes: 20 additions & 0 deletions cli/internal/context/context_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package context

import (
"os"
"reflect"
"testing"
"turbo/internal/fs"
Expand Down Expand Up @@ -93,3 +94,22 @@ func TestGetTargetsFromArguments(t *testing.T) {
})
}
}

func Test_getHashableTurboEnvVarsFromOs(t *testing.T) {
os.Setenv("SOME_ENV_VAR", "excluded")
os.Setenv("SOME_OTHER_ENV_VAR", "excluded")
os.Setenv("FIRST_THASH_ENV_VAR", "first")
os.Setenv("TURBO_TOKEN", "never")
os.Setenv("SOME_OTHER_THASH_ENV_VAR", "second")
os.Setenv("TURBO_TEAM", "never")

gotNames, gotPairs := getHashableTurboEnvVarsFromOs()
wantNames := []string{"FIRST_THASH_ENV_VAR", "SOME_OTHER_THASH_ENV_VAR"}
wantPairs := []string{"FIRST_THASH_ENV_VAR=first", "SOME_OTHER_THASH_ENV_VAR=second"}
if !reflect.DeepEqual(wantNames, gotNames) {
t.Errorf("getHashableTurboEnvVarsFromOs() env names got = %v, want %v", gotNames, wantNames)
}
if !reflect.DeepEqual(wantPairs, gotPairs) {
t.Errorf("getHashableTurboEnvVarsFromOs() env pairs got = %v, want %v", gotPairs, wantPairs)
}
}
40 changes: 32 additions & 8 deletions cli/internal/run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
)

const TOPOLOGICAL_PIPELINE_DELMITER = "^"
const ENV_PIPELINE_DELMITER = "$"

// RunCommand is a Command implementation that tells Turbo to run a task
type RunCommand struct {
Expand Down Expand Up @@ -349,6 +350,9 @@ func (c *RunCommand) Run(args []string) int {
deps := make(util.Set)
if core.IsPackageTask(taskName) {
for _, from := range value.DependsOn {
if strings.HasPrefix(from, ENV_PIPELINE_DELMITER) {
continue
}
if core.IsPackageTask(from) {
engine.AddDep(from, taskName)
continue
Expand All @@ -362,6 +366,9 @@ func (c *RunCommand) Run(args []string) int {
taskName = id
} else {
for _, from := range value.DependsOn {
if strings.HasPrefix(from, ENV_PIPELINE_DELMITER) {
continue
}
if strings.Contains(from, TOPOLOGICAL_PIPELINE_DELMITER) {
topoDeps.Add(from[1:])
} else {
Expand Down Expand Up @@ -423,16 +430,33 @@ func (c *RunCommand) Run(args []string) int {
outputs = append(outputs, pipeline.Outputs...)
}
targetLogger.Debug("task output globs", "outputs", outputs)

// Hash the task-specific environment variables found in the dependsOnKey in the pipeline
var hashabledEnvVars []string
var hashabledEnvPairs []string
if len(pipeline.DependsOn) > 0 {
for _, v := range pipeline.DependsOn {
if strings.Contains(v, ENV_PIPELINE_DELMITER) {
trimmed := strings.TrimPrefix(v, ENV_PIPELINE_DELMITER)
hashabledEnvPairs = append(hashabledEnvVars, fmt.Sprintf("%v=%v", trimmed, os.Getenv(trimmed)))
hashabledEnvVars = append(hashabledEnvVars, trimmed)
}
}
sort.Strings(hashabledEnvVars) // always sort them
}
targetLogger.Debug("hashable env vars", "vars", hashabledEnvVars)
hashable := struct {
Hash string
Task string
Outputs []string
PassThruArgs []string
Hash string
Task string
Outputs []string
PassThruArgs []string
HashableEnvPairs []string
}{
Hash: pack.Hash,
Task: task,
Outputs: outputs,
PassThruArgs: runOptions.passThroughArgs,
Hash: pack.Hash,
Task: task,
Outputs: outputs,
PassThruArgs: runOptions.passThroughArgs,
HashableEnvPairs: hashabledEnvPairs,
}
hash, err := fs.HashObject(hashable)
targetLogger.Debug("task hash", "value", hash)
Expand Down
2 changes: 1 addition & 1 deletion cli/npm/turbo-android-arm64/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "turbo-android-arm64",
"version": "1.0.24",
"version": "1.0.25-canary.0",
"description": "The Android ARM 64-bit binary for turbo, a monorepo build system.",
"repository": "https://github.com/vercel/turborepo",
"bugs": "https://github.com/vercel/turborepo/issues",
Expand Down
2 changes: 1 addition & 1 deletion cli/npm/turbo-darwin-64/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "turbo-darwin-64",
"version": "1.0.24",
"version": "1.0.25-canary.0",
"description": "The macOS 64-bit binary for turbo, a monorepo build system.",
"repository": "https://github.com/vercel/turborepo",
"bugs": "https://github.com/vercel/turborepo/issues",
Expand Down
2 changes: 1 addition & 1 deletion cli/npm/turbo-darwin-arm64/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "turbo-darwin-arm64",
"version": "1.0.24",
"version": "1.0.25-canary.0",
"description": "The macOS ARM 64-bit binary for turbo, a monorepo build system.",
"repository": "https://github.com/vercel/turborepo",
"bugs": "https://github.com/vercel/turborepo/issues",
Expand Down
2 changes: 1 addition & 1 deletion cli/npm/turbo-freebsd-64/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "turbo-freebsd-64",
"version": "1.0.24",
"version": "1.0.25-canary.0",
"description": "The FreeBSD 64-bit binary for turbo, a monorepo build system.",
"repository": "https://github.com/vercel/turborepo",
"bugs": "https://github.com/vercel/turborepo/issues",
Expand Down
2 changes: 1 addition & 1 deletion cli/npm/turbo-freebsd-arm64/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "turbo-freebsd-arm64",
"version": "1.0.24",
"version": "1.0.25-canary.0",
"description": "The FreeBSD ARM 64-bit binary for turbo, a monorepo build system.",
"repository": "https://github.com/vercel/turborepo",
"bugs": "https://github.com/vercel/turborepo/issues",
Expand Down
26 changes: 13 additions & 13 deletions cli/npm/turbo-install/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "turbo",
"version": "1.0.24",
"version": "1.0.25-canary.0",
"description": "Turborepo is a high-performance build system for JavaScript and TypeScript codebases.",
"repository": "https://github.com/vercel/turborepo",
"bugs": "https://github.com/vercel/turborepo/issues",
Expand All @@ -18,17 +18,17 @@
"install.js"
],
"optionalDependencies": {
"turbo-darwin-64": "1.0.24",
"turbo-darwin-arm64": "1.0.24",
"turbo-freebsd-64": "1.0.24",
"turbo-freebsd-arm64": "1.0.24",
"turbo-linux-32": "1.0.24",
"turbo-linux-64": "1.0.24",
"turbo-linux-arm": "1.0.24",
"turbo-linux-arm64": "1.0.24",
"turbo-linux-mips64le": "1.0.24",
"turbo-linux-ppc64le": "1.0.24",
"turbo-windows-32": "1.0.24",
"turbo-windows-64": "1.0.24"
"turbo-darwin-64": "1.0.25-canary.0",
"turbo-darwin-arm64": "1.0.25-canary.0",
"turbo-freebsd-64": "1.0.25-canary.0",
"turbo-freebsd-arm64": "1.0.25-canary.0",
"turbo-linux-32": "1.0.25-canary.0",
"turbo-linux-64": "1.0.25-canary.0",
"turbo-linux-arm": "1.0.25-canary.0",
"turbo-linux-arm64": "1.0.25-canary.0",
"turbo-linux-mips64le": "1.0.25-canary.0",
"turbo-linux-ppc64le": "1.0.25-canary.0",
"turbo-windows-32": "1.0.25-canary.0",
"turbo-windows-64": "1.0.25-canary.0"
}
}
2 changes: 1 addition & 1 deletion cli/npm/turbo-linux-32/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "turbo-linux-32",
"version": "1.0.24",
"version": "1.0.25-canary.0",
"description": "The Linux 32-bit binary for turbo, a monorepo build system.",
"repository": "https://github.com/vercel/turborepo",
"bugs": "https://github.com/vercel/turborepo/issues",
Expand Down
2 changes: 1 addition & 1 deletion cli/npm/turbo-linux-64/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "turbo-linux-64",
"version": "1.0.24",
"version": "1.0.25-canary.0",
"description": "The Linux 64-bit binary for turbo, a monorepo build system.",
"repository": "https://github.com/vercel/turborepo",
"bugs": "https://github.com/vercel/turborepo/issues",
Expand Down
2 changes: 1 addition & 1 deletion cli/npm/turbo-linux-arm/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "turbo-linux-arm",
"version": "1.0.24",
"version": "1.0.25-canary.0",
"description": "The Linux ARM binary for turbo, a monorepo build system.",
"repository": "https://github.com/vercel/turborepo",
"bugs": "https://github.com/vercel/turborepo/issues",
Expand Down
2 changes: 1 addition & 1 deletion cli/npm/turbo-linux-arm64/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "turbo-linux-arm64",
"version": "1.0.24",
"version": "1.0.25-canary.0",
"description": "The Linux ARM 64-bit binary for turbo, a monorepo build system.",
"repository": "https://github.com/vercel/turborepo",
"bugs": "https://github.com/vercel/turborepo/issues",
Expand Down
2 changes: 1 addition & 1 deletion cli/npm/turbo-linux-mips64le/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "turbo-linux-mips64le",
"version": "1.0.24",
"version": "1.0.25-canary.0",
"description": "The Linux MIPS 64-bit Little Endian binary for turbo, a monorepo build system.",
"repository": "https://github.com/vercel/turborepo",
"bugs": "https://github.com/vercel/turborepo/issues",
Expand Down
2 changes: 1 addition & 1 deletion cli/npm/turbo-linux-ppc64le/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "turbo-linux-ppc64le",
"version": "1.0.24",
"version": "1.0.25-canary.0",
"description": "The Linux PowerPC 64-bit Little Endian binary for turbo, a monorepo build system.",
"repository": "https://github.com/vercel/turborepo",
"bugs": "https://github.com/vercel/turborepo/issues",
Expand Down
2 changes: 1 addition & 1 deletion cli/npm/turbo-windows-32/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "turbo-windows-32",
"version": "1.0.24",
"version": "1.0.25-canary.0",
"description": "The Windows 32-bit binary for turbo, a monorepo build system.",
"repository": "https://github.com/vercel/turborepo",
"bugs": "https://github.com/vercel/turborepo/issues",
Expand Down
2 changes: 1 addition & 1 deletion cli/npm/turbo-windows-64/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "turbo-windows-64",
"version": "1.0.24",
"version": "1.0.25-canary.0",
"description": "The Windows 64-bit binary for turbo, a monorepo build system.",
"repository": "https://github.com/vercel/turborepo",
"bugs": "https://github.com/vercel/turborepo/issues",
Expand Down
4 changes: 2 additions & 2 deletions cli/version.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
1.0.24
latest
1.0.25-canary.0
canary
2 changes: 1 addition & 1 deletion create-turbo/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "create-turbo",
"version": "1.0.24",
"version": "1.0.25-canary.0",
"description": "Create a new Turborepo",
"homepage": "https://turborepo.org",
"license": "MPL-2.0",
Expand Down
Loading