Skip to content

Commit 9c6c637

Browse files
cipolleschifacebook-github-bot
authored andcommitted
Refactor Hermes workspace (facebook#45071)
Summary: This change is the first step in refactoring GHA so that they can be reused more easily across jobs. Its goal is also to be more reliable w.r.t. caches. That this change do: * moves `prepare_hermes_workspace` to a composite action * saves the `prepare_hermes_workspace` caches only on main * uploads the destination folder as an artifact so that we can use it later in the run * makes the `test-all`, `nightly` and `publish-release` workflow use the new composite action * updates the `setup-hermes-workspace` to download and use the artifact uploaded by `prepare_hermes_workspace` ## Changelog: [Internal] - Factor out the prepare_hermes_workspace action Pull Request resolved: facebook#45071 Test Plan: GHA in CI Reviewed By: cortinico Differential Revision: D58808087 Pulled By: cipolleschi fbshipit-source-id: 42c46bcf75fc73b2edfda9be62b5d0fe8a919a5d
1 parent 2e6f105 commit 9c6c637

File tree

7 files changed

+153
-174
lines changed

7 files changed

+153
-174
lines changed

.github/actions/cache_setup/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,5 +84,5 @@ runs:
8484
path: |
8585
/tmp/hermes/download/
8686
/tmp/hermes/hermes/
87-
key: v1-hermes-${{ inputs.hermes-version }}-${{ github.run_number }}
87+
key: v1-hermes-${{ inputs.hermes-version }}
8888
enableCrossOsArchive: true
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
name: prepare-hermes-workspace
2+
description: This action prepares the hermes workspace with the right hermes and react-native versions.
3+
inputs:
4+
HERMES_WS_DIR:
5+
required: true
6+
description: The hermes dir we need to use to setup the workspace
7+
HERMES_VERSION_FILE:
8+
required: true
9+
description: the path to the file that will contain the hermes version
10+
BUILD_FROM_SOURCE:
11+
description: Whether we need to build from source or not
12+
default: true
13+
outputs:
14+
hermes-version:
15+
description: the version of Hermes tied to this run
16+
value: ${{ steps.hermes-version.outputs.VERSION }}
17+
react-native-version:
18+
description: the version of React Native tied to this run
19+
value: ${{ steps.react-native-version.outputs.VERSION }}
20+
runs:
21+
using: composite
22+
steps:
23+
- name: Setup node.js
24+
uses: ./.github/actions/setup-node
25+
26+
- name: Setup hermes version
27+
shell: bash
28+
id: hermes-version
29+
run: |
30+
mkdir -p "/tmp/hermes" "/tmp/hermes/download" "/tmp/hermes/hermes"
31+
32+
if [ -f "$HERMES_VERSION_FILE" ]; then
33+
echo "Hermes Version file found! Using this version for the build:"
34+
echo "VERSION=$(cat $HERMES_VERSION_FILE)" >> "$GITHUB_OUTPUT"
35+
else
36+
echo "Hermes Version file not found!!!"
37+
echo "Using the last commit from main for the build:"
38+
HERMES_TAG_SHA=$(git ls-remote https://github.com/facebook/hermes main | cut -f 1 | tr -d '[:space:]')
39+
echo "VERSION=$HERMES_TAG_SHA" >> "$GITHUB_OUTPUT"
40+
fi
41+
echo "Hermes commit is $HERMES_TAG_SHA"
42+
43+
- name: Get react-native version
44+
shell: bash
45+
id: react-native-version
46+
run: |
47+
VERSION=$(cat packages/react-native/package.json | jq -r '.version')
48+
# Save the react native version we are building in an output variable so we can use that file as part of the cache key.
49+
echo "VERSION=$VERSION" >> "$GITHUB_OUTPUT"
50+
echo "React Native Version is $VERSION"
51+
52+
- name: Cache hermes workspace
53+
id: restore-hermes
54+
uses: actions/cache/[email protected]
55+
with:
56+
path: |
57+
/tmp/hermes/download/
58+
/tmp/hermes/hermes/
59+
key: v1-hermes-${{ steps.hermes-version.outputs.version }}
60+
enableCrossOsArchive: true
61+
62+
# It happened while testing that a cache was created from the right folders
63+
# but those folders where empty. Thus, the next check ensures that we can work with those caches.
64+
- name: Check if cache was meaningful
65+
id: meaningful-cache
66+
shell: bash
67+
run: |
68+
if [[ -d /tmp/hermes/hermes ]] && [[ -n "$(ls -A /tmp/hermes/hermes)" ]]; then
69+
echo "Found a good hermes cache"
70+
echo "HERMES_CACHED=true" >> "$GITHUB_OUTPUT"
71+
fi
72+
73+
- name: Yarn- Install Dependencies
74+
if: ${{ steps.meaningful-cache.outputs.HERMES_CACHED != 'true' }}
75+
shell: bash
76+
run: yarn install --non-interactive
77+
78+
- name: Download Hermes tarball
79+
if: ${{ steps.meaningful-cache.outputs.HERMES_CACHED != 'true' }}
80+
shell: bash
81+
run: |
82+
node packages/react-native/scripts/hermes/prepare-hermes-for-build ${{ github.event.pull_request.html_url }}
83+
cp packages/react-native/sdks/download/* $HERMES_WS_DIR/download/.
84+
cp -r packages/react-native/sdks/hermes/* $HERMES_WS_DIR/hermes/.
85+
86+
echo ${{ steps.hermes-version.outputs.version }}
87+
88+
- name: Upload Hermes artifact
89+
uses: actions/upload-artifact@v4
90+
with:
91+
name: hermes-workspace
92+
path: |
93+
/tmp/hermes/download/
94+
/tmp/hermes/hermes/
95+
96+
- name: Cache hermes workspace
97+
uses: actions/cache/[email protected]
98+
if: ${{ github.ref == 'refs/heads/main' }} # To avoid that the cache explode.
99+
with:
100+
path: |
101+
/tmp/hermes/download/
102+
/tmp/hermes/hermes/
103+
key: v1-hermes-${{ steps.hermes-version.outputs.version }}
104+
enableCrossOsArchive: true

.github/actions/setup_hermes_workspace/action.yml renamed to .github/actions/restore-hermes-workspace/action.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1-
name: setup_hermes_workspace
2-
description: "Setup hermes workspace"
1+
name: restore-hermes-workspace
2+
description: "Restore hermes workspace that has been created in Prepare Hermes Workspace"
33
runs:
44
using: composite
55
steps:
6+
- name: Download Previous Artifacts
7+
uses: actions/download-artifact@v4
8+
with:
9+
name: hermes-workspace
10+
path: /tmp/hermes
611
- name: Set up workspace
712
shell: bash
813
run: |

.github/actions/test_ios_helloworld/action.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ runs:
5454
- name: Run yarn
5555
shell: bash
5656
run: yarn install --non-interactive
57-
- name: Setup Hermes workspace
58-
uses: ./.github/actions/setup_hermes_workspace
57+
- name: Restore Hermes workspace
58+
uses: ./.github/actions/restore-hermes-workspace
5959
- name: Setup ruby
6060
uses: ruby/[email protected]
6161
with:

.github/workflows/nightly.yml

Lines changed: 12 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -30,52 +30,14 @@ jobs:
3030
BUILD_FROM_SOURCE: true
3131
GRADLE_OPTS: '-Dorg.gradle.daemon=false'
3232
outputs:
33-
react-native-version: ${{ steps.react-native-version.outputs.version }}
34-
hermes-version: ${{ steps.hermes-version.outputs.version }}
33+
react-native-version: ${{ steps.prepare-hermes-workspace.outputs.react-native-version }}
34+
hermes-version: ${{ steps.prepare-hermes-workspace.outputs.hermes-version }}
3535
steps:
3636
- name: Checkout
3737
uses: actions/[email protected]
38-
- name: Setup node.js
39-
uses: ./.github/actions/setup-node
40-
- name: Setup hermes version
41-
id: hermes-version
42-
run: |
43-
mkdir -p "/tmp/hermes" "/tmp/hermes/download" "/tmp/hermes/hermes"
44-
45-
if [ -f "$HERMES_VERSION_FILE" ]; then
46-
echo "Hermes Version file found! Using this version for the build:"
47-
echo "VERSION=$(cat $HERMES_VERSION_FILE)" >> "$GITHUB_OUTPUT"
48-
else
49-
echo "Hermes Version file not found!!!"
50-
echo "Using the last commit from main for the build:"
51-
HERMES_TAG_SHA=$(git ls-remote https://github.com/facebook/hermes main | cut -f 1 | tr -d '[:space:]')
52-
echo "VERSION=$HERMES_TAG_SHA" >> "$GITHUB_OUTPUT"
53-
fi
54-
echo "Hermes commit is $HERMES_TAG_SHA"
55-
- name: Get react-native version
56-
id: react-native-version
57-
run: |
58-
VERSION=$(cat packages/react-native/package.json | jq -r '.version')
59-
# Save the react native version we are building in an output variable so we can use that file as part of the cache key.
60-
echo "VERSION=$VERSION" >> "$GITHUB_OUTPUT"
61-
echo "React Native Version is $VERSION"
62-
- name: Cache hermes workspace
63-
uses: actions/[email protected]
64-
with:
65-
path: |
66-
/tmp/hermes/download/
67-
/tmp/hermes/hermes/
68-
key: v1-hermes-${{ steps.hermes-version.outputs.version }}-${{ github.run_number }}
69-
enableCrossOsArchive: true
70-
- name: Yarn- Install Dependencies
71-
run: yarn install --non-interactive
72-
- name: Download Hermes tarball
73-
run: |
74-
node packages/react-native/scripts/hermes/prepare-hermes-for-build ${{ github.event.pull_request.html_url }}
75-
cp packages/react-native/sdks/download/* $HERMES_WS_DIR/download/.
76-
cp -r packages/react-native/sdks/hermes/* $HERMES_WS_DIR/hermes/.
77-
78-
echo ${{ steps.hermes-version.outputs.version }}
38+
- name: Prepare Hermes Workspace
39+
id: prepare-hermes-workspace
40+
uses: ./.github/actions/prepare-hermes-workspace
7941

8042
build_hermesc_apple:
8143
runs-on: macos-13
@@ -86,16 +48,8 @@ jobs:
8648
steps:
8749
- name: Checkout
8850
uses: actions/[email protected]
89-
- name: Cache hermes workspace
90-
uses: actions/[email protected]
91-
with:
92-
path: |
93-
/tmp/hermes/download/
94-
/tmp/hermes/hermes/
95-
key: v1-hermes-${{ needs.prepare_hermes_workspace.outputs.hermes-version }}-${{ github.run_number }}
96-
enableCrossOsArchive: true
97-
- name: Setup Hermes workspace
98-
uses: ./.github/actions/setup_hermes_workspace
51+
- name: Restore Hermes workspace
52+
uses: ./.github/actions/restore-hermes-workspace
9953
- name: Hermes apple cache
10054
uses: actions/[email protected]
10155
with:
@@ -131,8 +85,8 @@ jobs:
13185
with:
13286
hermes-version: ${{ needs.prepare_hermes_workspace.outputs.hermes-version }}
13387
react-native-version: ${{ needs.prepare_hermes_workspace.outputs.react-native-version }}
134-
- name: Setup Hermes workspace
135-
uses: ./.github/actions/setup_hermes_workspace
88+
- name: Restore Hermes workspace
89+
uses: ./.github/actions/restore-hermes-workspace
13690
- name: Check if the required artifacts already exist
13791
id: check_if_apple_artifacts_are_there
13892
run: |
@@ -226,8 +180,8 @@ jobs:
226180
with:
227181
hermes-version: ${{ needs.prepare_hermes_workspace.outputs.hermes-version }}
228182
react-native-version: ${{ needs.prepare_hermes_workspace.outputs.react-native-version }}
229-
- name: Setup Hermes workspace
230-
uses: ./.github/actions/setup_hermes_workspace
183+
- name: Restore Hermes workspace
184+
uses: ./.github/actions/restore-hermes-workspace
231185
- name: Check if the required artifacts already exist
232186
id: check_if_apple_artifacts_are_there
233187
run: |
@@ -306,6 +260,7 @@ jobs:
306260
run: |
307261
cd ./packages/react-native/sdks/hermes || exit 1
308262
echo "[HERMES] Creating the universal framework"
263+
chmod +x ./utils/build-ios-framework.sh
309264
./utils/build-ios-framework.sh build_framework
310265
- name: Package the Hermes Apple frameworks
311266
if: ${{ steps.check_if_apple_artifacts_are_there.outputs.ARTIFACTS_EXIST != true }}

.github/workflows/publish-release.yml

Lines changed: 12 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -27,52 +27,14 @@ jobs:
2727
BUILD_FROM_SOURCE: true
2828
GRADLE_OPTS: '-Dorg.gradle.daemon=false'
2929
outputs:
30-
react-native-version: ${{ steps.react-native-version.outputs.version }}
31-
hermes-version: ${{ steps.hermes-version.outputs.version }}
30+
react-native-version: ${{ steps.prepare-hermes-workspace.outputs.react-native-version }}
31+
hermes-version: ${{ steps.prepare-hermes-workspace.outputs.hermes-version }}
3232
steps:
3333
- name: Checkout
3434
uses: actions/[email protected]
35-
- name: Setup node.js
36-
uses: ./.github/actions/setup-node
37-
- name: Setup hermes version
38-
id: hermes-version
39-
run: |
40-
mkdir -p "/tmp/hermes" "/tmp/hermes/download" "/tmp/hermes/hermes"
41-
42-
if [ -f "$HERMES_VERSION_FILE" ]; then
43-
echo "Hermes Version file found! Using this version for the build:"
44-
echo "VERSION=$(cat $HERMES_VERSION_FILE)" >> "$GITHUB_OUTPUT"
45-
else
46-
echo "Hermes Version file not found!!!"
47-
echo "Using the last commit from main for the build:"
48-
HERMES_TAG_SHA=$(git ls-remote https://github.com/facebook/hermes main | cut -f 1 | tr -d '[:space:]')
49-
echo "VERSION=$HERMES_TAG_SHA" >> "$GITHUB_OUTPUT"
50-
fi
51-
echo "Hermes commit is $HERMES_TAG_SHA"
52-
- name: Get react-native version
53-
id: react-native-version
54-
run: |
55-
VERSION=$(cat packages/react-native/package.json | jq -r '.version')
56-
# Save the react native version we are building in an output variable so we can use that file as part of the cache key.
57-
echo "VERSION=$VERSION" >> "$GITHUB_OUTPUT"
58-
echo "React Native Version is $VERSION"
59-
- name: Cache hermes workspace
60-
uses: actions/[email protected]
61-
with:
62-
path: |
63-
/tmp/hermes/download/
64-
/tmp/hermes/hermes/
65-
key: v1-hermes-${{ steps.hermes-version.outputs.version }}-${{ github.run_number }}
66-
enableCrossOsArchive: true
67-
- name: Yarn- Install Dependencies
68-
run: yarn install --non-interactive
69-
- name: Download Hermes tarball
70-
run: |
71-
node packages/react-native/scripts/hermes/prepare-hermes-for-build ${{ github.event.pull_request.html_url }}
72-
cp packages/react-native/sdks/download/* $HERMES_WS_DIR/download/.
73-
cp -r packages/react-native/sdks/hermes/* $HERMES_WS_DIR/hermes/.
74-
75-
echo ${{ steps.hermes-version.outputs.version }}
35+
- name: Prepare Hermes Workspace
36+
id: prepare-hermes-workspace
37+
uses: ./.github/actions/prepare-hermes-workspace
7638

7739
build_hermesc_apple:
7840
runs-on: macos-13
@@ -83,16 +45,8 @@ jobs:
8345
steps:
8446
- name: Checkout
8547
uses: actions/[email protected]
86-
- name: Cache hermes workspace
87-
uses: actions/[email protected]
88-
with:
89-
path: |
90-
/tmp/hermes/download/
91-
/tmp/hermes/hermes/
92-
key: v1-hermes-${{ needs.prepare_hermes_workspace.outputs.hermes-version }}-${{ github.run_number }}
93-
enableCrossOsArchive: true
94-
- name: Setup Hermes workspace
95-
uses: ./.github/actions/setup_hermes_workspace
48+
- name: Restore Hermes workspace
49+
uses: ./.github/actions/restore-hermes-workspace
9650
- name: Hermes apple cache
9751
uses: actions/[email protected]
9852
with:
@@ -128,8 +82,8 @@ jobs:
12882
with:
12983
hermes-version: ${{ needs.prepare_hermes_workspace.outputs.hermes-version }}
13084
react-native-version: ${{ needs.prepare_hermes_workspace.outputs.react-native-version }}
131-
- name: Setup Hermes workspace
132-
uses: ./.github/actions/setup_hermes_workspace
85+
- name: Restore Hermes workspace
86+
uses: ./.github/actions/restore-hermes-workspace
13387
- name: Check if the required artifacts already exist
13488
id: check_if_apple_artifacts_are_there
13589
run: |
@@ -223,8 +177,8 @@ jobs:
223177
with:
224178
hermes-version: ${{ needs.prepare_hermes_workspace.outputs.hermes-version }}
225179
react-native-version: ${{ needs.prepare_hermes_workspace.outputs.react-native-version }}
226-
- name: Setup Hermes workspace
227-
uses: ./.github/actions/setup_hermes_workspace
180+
- name: Restore Hermes workspace
181+
uses: ./.github/actions/restore-hermes-workspace
228182
- name: Check if the required artifacts already exist
229183
id: check_if_apple_artifacts_are_there
230184
run: |
@@ -303,6 +257,7 @@ jobs:
303257
run: |
304258
cd ./packages/react-native/sdks/hermes || exit 1
305259
echo "[HERMES] Creating the universal framework"
260+
chmod +x ./utils/build-ios-framework.sh
306261
./utils/build-ios-framework.sh build_framework
307262
- name: Package the Hermes Apple frameworks
308263
if: ${{ steps.check_if_apple_artifacts_are_there.outputs.ARTIFACTS_EXIST != true }}

0 commit comments

Comments
 (0)