From 6cb375f84c46625bd4701f3a082c8a22b38a33eb Mon Sep 17 00:00:00 2001 From: Satyajit Sahoo Date: Tue, 17 Dec 2024 18:40:08 +0100 Subject: [PATCH] chore: always cache actions regardless of failure (#730) --- .github/actions/setup/action.yml | 13 ++++++++-- .github/workflows/build-templates.yml | 26 ++++++++++++++++--- .../common/$.github/actions/setup/action.yml | 13 ++++++++-- .../common/$.github/workflows/ci.yml | 18 +++++++++---- 4 files changed, 57 insertions(+), 13 deletions(-) diff --git a/.github/actions/setup/action.yml b/.github/actions/setup/action.yml index 60df30889..066f4f5e1 100644 --- a/.github/actions/setup/action.yml +++ b/.github/actions/setup/action.yml @@ -9,9 +9,9 @@ runs: with: node-version-file: .nvmrc - - name: Cache dependencies + - name: Restore dependencies id: yarn-cache - uses: actions/cache@v4 + uses: actions/cache/restore@v4 with: path: | **/node_modules @@ -25,3 +25,12 @@ runs: if: steps.yarn-cache.outputs.cache-hit != 'true' run: yarn install --immutable shell: bash + + - name: Cache dependencies + if: steps.yarn-cache.outputs.cache-hit != 'true' + uses: actions/cache/save@v4 + with: + path: | + **/node_modules + .yarn/install-state.gz + key: ${{ steps.yarn-cache.outputs.cache-primary-key }} diff --git a/.github/workflows/build-templates.yml b/.github/workflows/build-templates.yml index 092f5233e..19d5ef1c0 100644 --- a/.github/workflows/build-templates.yml +++ b/.github/workflows/build-templates.yml @@ -88,9 +88,9 @@ jobs: --example ${{ matrix.language == 'js' && 'expo' || 'vanilla' }} \ --no-local - - name: Cache dependencies of library + - name: Restore dependencies of library id: library-yarn-cache - uses: actions/cache@v4 + uses: actions/cache/restore@v4 with: path: | ${{ env.work_dir }}/**/node_modules @@ -107,6 +107,15 @@ jobs: rm -f example/yarn.lock # Workaround for cached yarn.lock from older version yarn install --no-immutable + - name: Cache dependencies of library + if: steps.library-yarn-cache.outputs.cache-hit != 'true' + uses: actions/cache/save@v4 + with: + path: | + ${{ env.work_dir }}/**/node_modules + ${{ env.work_dir }}/yarn.lock + key: ${{ steps.library-yarn-cache.outputs.cache-primary-key }} + - name: Use local version of react-native-builder-bob run: | cd packages/react-native-builder-bob @@ -215,10 +224,10 @@ jobs: run: | yarn turbo run build:android --cache-dir=".turbo" - - name: Cache cocoapods + - name: Restore cocoapods if: env.ios_build == 1 && env.turbo_cache_hit_ios != 1 id: library-cocoapods-cache - uses: actions/cache@v4 + uses: actions/cache/restore@v4 with: path: | ${{ env.work_dir }}/**/ios/Pods @@ -237,6 +246,15 @@ jobs: cd example/ios pod install + - name: Cache cocoapods + if: env.ios_build == 1 && env.turbo_cache_hit_ios != 1 && steps.library-cocoapods-cache.outputs.cache-hit != 'true' + uses: actions/cache/save@v4 + with: + path: | + ${{ env.work_dir }}/**/ios/Pods + ${{ env.work_dir }}/**/ios/Podfile.lock + key: ${{ steps.library-cocoapods-cache.outputs.cache-primary-key }} + - name: Build example (iOS) if: env.ios_build == 1 working-directory: ${{ env.work_dir }} diff --git a/packages/create-react-native-library/templates/common/$.github/actions/setup/action.yml b/packages/create-react-native-library/templates/common/$.github/actions/setup/action.yml index fb98c79ad..d1437f0c5 100644 --- a/packages/create-react-native-library/templates/common/$.github/actions/setup/action.yml +++ b/packages/create-react-native-library/templates/common/$.github/actions/setup/action.yml @@ -9,9 +9,9 @@ runs: with: node-version-file: .nvmrc - - name: Cache dependencies + - name: Restore dependencies id: yarn-cache - uses: actions/cache@v3 + uses: actions/cache/restore@v4 with: path: | **/node_modules @@ -25,3 +25,12 @@ runs: if: steps.yarn-cache.outputs.cache-hit != 'true' run: yarn install --immutable shell: bash + + - name: Cache dependencies + if: steps.yarn-cache.outputs.cache-hit != 'true' + uses: actions/cache/save@v4 + with: + path: | + **/node_modules + .yarn/install-state.gz + key: ${{ steps.yarn-cache.outputs.cache-primary-key }} diff --git a/packages/create-react-native-library/templates/common/$.github/workflows/ci.yml b/packages/create-react-native-library/templates/common/$.github/workflows/ci.yml index c49760c8c..b676e9bbd 100644 --- a/packages/create-react-native-library/templates/common/$.github/workflows/ci.yml +++ b/packages/create-react-native-library/templates/common/$.github/workflows/ci.yml @@ -63,7 +63,7 @@ jobs: uses: ./.github/actions/setup - name: Cache turborepo for Android - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: ${{ env.TURBO_CACHE_DIR }} key: ${{ runner.os }}-turborepo-android-${{ hashFiles('yarn.lock') }} @@ -92,7 +92,7 @@ jobs: - name: Cache Gradle if: env.turbo_cache_hit != 1 - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: | ~/.gradle/wrapper @@ -119,7 +119,7 @@ jobs: uses: ./.github/actions/setup - name: Cache turborepo for iOS - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: ${{ env.TURBO_CACHE_DIR }} key: ${{ runner.os }}-turborepo-ios-${{ hashFiles('yarn.lock') }} @@ -134,10 +134,10 @@ jobs: echo "turbo_cache_hit=1" >> $GITHUB_ENV fi - - name: Cache cocoapods + - name: Restore cocoapods if: env.turbo_cache_hit != 1 id: cocoapods-cache - uses: actions/cache@v3 + uses: actions/cache/restore@v4 with: path: | **/ios/Pods @@ -153,6 +153,14 @@ jobs: env: NO_FLIPPER: 1 + - name: Cache cocoapods + if: env.turbo_cache_hit != 1 && steps.cocoapods-cache.outputs.cache-hit != 'true' + uses: actions/cache/save@v4 + with: + path: | + **/ios/Pods + key: ${{ steps.cocoapods-cache.outputs.cache-key }} + - name: Build example for iOS run: | yarn turbo run build:ios --cache-dir="${{ env.TURBO_CACHE_DIR }}"