Skip to content

Commit

Permalink
Remove THASH (#4724)
Browse files Browse the repository at this point in the history
After 1.9 as a deprecation period (and having heard no user feedback as
to being an integral part of their workflow) this removes `THASH`.

Related: #4526
  • Loading branch information
nathanhammond committed May 18, 2023
1 parent f43f259 commit ebc002c
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 48 deletions.
14 changes: 1 addition & 13 deletions cli/internal/run/global_hash.go
Expand Up @@ -3,10 +3,8 @@ package run
import (
"fmt"
"path/filepath"
"strings"

"github.com/hashicorp/go-hclog"
"github.com/mitchellh/cli"
"github.com/vercel/turbo/cli/internal/env"
"github.com/vercel/turbo/cli/internal/fs"
"github.com/vercel/turbo/cli/internal/globby"
Expand Down Expand Up @@ -133,26 +131,16 @@ func getGlobalHashInputs(
envMode util.EnvMode,
frameworkInference bool,
logger hclog.Logger,
ui cli.Ui,
isStructuredOutput bool,
) (GlobalHashableInputs, error) {
// Calculate env var dependencies
envVars := []string{}
envVars = append(envVars, envVarDependencies...)
envVars = append(envVars, _defaultEnvVars...)
globalHashableEnvVars, err := env.GetHashableEnvVars(envVars, []string{".*THASH.*"}, "")
globalHashableEnvVars, err := env.GetHashableEnvVars(envVars, nil, "")
if err != nil {
return GlobalHashableInputs{}, err
}

// The only way we can add env vars into the hash via matching is via THASH,
// so we only do a simple check here for entries in `BySource.Matching`.
// If we enable globalEnv to accept wildcard characters, we'll need to update this
// check.
if !isStructuredOutput && len(globalHashableEnvVars.BySource.Matching) > 0 {
ui.Warn(fmt.Sprintf("[DEPRECATED] Using .*THASH.* to specify an environment variable for inclusion into the hash is deprecated. You specified: %s.", strings.Join(globalHashableEnvVars.BySource.Matching.Names(), ", ")))
}

logger.Debug("global hash env vars", "vars", globalHashableEnvVars.All.Names())

// Calculate global file dependencies
Expand Down
4 changes: 0 additions & 4 deletions cli/internal/run/run.go
Expand Up @@ -154,8 +154,6 @@ func (r *run) run(ctx gocontext.Context, targets []string, executionState *turbo
return fmt.Errorf("failed to read package.json: %w", err)
}

isStructuredOutput := r.opts.runOpts.GraphDot || r.opts.runOpts.DryRunJSON

var pkgDepGraph *context.Context
if r.opts.runOpts.SinglePackage {
pkgDepGraph, err = context.SinglePackageGraph(rootPackageJSON, executionState.PackageManager)
Expand Down Expand Up @@ -251,8 +249,6 @@ func (r *run) run(ctx gocontext.Context, targets []string, executionState *turbo
r.opts.runOpts.EnvMode,
r.opts.runOpts.FrameworkInference,
r.base.Logger,
r.base.UI,
isStructuredOutput,
)

if err != nil {
Expand Down
1 change: 0 additions & 1 deletion docs/pages/blog/turbo-1-1-0.mdx
Expand Up @@ -82,7 +82,6 @@ You can now control `turbo`'s [cache fingerprinting (a.k.a. hashing)](/repo/docs
- Including environment variables in a `dependsOn` in your `pipeline` definition prefixed by a `$` will impact the cache fingerprint on a per-task or per-package-task basis.
- Including environment variables in `globalDependencies` list prefixed by a `$` will impact the cache fingerprint of _all_ tasks.
- Including files or globs of files in `globalDependencies` will impact the cache fingerprint of _all_ tasks.
- The value of any environment variable that includes `THASH` in its name will impact the cache fingerprint of _all_ tasks.

```jsonc
{
Expand Down
2 changes: 0 additions & 2 deletions docs/pages/repo/docs/core-concepts/caching.mdx
Expand Up @@ -194,7 +194,6 @@ You can control `turbo`'s caching behavior based on
the values of environment variables:

- Including environment variables in the `env` key in your `pipeline` definition will impact the cache fingerprint on a per-task or per-workspace-task basis.
- The value of any environment variable that includes `THASH` in its name will impact the cache fingerprint of _all_ tasks.

```jsonc
{
Expand Down Expand Up @@ -436,7 +435,6 @@ By now, you're probably wondering how `turbo` decides what constitutes a cache h
First, `turbo` constructs a hash of the current global state of the codebase:

- The contents of any files that satisfy the glob patterns and any the values of environment variables listed in [`globalDependencies`](/repo/docs/reference/configuration#globalDependencies)
- The sorted list environment variable key-value pairs that include `THASH` _anywhere_ in their names (e.g. `STRIPE_PUBLIC_THASH_SECRET_KEY`, but not `STRIPE_PUBLIC_KEY`)

Then it adds more factors relevant to a given workspace's task:

Expand Down
29 changes: 1 addition & 28 deletions turborepo-tests/integration/tests/global_env.t
Expand Up @@ -37,18 +37,6 @@ Setup
Cached: 0 cached, 1 total
Time:\s*[\.0-9]+m?s (re)

# set env var with "THASH" and ensure cache miss
$ SOMETHING_THASH_YES=hi ${TURBO} run build --filter=util --output-logs=hash-only
[DEPRECATED] Using .*THASH.* to specify an environment variable for inclusion into the hash is deprecated. You specified: SOMETHING_THASH_YES.
\xe2\x80\xa2 Packages in scope: util (esc)
\xe2\x80\xa2 Running build in 1 packages (esc)
\xe2\x80\xa2 Remote caching disabled (esc)
util:build: cache miss, executing c3c2acfea2980d29

Tasks: 1 successful, 1 total
Cached: 0 cached, 1 total
Time:\s*[\.0-9]+m?s (re)

# set vercel analytics env var and ensure cache miss
$ VERCEL_ANALYTICS_ID=hi ${TURBO} run build --filter=util --output-logs=hash-only
\xe2\x80\xa2 Packages in scope: util (esc)
Expand All @@ -59,19 +47,4 @@ Setup
Tasks: 1 successful, 1 total
Cached: 0 cached, 1 total
Time:\s*[\.0-9]+m?s (re)

# THASH deprecation doesn't break --dry=json
$ SOMETHING_THASH_YES=hi ${TURBO} run build --filter=util --dry=json | jq -r '.tasks[0].environmentVariables.global[0]'
SOMETHING_THASH_YES=8f434346648f6b96df89dda901c5176b10a6d83961dd3c1ac88b59b2dc327aa4

# THASH deprecation doesn't break --graph
$ SOMETHING_THASH_YES=hi ${TURBO} run build --filter=util --graph

digraph {
\tcompound = "true" (esc)
\tnewrank = "true" (esc)
\tsubgraph "root" { (esc)
\t\t"[root] util#build" -> "[root] ___ROOT___" (esc)
\t} (esc)
}


1 comment on commit ebc002c

@vercel
Copy link

@vercel vercel bot commented on ebc002c May 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.