From 7375f53a37b231576356efb7f7ed98226de2c49e Mon Sep 17 00:00:00 2001 From: Shohei Maeda <11495867+smaeda-ks@users.noreply.github.com> Date: Fri, 28 Apr 2023 05:37:49 +0900 Subject: [PATCH] Move `TURBO_FORCE` config env var detection to Rust (#4590) Moving `TURBO_FORCE` env var detection logic to Rust, so we can properly throw an error message when an unsupported value is set (e.g., `TURBO_FORCE=1`). Co-authored-by: Mehul Kar --- cli/internal/run/run.go | 4 - crates/turborepo-lib/src/cli.rs | 6 +- turborepo-tests/integration/tests/bad_flag.t | 2 +- turborepo-tests/integration/tests/no_args.t | 2 +- turborepo-tests/integration/tests/run/force.t | 168 ++++++++++++++++++ .../integration/tests/turbo_help.t | 4 +- 6 files changed, 175 insertions(+), 11 deletions(-) create mode 100644 turborepo-tests/integration/tests/run/force.t diff --git a/cli/internal/run/run.go b/cli/internal/run/run.go index 8575e85f6f047..a2a6d7379973c 100644 --- a/cli/internal/run/run.go +++ b/cli/internal/run/run.go @@ -129,10 +129,6 @@ func optsFromArgs(args *turbostate.ParsedArgsFromRust) (*Opts, error) { } func configureRun(base *cmdutil.CmdBase, opts *Opts, signalWatcher *signals.Watcher) *run { - if os.Getenv("TURBO_FORCE") == "true" { - opts.runcacheOpts.SkipReads = true - } - if os.Getenv("TURBO_REMOTE_ONLY") == "true" { opts.cacheOpts.SkipFilesystem = true } diff --git a/crates/turborepo-lib/src/cli.rs b/crates/turborepo-lib/src/cli.rs index 5f9acdc14c2cc..667a7106a0a09 100644 --- a/crates/turborepo-lib/src/cli.rs +++ b/crates/turborepo-lib/src/cli.rs @@ -325,8 +325,8 @@ pub struct RunArgs { #[clap(short = 'F', long, action = ArgAction::Append)] pub filter: Vec, /// Ignore the existing cache (to force execution) - #[clap(long)] - pub force: bool, + #[clap(long, env = "TURBO_FORCE", default_missing_value = "true")] + pub force: Option>, /// Specify glob of global filesystem dependencies to be hashed. Useful /// for .env and files #[clap(long = "global-deps", action = ArgAction::Append)] @@ -876,7 +876,7 @@ mod test { Args { command: Some(Command::Run(Box::new(RunArgs { tasks: vec!["build".to_string()], - force: true, + force: Some(Some(true)), ..get_default_run_args() }))), ..Args::default() diff --git a/turborepo-tests/integration/tests/bad_flag.t b/turborepo-tests/integration/tests/bad_flag.t index c0a3fb945e24e..a976bfc599bbb 100644 --- a/turborepo-tests/integration/tests/bad_flag.t +++ b/turborepo-tests/integration/tests/bad_flag.t @@ -19,7 +19,7 @@ Bad flag with an implied run command should display run flags note: to pass '--bad-flag' as a value, use '-- --bad-flag' - Usage: turbo <--cache-dir |--cache-workers |--concurrency |--continue|--dry-run []|--single-package|--filter |--force|--global-deps |--graph []|--experimental-env-mode []|--ignore |--include-dependencies|--no-cache|--no-daemon|--no-deps|--output-logs |--only|--parallel|--pkg-inference-root |--profile |--remote-only|--scope |--since |--summarize []|--log-prefix |TASKS|PASS_THROUGH_ARGS|--experimental-space-id > + Usage: turbo <--cache-dir |--cache-workers |--concurrency |--continue|--dry-run []|--single-package|--filter |--force []|--global-deps |--graph []|--experimental-env-mode []|--ignore |--include-dependencies|--no-cache|--no-daemon|--no-deps|--output-logs |--only|--parallel|--pkg-inference-root |--profile |--remote-only|--scope |--since |--summarize []|--log-prefix |TASKS|PASS_THROUGH_ARGS|--experimental-space-id > For more information, try '--help'. diff --git a/turborepo-tests/integration/tests/no_args.t b/turborepo-tests/integration/tests/no_args.t index f4825484328a2..7f0a79ec95482 100644 --- a/turborepo-tests/integration/tests/no_args.t +++ b/turborepo-tests/integration/tests/no_args.t @@ -45,7 +45,7 @@ Make sure exit code is 2 when no args are passed --dry-run [] [possible values: text, json] --single-package Run turbo in single-package mode -F, --filter Use the given selector to specify package(s) to act as entry points. The syntax mirrors pnpm's syntax, and additional documentation and examples can be found in turbo's documentation https://turbo.build/repo/docs/reference/command-line-reference#--filter - --force Ignore the existing cache (to force execution) + --force [] Ignore the existing cache (to force execution) [env: TURBO_FORCE=] [possible values: true, false] --global-deps Specify glob of global filesystem dependencies to be hashed. Useful for .env and files --graph [] Generate a graph of the task execution and output to a file when a filename is specified (.svg, .png, .jpg, .pdf, .json, .html). Outputs dot graph to stdout when if no filename is provided --ignore Files to ignore when calculating changed files (i.e. --since). Supports globs diff --git a/turborepo-tests/integration/tests/run/force.t b/turborepo-tests/integration/tests/run/force.t new file mode 100644 index 0000000000000..4c76ebfae0582 --- /dev/null +++ b/turborepo-tests/integration/tests/run/force.t @@ -0,0 +1,168 @@ +Setup + $ . ${TESTDIR}/../../../helpers/setup.sh + $ . ${TESTDIR}/../_helpers/setup_monorepo.sh $(pwd) + +# Tests +| env var | flag | bypass? | +| ------- | ------- | ------- | +| true | missing | yes | +| true | true | yes | +| true | false | no | +| true | novalue | yes | + +| false | missing | no | +| false | true | yes | +| false | false | no | +| false | novalue | yes | + +| missing | missing | no | +| missing | true | yes | +| missing | false | no | +| missing | novalue | yes | + +baseline to generate cache + $ ${TURBO} run build --output-logs=hash-only --filter=my-app + \xe2\x80\xa2 Packages in scope: my-app (esc) + \xe2\x80\xa2 Running build in 1 packages (esc) + \xe2\x80\xa2 Remote caching disabled (esc) + my-app:build: cache miss, executing 2f192ed93e20f940 + + Tasks: 1 successful, 1 total + Cached: 0 cached, 1 total + Time:\s*[\.0-9]+m?s (re) + + +# env var=true, missing flag: cache bypass + $ TURBO_FORCE=true ${TURBO} run build --output-logs=hash-only --filter=my-app + \xe2\x80\xa2 Packages in scope: my-app (esc) + \xe2\x80\xa2 Running build in 1 packages (esc) + \xe2\x80\xa2 Remote caching disabled (esc) + my-app:build: cache bypass, force executing 2f192ed93e20f940 + + Tasks: 1 successful, 1 total + Cached: 0 cached, 1 total + Time:\s*[\.0-9]+m?s (re) + +# env var=true, --flag=true: cache bypass + $ TURBO_FORCE=true ${TURBO} run build --output-logs=hash-only --filter=my-app --force=true + \xe2\x80\xa2 Packages in scope: my-app (esc) + \xe2\x80\xa2 Running build in 1 packages (esc) + \xe2\x80\xa2 Remote caching disabled (esc) + my-app:build: cache bypass, force executing 2f192ed93e20f940 + + Tasks: 1 successful, 1 total + Cached: 0 cached, 1 total + Time:\s*[\.0-9]+m?s (re) + +# env var=true, --flag=false: cache hit + $ TURBO_FORCE=true ${TURBO} run build --output-logs=hash-only --filter=my-app --force=false + \xe2\x80\xa2 Packages in scope: my-app (esc) + \xe2\x80\xa2 Running build in 1 packages (esc) + \xe2\x80\xa2 Remote caching disabled (esc) + my-app:build: cache hit, suppressing output 2f192ed93e20f940 + + Tasks: 1 successful, 1 total + Cached: 1 cached, 1 total + Time:\s*[\.0-9]+m?s >>> FULL TURBO (re) + +# env var=true, --flag (no value): cache bypass + $ TURBO_FORCE=true ${TURBO} run build --output-logs=hash-only --filter=my-app --force + \xe2\x80\xa2 Packages in scope: my-app (esc) + \xe2\x80\xa2 Running build in 1 packages (esc) + \xe2\x80\xa2 Remote caching disabled (esc) + my-app:build: cache bypass, force executing 2f192ed93e20f940 + + Tasks: 1 successful, 1 total + Cached: 0 cached, 1 total + Time:\s*[\.0-9]+m?s (re) + + +# env var=false, missing flag, cache hit + $ TURBO_FORCE=false ${TURBO} run build --output-logs=hash-only --filter=my-app + \xe2\x80\xa2 Packages in scope: my-app (esc) + \xe2\x80\xa2 Running build in 1 packages (esc) + \xe2\x80\xa2 Remote caching disabled (esc) + my-app:build: cache hit, suppressing output 2f192ed93e20f940 + + Tasks: 1 successful, 1 total + Cached: 1 cached, 1 total + Time:\s*[\.0-9]+m?s >>> FULL TURBO (re) + +# env var=false, --flag=true: cache bypass + $ TURBO_FORCE=false ${TURBO} run build --output-logs=hash-only --filter=my-app --force=true + \xe2\x80\xa2 Packages in scope: my-app (esc) + \xe2\x80\xa2 Running build in 1 packages (esc) + \xe2\x80\xa2 Remote caching disabled (esc) + my-app:build: cache bypass, force executing 2f192ed93e20f940 + + Tasks: 1 successful, 1 total + Cached: 0 cached, 1 total + Time:\s*[\.0-9]+m?s (re) + +# env var=false, --flag=false: cache hit + $ TURBO_FORCE=false ${TURBO} run build --output-logs=hash-only --filter=my-app --force=false + \xe2\x80\xa2 Packages in scope: my-app (esc) + \xe2\x80\xa2 Running build in 1 packages (esc) + \xe2\x80\xa2 Remote caching disabled (esc) + my-app:build: cache hit, suppressing output 2f192ed93e20f940 + + Tasks: 1 successful, 1 total + Cached: 1 cached, 1 total + Time:\s*[\.0-9]+m?s >>> FULL TURBO (re) + +# env var=false, --flag (no value): cache bypass + $ TURBO_FORCE=false ${TURBO} run build --output-logs=hash-only --filter=my-app --force + \xe2\x80\xa2 Packages in scope: my-app (esc) + \xe2\x80\xa2 Running build in 1 packages (esc) + \xe2\x80\xa2 Remote caching disabled (esc) + my-app:build: cache bypass, force executing 2f192ed93e20f940 + + Tasks: 1 successful, 1 total + Cached: 0 cached, 1 total + Time:\s*[\.0-9]+m?s (re) + + +# missing env var, missing flag: cache hit + $ ${TURBO} run build --output-logs=hash-only --filter=my-app + \xe2\x80\xa2 Packages in scope: my-app (esc) + \xe2\x80\xa2 Running build in 1 packages (esc) + \xe2\x80\xa2 Remote caching disabled (esc) + my-app:build: cache hit, suppressing output 2f192ed93e20f940 + + Tasks: 1 successful, 1 total + Cached: 1 cached, 1 total + Time:\s*[\.0-9]+m?s >>> FULL TURBO (re) + +# missing env var, --flag=true: cache bypass + $ ${TURBO} run build --output-logs=hash-only --filter=my-app --force=true + \xe2\x80\xa2 Packages in scope: my-app (esc) + \xe2\x80\xa2 Running build in 1 packages (esc) + \xe2\x80\xa2 Remote caching disabled (esc) + my-app:build: cache bypass, force executing 2f192ed93e20f940 + + Tasks: 1 successful, 1 total + Cached: 0 cached, 1 total + Time:\s*[\.0-9]+m?s (re) + +# missing env var, --flag=false: cache hit + $ ${TURBO} run build --output-logs=hash-only --filter=my-app --force=false + \xe2\x80\xa2 Packages in scope: my-app (esc) + \xe2\x80\xa2 Running build in 1 packages (esc) + \xe2\x80\xa2 Remote caching disabled (esc) + my-app:build: cache hit, suppressing output 2f192ed93e20f940 + + Tasks: 1 successful, 1 total + Cached: 1 cached, 1 total + Time:\s*[\.0-9]+m?s >>> FULL TURBO (re) + +# missing env var, --flag (no value): cache bypass + $ ${TURBO} run build --output-logs=hash-only --filter=my-app --force + \xe2\x80\xa2 Packages in scope: my-app (esc) + \xe2\x80\xa2 Running build in 1 packages (esc) + \xe2\x80\xa2 Remote caching disabled (esc) + my-app:build: cache bypass, force executing 2f192ed93e20f940 + + Tasks: 1 successful, 1 total + Cached: 0 cached, 1 total + Time:\s*[\.0-9]+m?s (re) + diff --git a/turborepo-tests/integration/tests/turbo_help.t b/turborepo-tests/integration/tests/turbo_help.t index 297ecf483a760..02231744f49ce 100644 --- a/turborepo-tests/integration/tests/turbo_help.t +++ b/turborepo-tests/integration/tests/turbo_help.t @@ -45,7 +45,7 @@ Test help flag --dry-run [] [possible values: text, json] --single-package Run turbo in single-package mode -F, --filter Use the given selector to specify package(s) to act as entry points. The syntax mirrors pnpm's syntax, and additional documentation and examples can be found in turbo's documentation https://turbo.build/repo/docs/reference/command-line-reference#--filter - --force Ignore the existing cache (to force execution) + --force [] Ignore the existing cache (to force execution) [env: TURBO_FORCE=] [possible values: true, false] --global-deps Specify glob of global filesystem dependencies to be hashed. Useful for .env and files --graph [] Generate a graph of the task execution and output to a file when a filename is specified (.svg, .png, .jpg, .pdf, .json, .html). Outputs dot graph to stdout when if no filename is provided --ignore Files to ignore when calculating changed files (i.e. --since). Supports globs @@ -110,7 +110,7 @@ Test help flag --dry-run [] [possible values: text, json] --single-package Run turbo in single-package mode -F, --filter Use the given selector to specify package(s) to act as entry points. The syntax mirrors pnpm's syntax, and additional documentation and examples can be found in turbo's documentation https://turbo.build/repo/docs/reference/command-line-reference#--filter - --force Ignore the existing cache (to force execution) + --force [] Ignore the existing cache (to force execution) [env: TURBO_FORCE=] [possible values: true, false] --global-deps Specify glob of global filesystem dependencies to be hashed. Useful for .env and files --graph [] Generate a graph of the task execution and output to a file when a filename is specified (.svg, .png, .jpg, .pdf, .json, .html). Outputs dot graph to stdout when if no filename is provided --ignore Files to ignore when calculating changed files (i.e. --since). Supports globs