From cd344c8f46f339aff69b5d3e7ad8ed75842e6b50 Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Mon, 15 Apr 2024 12:42:28 +0200 Subject: [PATCH] improve turborepo caching (#64493) ### What? There is a race condition in the `pull-build-cache` script. When the remote cache entry was removed between the dry run and the real run, it will run the command and caches whatever is in the native folder. Seems like there are some very old leftover files there which lead to an broken publish. This changes the command to fail when there are no files and empties the folder before running the script. This should lead to pull-build-cache to failing instead. Closes PACK-2957 Fixes #64468 --- .github/workflows/build_and_deploy.yml | 3 +++ packages/next-swc/package.json | 2 +- scripts/pull-turbo-cache.js | 1 + 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build_and_deploy.yml b/.github/workflows/build_and_deploy.yml index e585a05bac19c..83c2f9b183235 100644 --- a/.github/workflows/build_and_deploy.yml +++ b/.github/workflows/build_and_deploy.yml @@ -275,6 +275,9 @@ jobs: cache-provider: 'turbo' shared-key: build-${{ matrix.settings.target }}-${{ hashFiles('.cargo/config.toml') }} + - name: Clear native build + run: rm -rf packages/next-swc/native + # we only need custom caching for docker builds # as they are on an older Node.js version and have # issues with turbo caching diff --git a/packages/next-swc/package.json b/packages/next-swc/package.json index 0486159429743..1ff5c5f4b4fdc 100644 --- a/packages/next-swc/package.json +++ b/packages/next-swc/package.json @@ -11,7 +11,7 @@ "build-native-no-plugin-woa-release": "napi build --platform -p next-swc-napi --cargo-cwd ../../ --cargo-name next_swc_napi --release --cargo-flags=--no-default-features --features image-webp,tracing/release_max_level_info --js false native", "build-native-wasi": "npx --package=@napi-rs/cli@3.0.0-alpha.45 napi build --platform --target wasm32-wasip1-threads -p next-swc-napi --cwd ../../ --output-dir packages/next-swc/native", "build-wasm": "wasm-pack build crates/wasm --scope=next", - "cache-build-native": "echo $(ls native)", + "cache-build-native": "[ -d native ] && echo $(ls native)", "rust-check-fmt": "cd ../..; cargo fmt -- --check", "rust-check-clippy": "cargo clippy --workspace --all-targets -- -D warnings -A deprecated", "rust-check-napi-rustls": "cargo check -p next-swc-napi", diff --git a/scripts/pull-turbo-cache.js b/scripts/pull-turbo-cache.js index 919618a347f61..fa7e9a06e6f28 100644 --- a/scripts/pull-turbo-cache.js +++ b/scripts/pull-turbo-cache.js @@ -42,6 +42,7 @@ const { spawn } = require('child_process') // pull cache if it was available if (task.cache.local || task.cache.remote) { + console.log('Cache Status', task.taskId, task.hash, task.cache) await new Promise((resolve, reject) => { const child = spawn( '/bin/bash',