From a28867f9524beeabb3cb939446fe825cac124c58 Mon Sep 17 00:00:00 2001 From: Nick Gerleman Date: Thu, 12 Dec 2024 09:13:52 -0800 Subject: [PATCH] Remove home-rolled yarn caching (#48237) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/48237 Noticed this when trying to diagnose what seemed like a stale caching issue. It effectively reverts D59917944. D59917944 added logic to only do yarn caching on main, but it has some correctness issues: 1. We cache `node_modules` instead of the yarn cache, which may contain e.g. build artifacts, or other scratch/cache files written (such as anything that writes to `node_modules/.cache`). We really want to be caching the yarn cache, which has pristine packages before install, which I think it will also need to perform the real install anyways. 2. We key the cache on root `package.json`, which is missing a lot of information (both provided by the other `package.json` in the repo, but mostly, the lockfile resolution). We only save cache when we're on `refs/heads/main` (so continuous builds against main), and supposedly, builds against base branch should be able to restore against those, but recent PR jobs I have seen, where `package.json` has not changed, all have `Cache not found for input keys: node-modules-068350889e87919c1c6c2c220c8d2d92db13f38820bf2efb315d1274b97bc367` Because of the potential correctness issues, and that the strategy for limiting to main seemingly is not allowing cache to be used in PR, this diff goes back to previous solution, which may store more artifacts (but working cache should also reduce cost by making jobs run faster). Changelog: [Internal] Reviewed By: cipolleschi Differential Revision: D67140004 fbshipit-source-id: f74074a498af56b1837fa23cf80795f76935b762 --- .github/actions/build-android/action.yml | 2 +- .github/actions/build-hermes-macos/action.yml | 2 +- .github/actions/build-npm-package/action.yml | 2 +- .github/actions/create-release/action.yml | 2 +- .../prepare-hermes-workspace/action.yml | 2 +- .github/actions/setup-node/action.yml | 1 + .../actions/test-ios-helloworld/action.yml | 2 +- .github/actions/test-ios-rntester/action.yml | 2 +- .github/actions/test-js/action.yml | 2 +- .../yarn-install-with-cache/action.yml | 28 ------------------- .github/actions/yarn-install/action.yml | 7 +++++ .github/workflows/publish-bumped-packages.yml | 2 +- .github/workflows/test-all.yml | 8 +++--- .../workflows/update-node-modules-cache.yml | 18 ------------ 14 files changed, 21 insertions(+), 59 deletions(-) delete mode 100644 .github/actions/yarn-install-with-cache/action.yml create mode 100644 .github/actions/yarn-install/action.yml delete mode 100644 .github/workflows/update-node-modules-cache.yml diff --git a/.github/actions/build-android/action.yml b/.github/actions/build-android/action.yml index cf2367f647e32c..b18e605c8eb90d 100644 --- a/.github/actions/build-android/action.yml +++ b/.github/actions/build-android/action.yml @@ -16,7 +16,7 @@ runs: - name: Setup node.js uses: ./.github/actions/setup-node - name: Install node dependencies - uses: ./.github/actions/yarn-install-with-cache + uses: ./.github/actions/yarn-install - name: Set React Native Version shell: bash run: node ./scripts/releases/set-rn-artifacts-version.js --build-type ${{ inputs.release-type }} diff --git a/.github/actions/build-hermes-macos/action.yml b/.github/actions/build-hermes-macos/action.yml index 18afd8b98b0b4e..41c7e6e869c8e2 100644 --- a/.github/actions/build-hermes-macos/action.yml +++ b/.github/actions/build-hermes-macos/action.yml @@ -47,7 +47,7 @@ runs: fi - name: Yarn- Install Dependencies if: ${{ steps.check_if_apple_artifacts_are_there.outputs.ARTIFACTS_EXIST != 'true' }} - uses: ./.github/actions/yarn-install-with-cache + uses: ./.github/actions/yarn-install - name: Slice cache macosx if: ${{ steps.check_if_apple_artifacts_are_there.outputs.ARTIFACTS_EXIST != 'true' }} uses: actions/download-artifact@v4 diff --git a/.github/actions/build-npm-package/action.yml b/.github/actions/build-npm-package/action.yml index 295868a376bbe3..2f66293313b5e4 100644 --- a/.github/actions/build-npm-package/action.yml +++ b/.github/actions/build-npm-package/action.yml @@ -103,7 +103,7 @@ runs: - name: Setup gradle uses: ./.github/actions/setup-gradle - name: Install dependencies - uses: ./.github/actions/yarn-install-with-cache + uses: ./.github/actions/yarn-install - name: Build packages shell: bash run: yarn build diff --git a/.github/actions/create-release/action.yml b/.github/actions/create-release/action.yml index 0d0f2055f0359e..ff22a0cb3a0906 100644 --- a/.github/actions/create-release/action.yml +++ b/.github/actions/create-release/action.yml @@ -15,7 +15,7 @@ runs: using: composite steps: - name: Yarn install - uses: ./.github/actions/yarn-install-with-cache + uses: ./.github/actions/yarn-install - name: Configure Git shell: bash run: | diff --git a/.github/actions/prepare-hermes-workspace/action.yml b/.github/actions/prepare-hermes-workspace/action.yml index 4a5e638790e017..22dbe356ee581d 100644 --- a/.github/actions/prepare-hermes-workspace/action.yml +++ b/.github/actions/prepare-hermes-workspace/action.yml @@ -69,7 +69,7 @@ runs: - name: Yarn- Install Dependencies if: ${{ steps.meaningful-cache.outputs.HERMES_CACHED != 'true' }} - uses: ./.github/actions/yarn-install-with-cache + uses: ./.github/actions/yarn-install - name: Download Hermes tarball if: ${{ steps.meaningful-cache.outputs.HERMES_CACHED != 'true' }} diff --git a/.github/actions/setup-node/action.yml b/.github/actions/setup-node/action.yml index fe041bca1c62a0..b1d1a1ebf963f7 100644 --- a/.github/actions/setup-node/action.yml +++ b/.github/actions/setup-node/action.yml @@ -12,3 +12,4 @@ runs: uses: actions/setup-node@v4 with: node-version: ${{ inputs.node-version }} + cache: yarn diff --git a/.github/actions/test-ios-helloworld/action.yml b/.github/actions/test-ios-helloworld/action.yml index c3819ae95270c5..687a9d24970ca3 100644 --- a/.github/actions/test-ios-helloworld/action.yml +++ b/.github/actions/test-ios-helloworld/action.yml @@ -41,7 +41,7 @@ runs: shell: bash run: ls -lR "$HERMES_WS_DIR" - name: Run yarn - uses: ./.github/actions/yarn-install-with-cache + uses: ./.github/actions/yarn-install - name: Setup ruby uses: ruby/setup-ruby@v1.170.0 with: diff --git a/.github/actions/test-ios-rntester/action.yml b/.github/actions/test-ios-rntester/action.yml index 25acfe2cd60353..d731957978bfeb 100644 --- a/.github/actions/test-ios-rntester/action.yml +++ b/.github/actions/test-ios-rntester/action.yml @@ -41,7 +41,7 @@ runs: - name: Setup node.js uses: ./.github/actions/setup-node - name: Run yarn - uses: ./.github/actions/yarn-install-with-cache + uses: ./.github/actions/yarn-install - name: Download Hermes uses: actions/download-artifact@v4 with: diff --git a/.github/actions/test-js/action.yml b/.github/actions/test-js/action.yml index 4cb531c46097b7..58ee569fc6f01a 100644 --- a/.github/actions/test-js/action.yml +++ b/.github/actions/test-js/action.yml @@ -13,7 +13,7 @@ runs: with: node-version: ${{ inputs.node-version }} - name: Yarn install - uses: ./.github/actions/yarn-install-with-cache + uses: ./.github/actions/yarn-install - name: Run Tests - JavaScript Tests shell: bash run: node ./scripts/run-ci-javascript-tests.js --maxWorkers 2 diff --git a/.github/actions/yarn-install-with-cache/action.yml b/.github/actions/yarn-install-with-cache/action.yml deleted file mode 100644 index 8273398acbbea7..00000000000000 --- a/.github/actions/yarn-install-with-cache/action.yml +++ /dev/null @@ -1,28 +0,0 @@ -name: yarn-install-with-cache -inputs: - update-cache: - description: Update the cache, only do this if you are update-node-modules-cache.yml - default: "false" -description: Only update node_modules if on main -runs: - using: composite - steps: - - name: Load node_modules from cache - # Restore for all branches, but save for 'main'. - uses: actions/cache/restore@v4 - with: - path: node_modules/ - key: node-modules-${{ hashFiles('package.json') }} - - name: Install dependencies - shell: bash - run: yarn install --non-interactive - - name: Save node_modules to the cache - if: github.ref == 'refs/heads/main' && inputs.update-cache == 'true' - uses: actions/cache/save@v4 - with: - path: node_modules/ - # We're assuming that variations on branches will slightly vary from main, - # so it's always important to run yarn install --non-interactive after this - # cache is restored. - key: node-modules-v1-${{ hashFiles('package.json') }} - enableCrossOsArchive: true diff --git a/.github/actions/yarn-install/action.yml b/.github/actions/yarn-install/action.yml new file mode 100644 index 00000000000000..16a635792055d6 --- /dev/null +++ b/.github/actions/yarn-install/action.yml @@ -0,0 +1,7 @@ +name: yarn-install +runs: + using: composite + steps: + - name: Install dependencies + shell: bash + run: yarn install --non-interactive --frozen-lockfile diff --git a/.github/workflows/publish-bumped-packages.yml b/.github/workflows/publish-bumped-packages.yml index 6d5c27fbdd69be..d2a2fb7a9b3046 100644 --- a/.github/workflows/publish-bumped-packages.yml +++ b/.github/workflows/publish-bumped-packages.yml @@ -17,7 +17,7 @@ jobs: - name: Setup node.js uses: ./.github/actions/setup-node - name: Run Yarn Install - uses: ./.github/actions/yarn-install-with-cache + uses: ./.github/actions/yarn-install - name: Build packages run: yarn build - name: Set NPM auth token diff --git a/.github/workflows/test-all.yml b/.github/workflows/test-all.yml index b10d34c232315a..317fdbc49f4fec 100644 --- a/.github/workflows/test-all.yml +++ b/.github/workflows/test-all.yml @@ -242,7 +242,7 @@ jobs: - name: Setup node.js uses: ./.github/actions/setup-node - name: Run yarn - uses: ./.github/actions/yarn-install-with-cache + uses: ./.github/actions/yarn-install - name: Setup ruby uses: ruby/setup-ruby@v1.170.0 with: @@ -320,7 +320,7 @@ jobs: - name: Setup node.js uses: ./.github/actions/setup-node - name: Run yarn - uses: ./.github/actions/yarn-install-with-cache + uses: ./.github/actions/yarn-install - name: Set up JDK 17 uses: actions/setup-java@v2 with: @@ -451,7 +451,7 @@ jobs: - name: Setup node.js uses: ./.github/actions/setup-node - name: Install node dependencies - uses: ./.github/actions/yarn-install-with-cache + uses: ./.github/actions/yarn-install - name: Download APK uses: actions/download-artifact@v4 with: @@ -533,7 +533,7 @@ jobs: - name: Setup gradle uses: ./.github/actions/setup-gradle - name: Run yarn install - uses: ./.github/actions/yarn-install-with-cache + uses: ./.github/actions/yarn-install - name: Prepare the Helloworld application shell: bash run: node ./scripts/e2e/init-project-e2e.js --useHelloWorld --pathToLocalReactNative "$GITHUB_WORKSPACE/build/$(cat build/react-native-package-version)" diff --git a/.github/workflows/update-node-modules-cache.yml b/.github/workflows/update-node-modules-cache.yml deleted file mode 100644 index 9c74021341b8bd..00000000000000 --- a/.github/workflows/update-node-modules-cache.yml +++ /dev/null @@ -1,18 +0,0 @@ -name: Update node modules cache - -on: - workflow_dispatch: - push: - branches: - - main - -jobs: - update_node_modules_cache: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - - name: Install yarn dependencies and update cache - uses: ./.github/actions/yarn-install-with-cache - with: - update-cache: "true"