Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

chore(ci): use namesapce managed sccache (#5013)

teo26fd0a3430c1
diff --git a/.github/workflows/cargo_workspace_dependency_check.yml b/.github/workflows/cargo_workspace_dependency_check.yml
index 8f685630f0..5cde297521 100644
--- a/.github/workflows/cargo_workspace_dependency_check.yml
+++ b/.github/workflows/cargo_workspace_dependency_check.yml
@@ -31,9 +31,7 @@ jobs:
uses: namespacelabs/nscloud-cache-action@15799a6b54e5765f85b2aac25b3f0df43ed571c0
with:
cache: rust
- path: |-
- /home/runner/.cache/sccache
- /nix
+ path: /nix
continue-on-error: true
- name: Setup Nix
uses: './.github/actions/setup-nix'
@@ -42,10 +40,34 @@ jobs:
with:
cachix-auth-token: ${{ secrets.CACHIX_AUTH_TOKEN }}
dev-shell: 'true'
- - name: Point sccache at the cache volume
+ - name: Configure Namespace remote sccache
+ if: (github.event_name != 'pull_request' && github.event_name != 'pull_request_target') || github.event.pull_request.head.repo.full_name == github.repository
run: |-
- echo "SCCACHE_DIR=/home/runner/.cache/sccache" >> "$GITHUB_ENV"
- echo "SCCACHE_CACHE_SIZE=20G" >> "$GITHUB_ENV"
+ set -euo pipefail
+ env_file="$(mktemp "$RUNNER_TEMP/namespace-sccache.XXXXXX")"
+ trap 'rm -f "$env_file"' EXIT
+ if nsc cache sccache setup --cache_name sccache-ci > "$env_file"; then
+ # Register credential values as masked BEFORE exporting: GitHub only
+ # masks `secrets.*`, so without this SCCACHE_WEBDAV_TOKEN — a broad,
+ # ~24h Namespace workspace token (registry + cache write) — printed
+ # verbatim in every subsequent step's env dump. Masking is selective by
+ # key name: masking non-secrets like the endpoint URL or key prefix
+ # would redact those strings everywhere in the logs.
+ while IFS= read -r line; do
+ k="${line%%=*}"
+ v="${line#*=}"
+ [ -n "$v" ] && [ "$k" != "$line" ] || continue
+ case "$k" in
+ *TOKEN*|*SECRET*|*PASSWORD*) echo "::add-mask::$v" ;;
+ esac
+ done < "$env_file"
+ cat "$env_file" >> "$GITHUB_ENV"
+ # Force the next compiler invocation to start a server with the new remote
+ # backend even if a setup hook happened to launch one already.
+ sccache --stop-server >/dev/null 2>&1 || true
+ else
+ echo "::warning::Namespace remote sccache setup failed; using local cache fallback"
+ fi
- name: install tool
run: cargo install [email protected]
- name: check
@@ -65,9 +87,7 @@ jobs:
uses: namespacelabs/nscloud-cache-action@15799a6b54e5765f85b2aac25b3f0df43ed571c0
with:
cache: rust
- path: |-
- /home/runner/.cache/sccache
- /nix
+ path: /nix
continue-on-error: true
- name: Setup Nix
uses: './.github/actions/setup-nix'
@@ -76,10 +96,34 @@ jobs:
with:
cachix-auth-token: ${{ secrets.CACHIX_AUTH_TOKEN }}
dev-shell: 'true'
- - name: Point sccache at the cache volume
+ - name: Configure Namespace remote sccache
+ if: (github.event_name != 'pull_request' && github.event_name != 'pull_request_target') || github.event.pull_request.head.repo.full_name == github.repository
run: |-
- echo "SCCACHE_DIR=/home/runner/.cache/sccache" >> "$GITHUB_ENV"
- echo "SCCACHE_CACHE_SIZE=20G" >> "$GITHUB_ENV"
+ set -euo pipefail
+ env_file="$(mktemp "$RUNNER_TEMP/namespace-sccache.XXXXXX")"
+ trap 'rm -f "$env_file"' EXIT
+ if nsc cache sccache setup --cache_name sccache-ci > "$env_file"; then
+ # Register credential values as masked BEFORE exporting: GitHub only
+ # masks `secrets.*`, so without this SCCACHE_WEBDAV_TOKEN — a broad,
+ # ~24h Namespace workspace token (registry + cache write) — printed
+ # verbatim in every subsequent step's env dump. Masking is selective by
+ # key name: masking non-secrets like the endpoint URL or key prefix
+ # would redact those strings everywhere in the logs.
+ while IFS= read -r line; do
+ k="${line%%=*}"
+ v="${line#*=}"
+ [ -n "$v" ] && [ "$k" != "$line" ] || continue
+ case "$k" in
+ *TOKEN*|*SECRET*|*PASSWORD*) echo "::add-mask::$v" ;;
+ esac
+ done < "$env_file"
+ cat "$env_file" >> "$GITHUB_ENV"
+ # Force the next compiler invocation to start a server with the new remote
+ # backend even if a setup hook happened to launch one already.
+ sccache --stop-server >/dev/null 2>&1 || true
+ else
+ echo "::warning::Namespace remote sccache setup failed; using local cache fallback"
+ fi
- name: generated dependency artifacts are up to date
run: |
cargo run -p xtask --locked -- deps --check
diff --git a/.github/workflows/code_check_cloud_storage.yml b/.github/workflows/code_check_cloud_storage.yml
index 876164de91..9ae75857fb 100644
--- a/.github/workflows/code_check_cloud_storage.yml
+++ b/.github/workflows/code_check_cloud_storage.yml
@@ -137,9 +137,7 @@ jobs:
uses: namespacelabs/nscloud-cache-action@15799a6b54e5765f85b2aac25b3f0df43ed571c0
with:
cache: rust
- path: |-
- /home/runner/.cache/sccache
- /nix
+ path: /nix
continue-on-error: true
- name: Setup Nix
uses: './.github/actions/setup-nix'
@@ -148,10 +146,34 @@ jobs:
with:
cachix-auth-token: ${{ secrets.CACHIX_AUTH_TOKEN }}
dev-shell: 'true'
- - name: Point sccache at the cache volume
+ - name: Configure Namespace remote sccache
+ if: (github.event_name != 'pull_request' && github.event_name != 'pull_request_target') || github.event.pull_request.head.repo.full_name == github.repository
run: |-
- echo "SCCACHE_DIR=/home/runner/.cache/sccache" >> "$GITHUB_ENV"
- echo "SCCACHE_CACHE_SIZE=20G" >> "$GITHUB_ENV"
+ set -euo pipefail
+ env_file="$(mktemp "$RUNNER_TEMP/namespace-sccache.XXXXXX")"
+ trap 'rm -f "$env_file"' EXIT
+ if nsc cache sccache setup --cache_name sccache-ci > "$env_file"; then
+ # Register credential values as masked BEFORE exporting: GitHub only
+ # masks `secrets.*`, so without this SCCACHE_WEBDAV_TOKEN — a broad,
+ # ~24h Namespace workspace token (registry + cache write) — printed
+ # verbatim in every subsequent step's env dump. Masking is selective by
+ # key name: masking non-secrets like the endpoint URL or key prefix
+ # would redact those strings everywhere in the logs.
+ while IFS= read -r line; do
+ k="${line%%=*}"
+ v="${line#*=}"
+ [ -n "$v" ] && [ "$k" != "$line" ] || continue
+ case "$k" in
+ *TOKEN*|*SECRET*|*PASSWORD*) echo "::add-mask::$v" ;;
+ esac
+ done < "$env_file"
+ cat "$env_file" >> "$GITHUB_ENV"
+ # Force the next compiler invocation to start a server with the new remote
+ # backend even if a setup hook happened to launch one already.
+ sccache --stop-server >/dev/null 2>&1 || true
+ else
+ echo "::warning::Namespace remote sccache setup failed; using local cache fallback"
+ fi
- name: validate Doppler configs
if: needs.path-check.outputs.doppler_config_bins != ''
run: |
@@ -242,9 +264,7 @@ jobs:
uses: namespacelabs/nscloud-cache-action@15799a6b54e5765f85b2aac25b3f0df43ed571c0
with:
cache: rust
- path: |-
- /home/runner/.cache/sccache
- /nix
+ path: /nix
continue-on-error: true
- name: Setup Nix
uses: './.github/actions/setup-nix'
@@ -253,10 +273,34 @@ jobs:
with:
cachix-auth-token: ${{ secrets.CACHIX_AUTH_TOKEN }}
dev-shell: 'true'
- - name: Point sccache at the cache volume
+ - name: Configure Namespace remote sccache
+ if: (github.event_name != 'pull_request' && github.event_name != 'pull_request_target') || github.event.pull_request.head.repo.full_name == github.repository
run: |-
- echo "SCCACHE_DIR=/home/runner/.cache/sccache" >> "$GITHUB_ENV"
- echo "SCCACHE_CACHE_SIZE=20G" >> "$GITHUB_ENV"
+ set -euo pipefail
+ env_file="$(mktemp "$RUNNER_TEMP/namespace-sccache.XXXXXX")"
+ trap 'rm -f "$env_file"' EXIT
+ if nsc cache sccache setup --cache_name sccache-ci > "$env_file"; then
+ # Register credential values as masked BEFORE exporting: GitHub only
+ # masks `secrets.*`, so without this SCCACHE_WEBDAV_TOKEN — a broad,
+ # ~24h Namespace workspace token (registry + cache write) — printed
+ # verbatim in every subsequent step's env dump. Masking is selective by
+ # key name: masking non-secrets like the endpoint URL or key prefix
+ # would redact those strings everywhere in the logs.
+ while IFS= read -r line; do
+ k="${line%%=*}"
+ v="${line#*=}"
+ [ -n "$v" ] && [ "$k" != "$line" ] || continue
+ case "$k" in
+ *TOKEN*|*SECRET*|*PASSWORD*) echo "::add-mask::$v" ;;
+ esac
+ done < "$env_file"
+ cat "$env_file" >> "$GITHUB_ENV"
+ # Force the next compiler invocation to start a server with the new remote
+ # backend even if a setup hook happened to launch one already.
+ sccache --stop-server >/dev/null 2>&1 || true
+ else
+ echo "::warning::Namespace remote sccache setup failed; using local cache fallback"
+ fi
- name: configure postgres for concurrent tests
run: |
postgres_container="$(docker ps --format '{{.ID}} {{.Image}}' | awk '$2 == "pgvector/pgvector:pg16" { print $1; exit }')"
diff --git a/.github/workflows/preview-fly.yml b/.github/workflows/preview-fly.yml
index 1813de26c2..9323ad0e7d 100644
--- a/.github/workflows/preview-fly.yml
+++ b/.github/workflows/preview-fly.yml
@@ -47,9 +47,11 @@ jobs:
with:
cachix-auth-token: ${{ secrets.CACHIX_AUTH_TOKEN }}
- name: Configure Namespace remote sccache
+ if: (github.event_name != 'pull_request' && github.event_name != 'pull_request_target') || github.event.pull_request.head.repo.full_name == github.repository
run: |-
set -euo pipefail
- env_file="$RUNNER_TEMP/namespace-sccache.env"
+ env_file="$(mktemp "$RUNNER_TEMP/namespace-sccache.XXXXXX")"
+ trap 'rm -f "$env_file"' EXIT
if nsc cache sccache setup --cache_name fly-preview > "$env_file"; then
# Register credential values as masked BEFORE exporting: GitHub only
# masks `secrets.*`, so without this SCCACHE_WEBDAV_TOKEN — a broad,
diff --git a/.github/workflows/web-app-check-main.yml b/.github/workflows/web-app-check-main.yml
index d8c0f81cbd..739671f575 100644
--- a/.github/workflows/web-app-check-main.yml
+++ b/.github/workflows/web-app-check-main.yml
@@ -66,9 +66,7 @@ jobs:
uses: namespacelabs/nscloud-cache-action@15799a6b54e5765f85b2aac25b3f0df43ed571c0
with:
cache: bun,rust
- path: |-
- /home/runner/.cache/sccache
- /nix
+ path: /nix
continue-on-error: true
- name: Setup Nix
uses: './.github/actions/setup-nix'
@@ -76,10 +74,34 @@ jobs:
uses: './.github/actions/setup-reqs-web'
with:
cachix-auth-token: ${{ secrets.CACHIX_AUTH_TOKEN }}
- - name: Point sccache at the cache volume
+ - name: Configure Namespace remote sccache
+ if: ((github.event_name != 'pull_request' && github.event_name != 'pull_request_target') || github.event.pull_request.head.repo.full_name == github.repository) && (needs.path-check.outputs.api_changed == 'true')
run: |-
- echo "SCCACHE_DIR=/home/runner/.cache/sccache" >> "$GITHUB_ENV"
- echo "SCCACHE_CACHE_SIZE=20G" >> "$GITHUB_ENV"
+ set -euo pipefail
+ env_file="$(mktemp "$RUNNER_TEMP/namespace-sccache.XXXXXX")"
+ trap 'rm -f "$env_file"' EXIT
+ if nsc cache sccache setup --cache_name web-ci > "$env_file"; then
+ # Register credential values as masked BEFORE exporting: GitHub only
+ # masks `secrets.*`, so without this SCCACHE_WEBDAV_TOKEN — a broad,
+ # ~24h Namespace workspace token (registry + cache write) — printed
+ # verbatim in every subsequent step's env dump. Masking is selective by
+ # key name: masking non-secrets like the endpoint URL or key prefix
+ # would redact those strings everywhere in the logs.
+ while IFS= read -r line; do
+ k="${line%%=*}"
+ v="${line#*=}"
+ [ -n "$v" ] && [ "$k" != "$line" ] || continue
+ case "$k" in
+ *TOKEN*|*SECRET*|*PASSWORD*) echo "::add-mask::$v" ;;
+ esac
+ done < "$env_file"
+ cat "$env_file" >> "$GITHUB_ENV"
+ # Force the next compiler invocation to start a server with the new remote
+ # backend even if a setup hook happened to launch one already.
+ sccache --stop-server >/dev/null 2>&1 || true
+ else
+ echo "::warning::Namespace remote sccache setup failed; using local cache fallback"
+ fi
- name: Generate API Types
if: needs.path-check.outputs.api_changed == 'true'
run: bun run gen-api -- --check
diff --git a/tooling/xtask/crates/xtask_workflows/src/workflows/cargo_workspace_dependency_check.rs b/tooling/xtask/crates/xtask_workflows/src/workflows/cargo_workspace_dependency_check.rs
index cbd524bf3d..dfac65c4df 100644
--- a/tooling/xtask/crates/xtask_workflows/src/workflows/cargo_workspace_dependency_check.rs
+++ b/tooling/xtask/crates/xtask_workflows/src/workflows/cargo_workspace_dependency_check.rs
@@ -3,11 +3,11 @@
//! dep-closure map. Generated into `cargo_workspace_dependency_check.yml`
//! (replaces the hand-written `cargo-workspace-dependency-check.yml`).
//!
-//! Both jobs build Rust, so they run on the rust-ci profile with the shared
-//! `sccache-ci` volume and the Nix dev shell — this replaces the deprecated
-//! `actions-rs/toolchain` + hardcoded `rustup default 1.85` (which drifted
-//! from the workspace toolchain) and gives the `cargo install`/xtask builds
-//! warm caches instead of compiling cold on every run.
+//! Both jobs build Rust, so they run on the rust-ci profile with the Nix/Cargo
+//! cache volume and Namespace's shared `sccache-ci` remote cache. This replaces
+//! the deprecated `actions-rs/toolchain` + hardcoded `rustup default 1.85`
+//! (which drifted from the workspace toolchain) and gives the `cargo install`
+//! and xtask builds warm caches instead of compiling cold on every run.
use gh_workflow::{
Concurrency, Event, Expression, Job, PullRequest, PullRequestType, Run, Step, Use, Workflow,
@@ -57,7 +57,7 @@ fn rust_ci_job() -> Job {
.add_step(steps::mount_cache_volume())
.add_step(steps::setup_nix())
.add_step(steps::setup_dev_shell())
- .add_step(steps::pin_sccache_dir())
+ .add_step(steps::configure_namespace_sccache(vars::CI_SCCACHE_NAME))
}
fn dependency_check() -> Job {
@@ -88,7 +88,7 @@ fn checkout() -> Step<Use> {
/// `cargo install` skips the build when the same version is already present
/// in `~/.cargo/bin` (persisted on the cache volume); cold installs compile
-/// through the volume-backed sccache.
+/// through Namespace's remote sccache.
fn install_checker() -> Step<Run> {
Step::new("install tool").run("cargo install [email protected]")
}
diff --git a/tooling/xtask/crates/xtask_workflows/src/workflows/code_check_cloud_storage.rs b/tooling/xtask/crates/xtask_workflows/src/workflows/code_check_cloud_storage.rs
index 6d13cc5799..4a55b808c7 100644
--- a/tooling/xtask/crates/xtask_workflows/src/workflows/code_check_cloud_storage.rs
+++ b/tooling/xtask/crates/xtask_workflows/src/workflows/code_check_cloud_storage.rs
@@ -2,8 +2,9 @@
//! workspace on pull requests. Generated into `code-check-cloud-storage.yml`.
//!
//! Ported from the hand-written workflow, with two infra changes: the runners
-//! moved to Namespace profiles, and sccache moved off the S3 bucket onto a
-//! persisted Namespace cache volume (so there are no AWS credentials anywhere).
+//! moved to Namespace profiles, and compiled objects moved off the S3/local
+//! volume backends onto Namespace's official remote sccache (so there are no
+//! AWS credentials anywhere).
use gh_workflow::{
Container, Env, Event, Expression, Job, Port, PullRequest, PullRequestType, Run, Step, Workflow,
@@ -69,7 +70,7 @@ fn check() -> Job {
.add_step(steps::mount_cache_volume())
.add_step(steps::setup_nix())
.add_step(steps::setup_dev_shell())
- .add_step(steps::pin_sccache_dir())
+ .add_step(steps::configure_namespace_sccache(vars::CI_SCCACHE_NAME))
.add_step(validate_doppler_configs())
.add_step(cargo_fmt())
.add_step(cargo_clippy())
@@ -92,7 +93,7 @@ fn test() -> Job {
.add_step(steps::mount_cache_volume())
.add_step(steps::setup_nix())
.add_step(steps::setup_dev_shell())
- .add_step(steps::pin_sccache_dir())
+ .add_step(steps::configure_namespace_sccache(vars::CI_SCCACHE_NAME))
.add_step(configure_postgres())
.add_step(prepare_tests())
.add_step(run_tests())
@@ -186,9 +187,9 @@ fn compute_nextest_filter() -> Step<Run> {
.shell("bash")
}
-/// Build and run the Doppler config binaries affected by this PR. (sccache is
-/// local now, so this no longer needs AWS credentials — only the assertion that
-/// `RUSTC_WRAPPER` is wired stays.)
+/// Build and run the Doppler config binaries affected by this PR. Namespace's
+/// remote sccache needs no AWS credentials; only the assertion that
+/// `RUSTC_WRAPPER` is wired stays.
fn validate_doppler_configs() -> Step<Run> {
Step::new("validate Doppler configs")
.run(include_str!("scripts/validate_doppler_configs.sh"))
@@ -207,7 +208,7 @@ fn cargo_fmt() -> Step<Run> {
Step::new("fmt").run("cargo fmt --check")
}
-/// `cargo clippy` (no AWS creds — sccache is local).
+/// `cargo clippy` (no AWS credentials; sccache uses Namespace's remote cache).
fn cargo_clippy() -> Step<Run> {
Step::new("clippy").run(indoc::indoc! {r#"
cargo clippy --workspace --all-features \
@@ -259,7 +260,7 @@ fn prepare_tests() -> Step<Run> {
Step::new("prepare tests").run("just setup_test_envs && just initialize_dbs")
}
-/// Run the test suite (no AWS creds — sccache is local).
+/// Run the test suite (no AWS credentials; sccache uses Namespace's remote cache).
fn run_tests() -> Step<Run> {
Step::new("run tests").run(include_str!("scripts/run_tests.sh"))
}
diff --git a/tooling/xtask/crates/xtask_workflows/src/workflows/runners.rs b/tooling/xtask/crates/xtask_workflows/src/workflows/runners.rs
index aa65b108b7..eae6f06bd1 100644
--- a/tooling/xtask/crates/xtask_workflows/src/workflows/runners.rs
+++ b/tooling/xtask/crates/xtask_workflows/src/workflows/runners.rs
@@ -3,7 +3,8 @@
//! We run on Namespace (namespace.so) hosted runners, selected by the dashboard
//! *profile* name — the same convention the deploy workflows already use. Each
//! profile's persisted cache volume is configured in the Namespace dashboard;
-//! that volume backs the sccache + cargo caches (see
+//! that volume backs Cargo/Nix state while compiled objects use Namespace's
+//! official remote sccache (see
//! [`crate::workflows::steps::mount_cache_volume`]).
use std::fmt;
@@ -22,7 +23,7 @@ pub enum Runner {
Mid,
/// Dedicated CI profile for the heavy compile + test jobs. Has its own
/// cache volume, isolated from the deploy profiles so deploy's churn can't
- /// evict the CI sccache/cargo caches.
+ /// evict the CI Cargo/Nix caches.
RustCi,
}
@@ -45,9 +46,8 @@ impl Runner {
/// branch can only inherit the *default* branch's cache, so any branch whose
/// workflow never runs on `main` starts cold every time. Pinning a fixed tag
/// makes every branch read/write the *same* volume — one global cache, like
- /// the old shared S3 sccache bucket. sccache entries are content-addressed,
- /// so concurrent writers never corrupt each other; the worst case is an
- /// occasional miss that simply recompiles.
+ /// the old globally shared cache behavior. Cache-volume writes are managed
+ /// by Namespace; compiled objects use the separately named remote sccache.
pub fn with_cache_tag(self, tag: &str) -> String {
format!("{self};overrides.cache-tag={tag}")
}
diff --git a/tooling/xtask/crates/xtask_workflows/src/workflows/steps.rs b/tooling/xtask/crates/xtask_workflows/src/workflows/steps.rs
index a684a75216..e9768a0b06 100644
--- a/tooling/xtask/crates/xtask_workflows/src/workflows/steps.rs
+++ b/tooling/xtask/crates/xtask_workflows/src/workflows/steps.rs
@@ -9,6 +9,18 @@ use xtask_paths::{RepoDir, RuntimePath};
use crate::workflows::vars;
+#[cfg(test)]
+mod test;
+
+/// Namespace's sccache setup mints a short-lived workspace credential. GitHub
+/// withholds repository secrets from fork PRs, but this runner-minted token is
+/// not a `secrets.*` value, so enforce the equivalent trust boundary here.
+const TRUSTED_NAMESPACE_SCCACHE_CONTEXT: &str = concat!(
+ "(github.event_name != 'pull_request' && ",
+ "github.event_name != 'pull_request_target') || ",
+ "github.event.pull_request.head.repo.full_name == github.repository"
+);
+
/// `.map` / `.when` combinators for fluent conditional composition
/// ("push ifs up"): centralize branching in the builder chain instead of
/// building values imperatively.
@@ -76,8 +88,9 @@ pub fn setup_nix() -> Step<Use> {
}
/// Enter the repo's Nix dev shell (toolchain, mold, just, the sccache binary,
-/// and `RUSTC_WRAPPER=sccache`). We pass NO `sccache-bucket`, so sccache runs in
-/// local-disk mode instead of talking to S3. Requires [`setup_nix`] first.
+/// and `RUSTC_WRAPPER=sccache`). We pass no S3 bucket; jobs that compile Rust
+/// follow this with [`configure_namespace_sccache`] to use Namespace's official
+/// remote cache. Requires [`setup_nix`] first.
pub fn setup_dev_shell() -> Step<Use> {
uses_local(
"Setup Nix dev shell",
@@ -88,10 +101,10 @@ pub fn setup_dev_shell() -> Step<Use> {
}
/// Mount the Namespace profile's persisted cache volume: `cache: rust` persists
-/// the cargo registry/git, and `path:` persists the sccache dir plus the Nix
-/// store. `continue-on-error` because the cache is a pure optimization — a
-/// missing/failed volume just means a cold build, never a wrong one (mirrors the
-/// deploy workflows' `/nix` mounts).
+/// the cargo registry/git, and `path:` persists the Nix store. Compiled objects
+/// deliberately use Namespace's official remote sccache instead of this volume.
+/// `continue-on-error` because the volume is a pure optimization — a failure
+/// just means cold Cargo/Nix state, never a wrong build.
pub fn mount_cache_volume() -> Step<Use> {
Step::new("Mount Namespace cache volume")
.uses(
@@ -100,7 +113,7 @@ pub fn mount_cache_volume() -> Step<Use> {
"15799a6b54e5765f85b2aac25b3f0df43ed571c0", // v1.4.3
)
.add_with(("cache", "rust"))
- .add_with(("path", format!("{}\n/nix", vars::SCCACHE_VOLUME_DIR)))
+ .add_with(("path", xtask_paths::runtime_path!("/nix").as_str()))
.continue_on_error(true)
}
@@ -130,14 +143,30 @@ pub fn mount_cache_volume_with_cargo_target() -> Step<Use> {
.continue_on_error(true)
}
-/// Configure Namespace's artifact-backed remote sccache. `setup-reqs-web`
-/// already installs sccache and exports `RUSTC_WRAPPER=sccache`; this replaces
-/// the local-disk backend with short-lived WebDAV credentials that work across
-/// runners and cache-volume misses.
+/// Configure Namespace's official artifact-backed remote sccache. Call this
+/// after [`setup_dev_shell`] or [`setup_reqs_web`], which install sccache and
+/// export `RUSTC_WRAPPER=sccache`. The short-lived WebDAV credentials work
+/// across runners and cache-volume misses. Fork PRs skip this step and retain
+/// the setup action's local fallback so untrusted code never receives the
+/// runner-minted Namespace workspace token.
pub fn configure_namespace_sccache(cache_name: &str) -> Step<Run> {
+ namespace_sccache_step(cache_name)
+ .if_condition(Expression::new(TRUSTED_NAMESPACE_SCCACHE_CONTEXT))
+}
+
+/// Configure Namespace's remote sccache in a trusted context when
+/// `additional_condition` is also true.
+pub fn configure_namespace_sccache_when(cache_name: &str, additional_condition: &str) -> Step<Run> {
+ namespace_sccache_step(cache_name).if_condition(Expression::new(format!(
+ "({TRUSTED_NAMESPACE_SCCACHE_CONTEXT}) && ({additional_condition})"
+ )))
+}
+
+fn namespace_sccache_step(cache_name: &str) -> Step<Run> {
Step::new("Configure Namespace remote sccache").run(format!(
r#"set -euo pipefail
-env_file="$RUNNER_TEMP/namespace-sccache.env"
+env_file="$(mktemp "$RUNNER_TEMP/namespace-sccache.XXXXXX")"
+trap 'rm -f "$env_file"' EXIT
if nsc cache sccache setup --cache_name {cache_name} > "$env_file"; then
# Register credential values as masked BEFORE exporting: GitHub only
# masks `secrets.*`, so without this SCCACHE_WEBDAV_TOKEN — a broad,
@@ -163,21 +192,11 @@ fi"#
))
}
-/// Repoint sccache at the persisted volume. Runs AFTER `setup-cachix`; this keeps
-/// the compiled artifact cache directory aligned with the Namespace mounted path.
-pub fn pin_sccache_dir() -> Step<Run> {
- Step::new("Point sccache at the cache volume").run(format!(
- "echo \"SCCACHE_DIR={dir}\" >> \"$GITHUB_ENV\"\n\
- echo \"SCCACHE_CACHE_SIZE={size}\" >> \"$GITHUB_ENV\"",
- dir = vars::SCCACHE_VOLUME_DIR,
- size = vars::SCCACHE_CACHE_SIZE,
- ))
-}
-
/// Mount the web-app cache volume: bun's install cache plus the Nix store
-/// (dev shell closure). `with_rust` additionally persists the cargo
-/// registry/git and the sccache dir for the `gen-api` OpenAPI-binary build.
-/// `continue-on-error` for the same reason as [`mount_cache_volume`].
+/// (dev shell closure). `with_rust` additionally persists the cargo registry
+/// and git state used by the `gen-api` OpenAPI-binary build; its compiled
+/// objects live in Namespace's official remote sccache. `continue-on-error`
+/// for the same reason as [`mount_cache_volume`].
pub fn mount_web_cache_volume(with_rust: bool) -> Step<Use> {
Step::new("Mount Namespace cache volume")
.uses(
@@ -186,19 +205,13 @@ pub fn mount_web_cache_volume(with_rust: bool) -> Step<Use> {
"15799a6b54e5765f85b2aac25b3f0df43ed571c0", // v1.4.3
)
.add_with(("cache", if with_rust { "bun,rust" } else { "bun" }))
- .map(|step| {
- if with_rust {
- step.add_with(("path", format!("{}\n/nix", vars::SCCACHE_VOLUME_DIR)))
- } else {
- step.add_with(("path", xtask_paths::runtime_path!("/nix").as_str()))
- }
- })
+ .add_with(("path", xtask_paths::runtime_path!("/nix").as_str()))
.continue_on_error(true)
}
/// The web-app composite: Nix dev shell (bun, biome, just) + `bun install`.
-/// We pass NO `sccache-bucket`, so the gen-api build's sccache stays on the
-/// cache volume. Requires [`setup_nix`] first.
+/// We pass no S3 bucket; jobs that run `gen-api` follow this with
+/// [`configure_namespace_sccache`]. Requires [`setup_nix`] first.
pub fn setup_reqs_web(name: &str, playwright: bool) -> Step<Use> {
uses_local(
name,
diff --git a/tooling/xtask/crates/xtask_workflows/src/workflows/steps/test.rs b/tooling/xtask/crates/xtask_workflows/src/workflows/steps/test.rs
new file mode 100644
index 0000000000..a78552abfe
--- /dev/null
+++ b/tooling/xtask/crates/xtask_workflows/src/workflows/steps/test.rs
@@ -0,0 +1,50 @@
+use super::*;
+
+#[test]
+fn namespace_sccache_masks_credentials_before_exporting_them() {
+ let step = configure_namespace_sccache("test-cache");
+ let condition = step
+ .value
+ .if_condition
+ .as_ref()
+ .expect("Namespace sccache credentials should be limited to trusted refs");
+ let run = step
+ .value
+ .run
+ .expect("Namespace sccache setup should be a run step");
+
+ let mask = run
+ .find("echo \"::add-mask::$v\"")
+ .expect("credential values should be registered with GitHub's log masker");
+ let export = run
+ .find("cat \"$env_file\" >> \"$GITHUB_ENV\"")
+ .expect("the generated sccache environment should be exported");
+
+ assert!(mask < export, "credentials must be masked before export");
+ assert!(run.contains("*TOKEN*|*SECRET*|*PASSWORD*"));
+ assert!(run.contains("mktemp \"$RUNNER_TEMP/namespace-sccache.XXXXXX\""));
+ assert!(run.contains("trap 'rm -f \"$env_file\"' EXIT"));
+ assert!(run.contains("nsc cache sccache setup --cache_name test-cache"));
+ assert!(
+ condition
+ .0
+ .contains("github.event.pull_request.head.repo.full_name")
+ );
+ assert!(condition.0.contains("github.repository"));
+}
+
+#[test]
+fn namespace_sccache_combines_job_specific_and_trust_conditions() {
+ let step = configure_namespace_sccache_when("test-cache", "steps.filter.outputs.hit == 'true'");
+ let condition = step
+ .value
+ .if_condition
+ .expect("conditional Namespace sccache setup should have an if expression");
+
+ assert!(
+ condition
+ .0
+ .contains("github.event.pull_request.head.repo.full_name")
+ );
+ assert!(condition.0.contains("steps.filter.outputs.hit == 'true'"));
+}
diff --git a/tooling/xtask/crates/xtask_workflows/src/workflows/vars.rs b/tooling/xtask/crates/xtask_workflows/src/workflows/vars.rs
index bbf55745c9..8b0ee5a37f 100644
--- a/tooling/xtask/crates/xtask_workflows/src/workflows/vars.rs
+++ b/tooling/xtask/crates/xtask_workflows/src/workflows/vars.rs
@@ -1,5 +1,5 @@
//! Shared workflow environment: secrets, the repo-wide env block, concurrency,
-//! and the sccache-on-volume settings. This is the "environment" file.
+//! and Namespace cache names. This is the "environment" file.
use gh_workflow::{Concurrency, Expression, Workflow};
@@ -37,11 +37,17 @@ pub const CLOUDFLARE_ACCOUNT_ID: &str = "${{ vars.CLOUDFLARE_ACCOUNT_ID }}";
/// smaller.
pub const NEXTEST_TEST_THREADS: u32 = 32;
-/// Explicit Namespace cache tag for the heavy compile jobs (check + test). A
-/// fixed tag (instead of the default per-branch scoping) makes the cache volume
-/// global across all branches — see [`crate::workflows::runners::Runner::with_cache_tag`].
+/// Explicit Namespace cache-volume tag for the heavy compile jobs (check +
+/// test). A fixed tag (instead of the default per-branch scoping) makes the
+/// Cargo/Nix volume global across all branches — see
+/// [`crate::workflows::runners::Runner::with_cache_tag`]. The legacy tag name is
+/// retained so the existing warm volume is not invalidated.
pub const CI_CACHE_TAG: &str = "sccache-ci";
+/// Namespace remote sccache shared by the cloud-storage compile/test jobs and
+/// the workspace dependency checks.
+pub const CI_SCCACHE_NAME: &str = "sccache-ci";
+
/// Namespace cache tag for the Fly preview deploy job. Its own pool, NOT
/// [`CI_CACHE_TAG`]: sharing looked economical but was measured cold both ways
/// (run 28968155599: sccache 2.65% hits, cargo target dir absent). The
@@ -66,9 +72,10 @@ pub const PREVIEW_SCCACHE_NAME: &str = "fly-preview";
/// `linux-mid` volume.
pub const WEB_CI_CACHE_TAG: &str = "web-ci";
-/// Directory sccache uses for its local-disk cache. Lives on the Namespace cache
-/// volume so it persists across runs — this is what replaces the S3 bucket.
-pub const SCCACHE_VOLUME_DIR: &str = "/home/runner/.cache/sccache";
+/// Namespace remote sccache used when the web checks compile Rust API schema
+/// generators. Kept separate from [`CI_SCCACHE_NAME`] because these jobs have
+/// a different workload and runner profile.
+pub const WEB_SCCACHE_NAME: &str = "web-ci";
/// Init-snapshot store for the preview job (`MACRO_STACK_SNAPSHOT_DIR`). Lives
/// on the preview cache volume for the zero-copy fast path; the workflow also
@@ -76,10 +83,6 @@ pub const SCCACHE_VOLUME_DIR: &str = "/home/runner/.cache/sccache";
/// cache-volume miss does not force another infra bake.
pub const PREVIEW_SNAPSHOT_VOLUME_DIR: &str = "/home/runner/.cache/macro-preview-snapshots";
-/// Max on-disk size for the sccache cache. Larger than the setup default since
-/// the persisted volume can hold a full-workspace cache.
-pub const SCCACHE_CACHE_SIZE: &str = "20G";
-
/// The repo-wide env block (mirrors the original top-level `env:`). Defaults the
/// linker to `lld`; the heavy jobs override `RUSTFLAGS` to use `mold`.
pub fn with_global_env(workflow: Workflow) -> Workflow {
diff --git a/tooling/xtask/crates/xtask_workflows/src/workflows/web_app_check_main.rs b/tooling/xtask/crates/xtask_workflows/src/workflows/web_app_check_main.rs
index f2e025f73c..5bd563029b 100644
--- a/tooling/xtask/crates/xtask_workflows/src/workflows/web_app_check_main.rs
+++ b/tooling/xtask/crates/xtask_workflows/src/workflows/web_app_check_main.rs
@@ -12,8 +12,9 @@ use crate::workflows::{
};
/// All the real web jobs share one mid-size Namespace profile with a dedicated
-/// cache tag, so the frontend caches (Nix store, bun cache, gen-api sccache)
-/// live on their own volume — see [`vars::WEB_CI_CACHE_TAG`].
+/// cache tag, so the frontend's Nix/Bun/Cargo state lives on its own volume.
+/// The `gen-api` Rust objects use [`vars::WEB_SCCACHE_NAME`] through Namespace's
+/// official remote sccache.
fn web_runner() -> String {
runners::Runner::Mid.with_cache_tag(vars::WEB_CI_CACHE_TAG)
}
@@ -66,7 +67,10 @@ fn typescript() -> Job {
.add_step(steps::mount_web_cache_volume(true))
.add_step(steps::setup_nix())
.add_step(steps::setup_reqs_web("Setup Prereqs", false))
- .add_step(steps::pin_sccache_dir())
+ .add_step(steps::configure_namespace_sccache_when(
+ vars::WEB_SCCACHE_NAME,
+ "needs.path-check.outputs.api_changed == 'true'",
+ ))
.add_step(generate_api_types())
.add_step(show_sccache_stats())
.add_step(check_types())