From 4b33b023bf537b4d2433998bd89003171fd404f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rados=C5=82aw=20Rolka?= Date: Wed, 11 Feb 2026 10:20:46 +0100 Subject: [PATCH 1/4] create android cached rn project for building --- .github/workflows/build-library-android.yml | 6 +++ .github/workflows/cache-rn-project.yml | 56 +++++++++++++++++++++ packages/builder/build-utils.ts | 24 +++++---- 3 files changed, 76 insertions(+), 10 deletions(-) create mode 100644 .github/workflows/cache-rn-project.yml diff --git a/.github/workflows/build-library-android.yml b/.github/workflows/build-library-android.yml index de4e94cd..bdb90b36 100644 --- a/.github/workflows/build-library-android.yml +++ b/.github/workflows/build-library-android.yml @@ -57,6 +57,12 @@ jobs: - name: 📦 Install dependencies run: bun install + - name: ♻️ Restore RN project cache + uses: actions/cache@v4 + with: + path: ${{ runner.temp }}/rnrepo_build_app + key: rn-project-cache-android-${{ inputs.react_native_version }} + - name: 🔨 Build library for Android run: bun run packages/builder/build-library-android.ts -- "${{ inputs.library_name }}" "${{ inputs.library_version }}" "${{ inputs.react_native_version }}" "${{ runner.temp }}" "${{ inputs.worklets_version }}" diff --git a/.github/workflows/cache-rn-project.yml b/.github/workflows/cache-rn-project.yml new file mode 100644 index 00000000..81b7cce7 --- /dev/null +++ b/.github/workflows/cache-rn-project.yml @@ -0,0 +1,56 @@ +name: Cache RN Project + +run-name: Cache RN project for RN@${{ inputs.react_native_version }} + +on: + workflow_dispatch: + inputs: + react_native_version: + description: 'React Native version' + required: true + type: string + +jobs: + cache-rn-project: + runs-on: rnrepo-builder-ubuntu-latest + timeout-minutes: 60 + + steps: + - name: 🏗 Checkout repository + uses: actions/checkout@v4 + + - name: ☕ Setup Java JDK + uses: actions/setup-java@v4 + with: + distribution: 'zulu' + java-version: '17' + + - name: 📱 Setup Android SDK + uses: android-actions/setup-android@v3 + + - name: ✅ Accept Android Licenses + run: | + yes | sdkmanager --licenses || true + + - name: 🏗 Setup Bun + uses: oven-sh/setup-bun@v1 + with: + bun-version: latest + + - name: 📦 Install dependencies + run: bun install + + - name: 📱 Create RN project + run: | + work_dir="${{ runner.temp }}" + mkdir -p "$work_dir" + cd "$work_dir" + bunx @react-native-community/cli@latest init rnrepo_build_app --version "${{ inputs.react_native_version }}" --skip-install + cd "$work_dir/rnrepo_build_app" + npm install + + - name: 📦 Cache RN project + uses: actions/cache@v4 + with: + path: ${{ runner.temp }}/rnrepo_build_app + key: rn-project-cache-android-${{ inputs.react_native_version }} diff --git a/packages/builder/build-utils.ts b/packages/builder/build-utils.ts index 26110054..28c0621e 100644 --- a/packages/builder/build-utils.ts +++ b/packages/builder/build-utils.ts @@ -248,19 +248,23 @@ export async function setupReactNativeProject( const { mkdirSync } = await import('fs'); mkdirSync(workDir, { recursive: true }); - // Check that app directory doesn't exist yet + // If appDir already exists, assume it's a cached RN project and skip setup if (existsSync(appDir)) { - throw new Error(`App directory ${appDir} already exists.`); - } + console.log(`♻️ Using cached React Native project at ${appDir}`); + } else { + // Create RN project in the work directory + console.log( + `📱 Creating temporary React Native project (RN ${reactNativeVersion})...` + ); - // Create RN project in the work directory - console.log( - `📱 Creating temporary React Native project (RN ${reactNativeVersion})...` - ); + await $`bunx @react-native-community/cli@latest init rnrepo_build_app --version ${reactNativeVersion} --skip-install` + .cwd(workDir) + .quiet(); + } - await $`bunx @react-native-community/cli@latest init rnrepo_build_app --version ${reactNativeVersion} --skip-install` - .cwd(workDir) - .quiet(); + if (!existsSync(join(appDir, 'package.json'))) { + throw new Error(`Invalid React Native project at ${appDir}`); + } // Perform any library-specific setup before installing await installSetup(appDir, libraryName, 'preInstall'); From 2138c9209f3c57838c16087645c66ba0d960c466 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rados=C5=82aw=20Rolka?= Date: Wed, 11 Feb 2026 10:26:13 +0100 Subject: [PATCH 2/4] add cache for ios too --- .github/workflows/build-library-android.yml | 2 +- .github/workflows/build-library-ios.yml | 6 ++++++ .github/workflows/cache-rn-project.yml | 22 +++++++-------------- 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/.github/workflows/build-library-android.yml b/.github/workflows/build-library-android.yml index bdb90b36..a092ec4f 100644 --- a/.github/workflows/build-library-android.yml +++ b/.github/workflows/build-library-android.yml @@ -61,7 +61,7 @@ jobs: uses: actions/cache@v4 with: path: ${{ runner.temp }}/rnrepo_build_app - key: rn-project-cache-android-${{ inputs.react_native_version }} + key: ${{ runner.os }}-rn-project-cache-${{ inputs.react_native_version }} - name: 🔨 Build library for Android run: bun run packages/builder/build-library-android.ts -- "${{ inputs.library_name }}" "${{ inputs.library_version }}" "${{ inputs.react_native_version }}" "${{ runner.temp }}" "${{ inputs.worklets_version }}" diff --git a/.github/workflows/build-library-ios.yml b/.github/workflows/build-library-ios.yml index 25867fc9..3fa43824 100644 --- a/.github/workflows/build-library-ios.yml +++ b/.github/workflows/build-library-ios.yml @@ -52,6 +52,12 @@ jobs: - name: 📦 Install dependencies run: bun install + - name: ♻️ Restore RN project cache + uses: actions/cache@v4 + with: + path: ${{ runner.temp }}/rnrepo_build_app + key: ${{ runner.os }}-rn-project-cache-${{ inputs.react_native_version }} + - name: 🔨 Build library for iOS run: bun run packages/builder/build-library-ios.ts -- "${{ inputs.library_name }}" "${{ inputs.library_version }}" "${{ inputs.react_native_version }}" "${{ runner.temp }}" "${{ inputs.worklets_version }}" diff --git a/.github/workflows/cache-rn-project.yml b/.github/workflows/cache-rn-project.yml index 81b7cce7..8cf2f088 100644 --- a/.github/workflows/cache-rn-project.yml +++ b/.github/workflows/cache-rn-project.yml @@ -12,26 +12,18 @@ on: jobs: cache-rn-project: - runs-on: rnrepo-builder-ubuntu-latest + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: + - rnrepo-builder-ubuntu-latest + - macos-latest timeout-minutes: 60 steps: - name: 🏗 Checkout repository uses: actions/checkout@v4 - - name: ☕ Setup Java JDK - uses: actions/setup-java@v4 - with: - distribution: 'zulu' - java-version: '17' - - - name: 📱 Setup Android SDK - uses: android-actions/setup-android@v3 - - - name: ✅ Accept Android Licenses - run: | - yes | sdkmanager --licenses || true - - name: 🏗 Setup Bun uses: oven-sh/setup-bun@v1 with: @@ -53,4 +45,4 @@ jobs: uses: actions/cache@v4 with: path: ${{ runner.temp }}/rnrepo_build_app - key: rn-project-cache-android-${{ inputs.react_native_version }} + key: ${{ runner.os }}-rn-project-cache-${{ inputs.react_native_version }} From bc53b7d974cd8724e9f9b4ca3f02a603c225e9ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rados=C5=82aw=20Rolka?= Date: Wed, 11 Feb 2026 10:42:32 +0100 Subject: [PATCH 3/4] automate cache creation --- .github/workflows/build-library-android.yml | 11 +++++ .github/workflows/build-library-ios.yml | 11 +++++ .github/workflows/cache-rn-project.yml | 48 --------------------- 3 files changed, 22 insertions(+), 48 deletions(-) delete mode 100644 .github/workflows/cache-rn-project.yml diff --git a/.github/workflows/build-library-android.yml b/.github/workflows/build-library-android.yml index a092ec4f..3626b56d 100644 --- a/.github/workflows/build-library-android.yml +++ b/.github/workflows/build-library-android.yml @@ -58,11 +58,22 @@ jobs: run: bun install - name: ♻️ Restore RN project cache + id: rn-project-cache uses: actions/cache@v4 with: path: ${{ runner.temp }}/rnrepo_build_app key: ${{ runner.os }}-rn-project-cache-${{ inputs.react_native_version }} + - name: 📱 Create RN project (cache miss) + if: steps.rn-project-cache.outputs.cache-hit != 'true' + run: | + work_dir="${{ runner.temp }}" + mkdir -p "$work_dir" + cd "$work_dir" + bunx @react-native-community/cli@latest init rnrepo_build_app --version "${{ inputs.react_native_version }}" --skip-install + cd "$work_dir/rnrepo_build_app" + npm install + - name: 🔨 Build library for Android run: bun run packages/builder/build-library-android.ts -- "${{ inputs.library_name }}" "${{ inputs.library_version }}" "${{ inputs.react_native_version }}" "${{ runner.temp }}" "${{ inputs.worklets_version }}" diff --git a/.github/workflows/build-library-ios.yml b/.github/workflows/build-library-ios.yml index 3fa43824..8a05c60b 100644 --- a/.github/workflows/build-library-ios.yml +++ b/.github/workflows/build-library-ios.yml @@ -53,11 +53,22 @@ jobs: run: bun install - name: ♻️ Restore RN project cache + id: rn-project-cache uses: actions/cache@v4 with: path: ${{ runner.temp }}/rnrepo_build_app key: ${{ runner.os }}-rn-project-cache-${{ inputs.react_native_version }} + - name: 📱 Create RN project (cache miss) + if: steps.rn-project-cache.outputs.cache-hit != 'true' + run: | + work_dir="${{ runner.temp }}" + mkdir -p "$work_dir" + cd "$work_dir" + bunx @react-native-community/cli@latest init rnrepo_build_app --version "${{ inputs.react_native_version }}" --skip-install + cd "$work_dir/rnrepo_build_app" + npm install + - name: 🔨 Build library for iOS run: bun run packages/builder/build-library-ios.ts -- "${{ inputs.library_name }}" "${{ inputs.library_version }}" "${{ inputs.react_native_version }}" "${{ runner.temp }}" "${{ inputs.worklets_version }}" diff --git a/.github/workflows/cache-rn-project.yml b/.github/workflows/cache-rn-project.yml deleted file mode 100644 index 8cf2f088..00000000 --- a/.github/workflows/cache-rn-project.yml +++ /dev/null @@ -1,48 +0,0 @@ -name: Cache RN Project - -run-name: Cache RN project for RN@${{ inputs.react_native_version }} - -on: - workflow_dispatch: - inputs: - react_native_version: - description: 'React Native version' - required: true - type: string - -jobs: - cache-rn-project: - runs-on: ${{ matrix.os }} - strategy: - matrix: - os: - - rnrepo-builder-ubuntu-latest - - macos-latest - timeout-minutes: 60 - - steps: - - name: 🏗 Checkout repository - uses: actions/checkout@v4 - - - name: 🏗 Setup Bun - uses: oven-sh/setup-bun@v1 - with: - bun-version: latest - - - name: 📦 Install dependencies - run: bun install - - - name: 📱 Create RN project - run: | - work_dir="${{ runner.temp }}" - mkdir -p "$work_dir" - cd "$work_dir" - bunx @react-native-community/cli@latest init rnrepo_build_app --version "${{ inputs.react_native_version }}" --skip-install - cd "$work_dir/rnrepo_build_app" - npm install - - - name: 📦 Cache RN project - uses: actions/cache@v4 - with: - path: ${{ runner.temp }}/rnrepo_build_app - key: ${{ runner.os }}-rn-project-cache-${{ inputs.react_native_version }} From 878f6ffd4b6ba0aa88102406ca10fc37160de169 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rados=C5=82aw=20Rolka?= Date: Wed, 11 Feb 2026 10:59:09 +0100 Subject: [PATCH 4/4] save cache before changes --- .github/workflows/build-library-android.yml | 9 ++++++++- .github/workflows/build-library-ios.yml | 9 ++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-library-android.yml b/.github/workflows/build-library-android.yml index 3626b56d..07d671a9 100644 --- a/.github/workflows/build-library-android.yml +++ b/.github/workflows/build-library-android.yml @@ -59,7 +59,7 @@ jobs: - name: ♻️ Restore RN project cache id: rn-project-cache - uses: actions/cache@v4 + uses: actions/cache/restore@v4 with: path: ${{ runner.temp }}/rnrepo_build_app key: ${{ runner.os }}-rn-project-cache-${{ inputs.react_native_version }} @@ -74,6 +74,13 @@ jobs: cd "$work_dir/rnrepo_build_app" npm install + - name: 💾 Save RN project cache (clean) + if: steps.rn-project-cache.outputs.cache-hit != 'true' + uses: actions/cache/save@v4 + with: + path: ${{ runner.temp }}/rnrepo_build_app + key: ${{ runner.os }}-rn-project-cache-${{ inputs.react_native_version }} + - name: 🔨 Build library for Android run: bun run packages/builder/build-library-android.ts -- "${{ inputs.library_name }}" "${{ inputs.library_version }}" "${{ inputs.react_native_version }}" "${{ runner.temp }}" "${{ inputs.worklets_version }}" diff --git a/.github/workflows/build-library-ios.yml b/.github/workflows/build-library-ios.yml index 8a05c60b..455d7fd7 100644 --- a/.github/workflows/build-library-ios.yml +++ b/.github/workflows/build-library-ios.yml @@ -54,7 +54,7 @@ jobs: - name: ♻️ Restore RN project cache id: rn-project-cache - uses: actions/cache@v4 + uses: actions/cache/restore@v4 with: path: ${{ runner.temp }}/rnrepo_build_app key: ${{ runner.os }}-rn-project-cache-${{ inputs.react_native_version }} @@ -69,6 +69,13 @@ jobs: cd "$work_dir/rnrepo_build_app" npm install + - name: 💾 Save RN project cache (clean) + if: steps.rn-project-cache.outputs.cache-hit != 'true' + uses: actions/cache/save@v4 + with: + path: ${{ runner.temp }}/rnrepo_build_app + key: ${{ runner.os }}-rn-project-cache-${{ inputs.react_native_version }} + - name: 🔨 Build library for iOS run: bun run packages/builder/build-library-ios.ts -- "${{ inputs.library_name }}" "${{ inputs.library_version }}" "${{ inputs.react_native_version }}" "${{ runner.temp }}" "${{ inputs.worklets_version }}"