Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate THASH. #4526

Merged
merged 2 commits into from Apr 11, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 17 additions & 1 deletion cli/integration_tests/global_env.t
Expand Up @@ -39,6 +39,7 @@ Setup

# 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)
Expand All @@ -58,4 +59,19 @@ 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)
}

12 changes: 12 additions & 0 deletions cli/internal/run/global_hash.go
Expand Up @@ -3,8 +3,10 @@ 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 @@ -93,6 +95,8 @@ func calculateGlobalHash(
envVarPassthroughs []string,
envMode util.EnvMode,
logger hclog.Logger,
ui cli.Ui,
isStructuredOutput bool,
) (GlobalHashable, error) {
// Calculate env var dependencies
envVars := []string{}
Expand All @@ -103,6 +107,14 @@ func calculateGlobalHash(
return GlobalHashable{}, 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(), ", ")))
}
nathanhammond marked this conversation as resolved.
Show resolved Hide resolved

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

// Calculate global file dependencies
Expand Down
4 changes: 4 additions & 0 deletions cli/internal/run/run.go
Expand Up @@ -159,6 +159,8 @@ func (r *run) run(ctx gocontext.Context, targets []string) error {
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(r.base.RepoRoot, rootPackageJSON)
Expand Down Expand Up @@ -247,6 +249,8 @@ func (r *run) run(ctx gocontext.Context, targets []string) error {
turboJSON.GlobalPassthroughEnv,
r.opts.runOpts.EnvMode,
r.base.Logger,
r.base.UI,
isStructuredOutput,
)

if err != nil {
Expand Down