Skip to content

Commit

Permalink
feat(tui): Set TURBO_IS_TUI environment variable when using TUI. (#8897)
Browse files Browse the repository at this point in the history
### Description

Tools being used inside Turborepo tasks may want to know if they are
being ran in our multiplexer, similar to the way other terminal tooling
set environment variables that other programs can read (e.g.
`ZSH`,`TMUX`, `ALACRITTY_WINDOW_ID`).

In this PR, we're exposing a `TURBO_IS_TUI` variable for this purpose.

### Testing Instructions

Using the `with-shell-commands` example, I edited one of the `build`
scripts to echo the value.

With TUI:
```
TURBO_UI devturbo build --force --skip-infer

<omitted for brevity>

┌ pkg-b#build > cache bypass, force executing 33b029c222753bd2
│
│
│ > pkg-b@ prebuild /Users/anthonyshew/projects/debugs/with-shell-commands/packages/pkg-b
│ > echo "Executing pre-build step..."
│
│ Executing pre-build step...
│
│ > pkg-b@ build /Users/anthonyshew/projects/debugs/with-shell-commands/packages/pkg-b
│ > echo $TURBO_IS_TUI
│
│ true
└────>
```

Without TUI:
```
TURBO_UI=0 devturbo build --force --skip-infer --filter=pkg-b
turbo 2.0.11

• Packages in scope: pkg-b
• Running build in 1 packages
• Remote caching disabled

pkg-b:prebuild: > echo "Executing pre-build step..."
pkg-b:prebuild:
pkg-b:prebuild: Executing pre-build step...
pkg-b:build: cache bypass, force executing 33b029c222753bd2
pkg-b:build:
pkg-b:build:
pkg-b:build: > pkg-b@ prebuild /Users/anthonyshew/projects/debugs/with-shell-commands/packages/pkg-b
pkg-b:build: > echo "Executing pre-build step..."
pkg-b:build:
pkg-b:build: Executing pre-build step...
pkg-b:build:
pkg-b:build: > pkg-b@ build /Users/anthonyshew/projects/debugs/with-shell-commands/packages/pkg-b
pkg-b:build: > echo $TURBO_IS_TUI
pkg-b:build:
pkg-b:build:

```
  • Loading branch information
anthonyshew authored Aug 1, 2024
1 parent 5fc75a3 commit 3437a3c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
6 changes: 6 additions & 0 deletions crates/turborepo-lib/src/task_graph/visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -912,6 +912,12 @@ impl ExecContext {
cmd.envs(self.execution_env.iter());
// Always last to make sure it overwrites any user configured env var.
cmd.env("TURBO_HASH", &self.task_hash);

// Allow downstream tools to detect if the task is being ran with TUI
if self.experimental_ui {
cmd.env("TURBO_IS_TUI", "true");
}

// enable task access tracing

// set the trace file env var - frameworks that support this can use it to
Expand Down
7 changes: 4 additions & 3 deletions docs/repo-docs/reference/system-environment-variables.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ System environment variables are always overridden by flag values provided direc

Turborepo will make the following environment variables available within your tasks while they are executing:

| Variable | Description |
| ------------ | --------------------------------------- |
| `TURBO_HASH` | The hash of the currently running task. |
| Variable | Description |
| -------------- | -------------------------------------------------------------------------------------------- |
| `TURBO_HASH` | The hash of the currently running task. |
| `TURBO_IS_TUI` | When using the [TUI](/repo/docs/reference/configuration#ui), this variable is set to `true`. |
Empty file added grep
Empty file.

0 comments on commit 3437a3c

Please sign in to comment.