Fix more sccache problems on windows runners for external PRs (#48980)

Conrad Irwin created

Closes #ISSUE

- [ ] Tests or screenshots needed?
- [ ] Code Reviewed
- [ ] Manual QA

Release Notes:

- N/A

Change summary

.github/workflows/release.yml              | 4 ++--
.github/workflows/release_nightly.yml      | 4 ++--
.github/workflows/run_tests.yml            | 4 ++--
tooling/xtask/src/tasks/workflows/steps.rs | 7 +++++--
4 files changed, 11 insertions(+), 8 deletions(-)

Detailed changes

.github/workflows/release.yml 🔗

@@ -159,7 +159,7 @@ jobs:
       run: cargo nextest run --workspace --no-fail-fast
       shell: pwsh
     - name: steps::show_sccache_stats
-      run: '& $env:RUSTC_WRAPPER --show-stats; exit 0'
+      run: if ($env:RUSTC_WRAPPER) { & $env:RUSTC_WRAPPER --show-stats }; exit 0
       shell: pwsh
     - name: steps::cleanup_cargo_config
       if: always()
@@ -278,7 +278,7 @@ jobs:
       run: ./script/clippy.ps1
       shell: pwsh
     - name: steps::show_sccache_stats
-      run: '& $env:RUSTC_WRAPPER --show-stats; exit 0'
+      run: if ($env:RUSTC_WRAPPER) { & $env:RUSTC_WRAPPER --show-stats }; exit 0
       shell: pwsh
     timeout-minutes: 60
   check_scripts:

.github/workflows/release_nightly.yml 🔗

@@ -67,7 +67,7 @@ jobs:
       run: cargo nextest run --workspace --no-fail-fast
       shell: pwsh
     - name: steps::show_sccache_stats
-      run: '& $env:RUSTC_WRAPPER --show-stats; exit 0'
+      run: if ($env:RUSTC_WRAPPER) { & $env:RUSTC_WRAPPER --show-stats }; exit 0
       shell: pwsh
     - name: steps::cleanup_cargo_config
       if: always()
@@ -110,7 +110,7 @@ jobs:
       run: ./script/clippy.ps1
       shell: pwsh
     - name: steps::show_sccache_stats
-      run: '& $env:RUSTC_WRAPPER --show-stats; exit 0'
+      run: if ($env:RUSTC_WRAPPER) { & $env:RUSTC_WRAPPER --show-stats }; exit 0
       shell: pwsh
     timeout-minutes: 60
   bundle_linux_aarch64:

.github/workflows/run_tests.yml 🔗

@@ -176,7 +176,7 @@ jobs:
       run: ./script/clippy.ps1
       shell: pwsh
     - name: steps::show_sccache_stats
-      run: '& $env:RUSTC_WRAPPER --show-stats; exit 0'
+      run: if ($env:RUSTC_WRAPPER) { & $env:RUSTC_WRAPPER --show-stats }; exit 0
       shell: pwsh
     timeout-minutes: 60
   clippy_linux:
@@ -303,7 +303,7 @@ jobs:
       run: cargo nextest run --workspace --no-fail-fast${{ needs.orchestrate.outputs.changed_packages && format(' -E "{0}"', needs.orchestrate.outputs.changed_packages) || '' }}
       shell: pwsh
     - name: steps::show_sccache_stats
-      run: '& $env:RUSTC_WRAPPER --show-stats; exit 0'
+      run: if ($env:RUSTC_WRAPPER) { & $env:RUSTC_WRAPPER --show-stats }; exit 0
       shell: pwsh
     - name: steps::cleanup_cargo_config
       if: always()

tooling/xtask/src/tasks/workflows/steps.rs 🔗

@@ -232,8 +232,11 @@ pub fn setup_sccache(platform: Platform) -> Step<Run> {
 pub fn show_sccache_stats(platform: Platform) -> Step<Run> {
     match platform {
         // Use $env:RUSTC_WRAPPER (absolute path) because GITHUB_PATH changes
-        // don't take effect until the next step in PowerShell
-        Platform::Windows => named::pwsh("& $env:RUSTC_WRAPPER --show-stats; exit 0"),
+        // don't take effect until the next step in PowerShell.
+        // Check if RUSTC_WRAPPER is set first (it won't be for fork PRs without secrets).
+        Platform::Windows => {
+            named::pwsh("if ($env:RUSTC_WRAPPER) { & $env:RUSTC_WRAPPER --show-stats }; exit 0")
+        }
         Platform::Linux | Platform::Mac => named::bash("sccache --show-stats || true"),
     }
 }