Skip to content

Commit

Permalink
Move TURBO_FORCE config env var detection to Rust (#4590)
Browse files Browse the repository at this point in the history
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 <mehul.kar@vercel.com>
  • Loading branch information
smaeda-ks and mehulkar committed Apr 27, 2023
1 parent 26df3ef commit 7375f53
Show file tree
Hide file tree
Showing 6 changed files with 175 additions and 11 deletions.
4 changes: 0 additions & 4 deletions cli/internal/run/run.go
Expand Up @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions crates/turborepo-lib/src/cli.rs
Expand Up @@ -325,8 +325,8 @@ pub struct RunArgs {
#[clap(short = 'F', long, action = ArgAction::Append)]
pub filter: Vec<String>,
/// Ignore the existing cache (to force execution)
#[clap(long)]
pub force: bool,
#[clap(long, env = "TURBO_FORCE", default_missing_value = "true")]
pub force: Option<Option<bool>>,
/// Specify glob of global filesystem dependencies to be hashed. Useful
/// for .env and files
#[clap(long = "global-deps", action = ArgAction::Append)]
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion turborepo-tests/integration/tests/bad_flag.t
Expand Up @@ -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_DIR>|--cache-workers <CACHE_WORKERS>|--concurrency <CONCURRENCY>|--continue|--dry-run [<DRY_RUN>]|--single-package|--filter <FILTER>|--force|--global-deps <GLOBAL_DEPS>|--graph [<GRAPH>]|--experimental-env-mode [<ENV_MODE>]|--ignore <IGNORE>|--include-dependencies|--no-cache|--no-daemon|--no-deps|--output-logs <OUTPUT_LOGS>|--only|--parallel|--pkg-inference-root <PKG_INFERENCE_ROOT>|--profile <PROFILE>|--remote-only|--scope <SCOPE>|--since <SINCE>|--summarize [<SUMMARIZE>]|--log-prefix <LOG_PREFIX>|TASKS|PASS_THROUGH_ARGS|--experimental-space-id <EXPERIMENTAL_SPACE_ID>>
Usage: turbo <--cache-dir <CACHE_DIR>|--cache-workers <CACHE_WORKERS>|--concurrency <CONCURRENCY>|--continue|--dry-run [<DRY_RUN>]|--single-package|--filter <FILTER>|--force [<FORCE>]|--global-deps <GLOBAL_DEPS>|--graph [<GRAPH>]|--experimental-env-mode [<ENV_MODE>]|--ignore <IGNORE>|--include-dependencies|--no-cache|--no-daemon|--no-deps|--output-logs <OUTPUT_LOGS>|--only|--parallel|--pkg-inference-root <PKG_INFERENCE_ROOT>|--profile <PROFILE>|--remote-only|--scope <SCOPE>|--since <SINCE>|--summarize [<SUMMARIZE>]|--log-prefix <LOG_PREFIX>|TASKS|PASS_THROUGH_ARGS|--experimental-space-id <EXPERIMENTAL_SPACE_ID>>

For more information, try '--help'.

Expand Down
2 changes: 1 addition & 1 deletion turborepo-tests/integration/tests/no_args.t
Expand Up @@ -45,7 +45,7 @@ Make sure exit code is 2 when no args are passed
--dry-run [<DRY_RUN>] [possible values: text, json]
--single-package Run turbo in single-package mode
-F, --filter <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 [<FORCE>] Ignore the existing cache (to force execution) [env: TURBO_FORCE=] [possible values: true, false]
--global-deps <GLOBAL_DEPS> Specify glob of global filesystem dependencies to be hashed. Useful for .env and files
--graph [<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 <IGNORE> Files to ignore when calculating changed files (i.e. --since). Supports globs
Expand Down
168 changes: 168 additions & 0 deletions 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)

4 changes: 2 additions & 2 deletions turborepo-tests/integration/tests/turbo_help.t
Expand Up @@ -45,7 +45,7 @@ Test help flag
--dry-run [<DRY_RUN>] [possible values: text, json]
--single-package Run turbo in single-package mode
-F, --filter <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 [<FORCE>] Ignore the existing cache (to force execution) [env: TURBO_FORCE=] [possible values: true, false]
--global-deps <GLOBAL_DEPS> Specify glob of global filesystem dependencies to be hashed. Useful for .env and files
--graph [<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 <IGNORE> Files to ignore when calculating changed files (i.e. --since). Supports globs
Expand Down Expand Up @@ -110,7 +110,7 @@ Test help flag
--dry-run [<DRY_RUN>] [possible values: text, json]
--single-package Run turbo in single-package mode
-F, --filter <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 [<FORCE>] Ignore the existing cache (to force execution) [env: TURBO_FORCE=] [possible values: true, false]
--global-deps <GLOBAL_DEPS> Specify glob of global filesystem dependencies to be hashed. Useful for .env and files
--graph [<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 <IGNORE> Files to ignore when calculating changed files (i.e. --since). Supports globs
Expand Down

0 comments on commit 7375f53

Please sign in to comment.