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

Move TURBO_FORCE config env var detection to Rust #4590

Merged
merged 13 commits into from Apr 27, 2023
9 changes: 0 additions & 9 deletions cli/internal/run/run.go
Expand Up @@ -3,7 +3,6 @@ package run
import (
gocontext "context"
"fmt"
"os"
"sort"
"sync"
"time"
Expand Down Expand Up @@ -129,14 +128,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
}

smaeda-ks marked this conversation as resolved.
Show resolved Hide resolved
processes := process.NewManager(base.Logger.Named("processes"))
signalWatcher.AddOnClose(processes.Close)
return &run{
Expand Down
12 changes: 6 additions & 6 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 @@ -379,8 +379,8 @@ pub struct RunArgs {
pub profile: Option<String>,
/// Ignore the local filesystem cache for all tasks. Only
/// allow reading and caching artifacts using the remote cache.
#[clap(long)]
pub remote_only: bool,
#[clap(long, env = "TURBO_REMOTE_ONLY", default_missing_value = "true")]
pub remote_only: Option<Option<bool>>,
/// Specify package(s) to act as entry points for task execution.
/// Supports globs.
#[clap(long)]
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 Expand Up @@ -1087,7 +1087,7 @@ mod test {
Args {
command: Some(Command::Run(Box::new(RunArgs {
tasks: vec!["build".to_string()],
remote_only: true,
remote_only: 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 [<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
4 changes: 2 additions & 2 deletions 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)
--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 All @@ -56,7 +56,7 @@ Make sure exit code is 2 when no args are passed
--output-logs <OUTPUT_LOGS> Set type of process output logging. Use "full" to show all output. Use "hash-only" to show only turbo-computed task hashes. Use "new-only" to show only new output with only hashes for cached tasks. Use "none" to hide process output. (default full) [possible values: full, none, hash-only, new-only, errors-only]
--parallel Execute all tasks in parallel
--profile <PROFILE> File to write turbo's performance profile output into. You can load the file up in chrome://tracing to see which parts of your build were slow
--remote-only Ignore the local filesystem cache for all tasks. Only allow reading and caching artifacts using the remote cache
--remote-only [<REMOTE_ONLY>] Ignore the local filesystem cache for all tasks. Only allow reading and caching artifacts using the remote cache
--scope <SCOPE> Specify package(s) to act as entry points for task execution. Supports globs
--since <SINCE> Limit/Set scope to changed packages since a mergebase. This uses the git diff ${target_branch}... mechanism to identify which packages have changed
--summarize [<SUMMARIZE>] Generate a summary of the turbo run [env: TURBO_RUN_SUMMARY=] [possible values: true, false]
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)

8 changes: 4 additions & 4 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)
--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 All @@ -56,7 +56,7 @@ Test help flag
--output-logs <OUTPUT_LOGS> Set type of process output logging. Use "full" to show all output. Use "hash-only" to show only turbo-computed task hashes. Use "new-only" to show only new output with only hashes for cached tasks. Use "none" to hide process output. (default full) [possible values: full, none, hash-only, new-only, errors-only]
--parallel Execute all tasks in parallel
--profile <PROFILE> File to write turbo's performance profile output into. You can load the file up in chrome://tracing to see which parts of your build were slow
--remote-only Ignore the local filesystem cache for all tasks. Only allow reading and caching artifacts using the remote cache
--remote-only [<REMOTE_ONLY>] Ignore the local filesystem cache for all tasks. Only allow reading and caching artifacts using the remote cache
--scope <SCOPE> Specify package(s) to act as entry points for task execution. Supports globs
--since <SINCE> Limit/Set scope to changed packages since a mergebase. This uses the git diff ${target_branch}... mechanism to identify which packages have changed
--summarize [<SUMMARIZE>] Generate a summary of the turbo run [env: TURBO_RUN_SUMMARY=] [possible values: true, false]
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)
--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 All @@ -121,7 +121,7 @@ Test help flag
--output-logs <OUTPUT_LOGS> Set type of process output logging. Use "full" to show all output. Use "hash-only" to show only turbo-computed task hashes. Use "new-only" to show only new output with only hashes for cached tasks. Use "none" to hide process output. (default full) [possible values: full, none, hash-only, new-only, errors-only]
--parallel Execute all tasks in parallel
--profile <PROFILE> File to write turbo's performance profile output into. You can load the file up in chrome://tracing to see which parts of your build were slow
--remote-only Ignore the local filesystem cache for all tasks. Only allow reading and caching artifacts using the remote cache
--remote-only [<REMOTE_ONLY>] Ignore the local filesystem cache for all tasks. Only allow reading and caching artifacts using the remote cache
--scope <SCOPE> Specify package(s) to act as entry points for task execution. Supports globs
--since <SINCE> Limit/Set scope to changed packages since a mergebase. This uses the git diff ${target_branch}... mechanism to identify which packages have changed
--summarize [<SUMMARIZE>] Generate a summary of the turbo run [env: TURBO_RUN_SUMMARY=] [possible values: true, false]
Expand Down