mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
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
101 lines
3.8 KiB
YAML
101 lines
3.8 KiB
YAML
name: prepare-hermes-workspace
|
|
description: This action prepares the hermes workspace with the right hermes and react-native versions.
|
|
inputs:
|
|
hermes-ws-dir:
|
|
required: true
|
|
description: The hermes dir we need to use to setup the workspace
|
|
hermes-version-file:
|
|
required: true
|
|
description: the path to the file that will contain the hermes version
|
|
outputs:
|
|
hermes-version:
|
|
description: the version of Hermes tied to this run
|
|
value: ${{ steps.hermes-version.outputs.VERSION }}
|
|
react-native-version:
|
|
description: the version of React Native tied to this run
|
|
value: ${{ steps.react-native-version.outputs.VERSION }}
|
|
runs:
|
|
using: composite
|
|
steps:
|
|
- name: Setup node.js
|
|
uses: ./.github/actions/setup-node
|
|
|
|
- name: Setup hermes version
|
|
shell: bash
|
|
id: hermes-version
|
|
run: |
|
|
mkdir -p "/tmp/hermes" "/tmp/hermes/download" "/tmp/hermes/hermes"
|
|
|
|
if [ -f "${{ inputs.hermes-version-file }}" ]; then
|
|
echo "Hermes Version file found! Using this version for the build:"
|
|
echo "VERSION=$(cat ${{ inputs.hermes-version-file }})" >> "$GITHUB_OUTPUT"
|
|
else
|
|
echo "Hermes Version file not found!!!"
|
|
echo "Using the last commit from main for the build:"
|
|
HERMES_TAG_SHA=$(git ls-remote https://github.com/facebook/hermes main | cut -f 1 | tr -d '[:space:]')
|
|
echo "VERSION=$HERMES_TAG_SHA" >> "$GITHUB_OUTPUT"
|
|
fi
|
|
echo "Hermes commit is $HERMES_TAG_SHA"
|
|
|
|
- name: Get react-native version
|
|
shell: bash
|
|
id: react-native-version
|
|
run: |
|
|
VERSION=$(cat packages/react-native/package.json | jq -r '.version')
|
|
# Save the react native version we are building in an output variable so we can use that file as part of the cache key.
|
|
echo "VERSION=$VERSION" >> "$GITHUB_OUTPUT"
|
|
echo "React Native Version is $VERSION"
|
|
|
|
- name: Cache hermes workspace
|
|
id: restore-hermes
|
|
uses: actions/cache/restore@v4
|
|
with:
|
|
path: |
|
|
/tmp/hermes/download/
|
|
/tmp/hermes/hermes/
|
|
key: v1-hermes-${{ steps.hermes-version.outputs.version }}
|
|
enableCrossOsArchive: true
|
|
|
|
# It happened while testing that a cache was created from the right folders
|
|
# but those folders where empty. Thus, the next check ensures that we can work with those caches.
|
|
- name: Check if cache was meaningful
|
|
id: meaningful-cache
|
|
shell: bash
|
|
run: |
|
|
if [[ -d /tmp/hermes/hermes ]] && [[ -n "$(ls -A /tmp/hermes/hermes)" ]]; then
|
|
echo "Found a good hermes cache"
|
|
echo "HERMES_CACHED=true" >> "$GITHUB_OUTPUT"
|
|
fi
|
|
|
|
- name: Yarn- Install Dependencies
|
|
if: ${{ steps.meaningful-cache.outputs.HERMES_CACHED != 'true' }}
|
|
uses: ./.github/actions/yarn-install
|
|
|
|
- name: Download Hermes tarball
|
|
if: ${{ steps.meaningful-cache.outputs.HERMES_CACHED != 'true' }}
|
|
shell: bash
|
|
run: |
|
|
node packages/react-native/scripts/hermes/prepare-hermes-for-build ${{ github.event.pull_request.html_url }}
|
|
cp packages/react-native/sdks/download/* ${{ inputs.hermes-ws-dir }}/download/.
|
|
cp -r packages/react-native/sdks/hermes/* ${{ inputs.hermes-ws-dir }}/hermes/.
|
|
|
|
echo ${{ steps.hermes-version.outputs.version }}
|
|
|
|
- name: Upload Hermes artifact
|
|
uses: actions/upload-artifact@v4.3.4
|
|
with:
|
|
name: hermes-workspace
|
|
path: |
|
|
/tmp/hermes/download/
|
|
/tmp/hermes/hermes/
|
|
|
|
- name: Cache hermes workspace
|
|
uses: actions/cache/save@v4
|
|
if: ${{ github.ref == 'refs/heads/main' }} # To avoid that the cache explode.
|
|
with:
|
|
path: |
|
|
/tmp/hermes/download/
|
|
/tmp/hermes/hermes/
|
|
key: v1-hermes-${{ steps.hermes-version.outputs.version }}
|
|
enableCrossOsArchive: true
|