Skip to content

Commit

Permalink
chore: check for turborepo cache before build
Browse files Browse the repository at this point in the history
  • Loading branch information
satya164 committed Jul 4, 2023
1 parent 325b7ca commit 6facf3b
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 30 deletions.
50 changes: 34 additions & 16 deletions .github/workflows/build-templates.yml
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,6 @@ jobs:
yarn install --cwd example
yarn install
- name: Cache turborepo
uses: actions/cache@v3
with:
path: |
${{ env.work_dir }}/.turbo
key: ${{ runner.os }}-library-turborepo-${{ matrix.type }}-${{ matrix.language }}-${{ hashFiles(format('{0}/**/yarn.lock', env.work_dir)) }}
restore-keys: |
${{ runner.os }}-library-turborepo-${{ matrix.type }}-${{ matrix.language }}-
- name: Get build target
working-directory: ${{ env.work_dir }}
run: |
Expand All @@ -158,6 +149,31 @@ jobs:
fi
fi
- name: Cache turborepo
if: env.android_build == 1 || env.ios_build == 1
uses: actions/cache@v3
with:
path: |
${{ env.work_dir }}/.turbo
key: ${{ runner.os }}-library-turborepo-${{ matrix.type }}-${{ matrix.language }}-${{ hashFiles(format('{0}/**/yarn.lock', env.work_dir)) }}
restore-keys: |
${{ runner.os }}-library-turborepo-${{ matrix.type }}-${{ matrix.language }}-
- name: Check turborepo cache
if: env.android_build == 1 || env.ios_build == 1
working-directory: ${{ env.work_dir }}
run: |
TURBO_CACHE_STATUS_ANDROID=$(node -p "($(yarn --silent turbo run build:android --cache-dir=".turbo/cache" --dry=json)).tasks.find(t => t.task === 'build:android').cache.status")
TURBO_CACHE_STATUS_IOS=$(node -p "($(yarn --silent turbo run build:ios --cache-dir=".turbo/cache" --dry=json)).tasks.find(t => t.task === 'build:ios').cache.status")
if [[ $TURBO_CACHE_STATUS_ANDROID == "HIT" ]]; then
echo "turbo_cache_hit_android=1" >> $GITHUB_ENV
fi
if [[ $TURBO_CACHE_STATUS_IOS == "HIT" ]]; then
echo "turbo_cache_hit_ios=1" >> $GITHUB_ENV
fi
- name: Lint library
working-directory: ${{ env.work_dir }}
run: |
Expand Down Expand Up @@ -185,25 +201,27 @@ jobs:
yarn example expo export:web
- name: Install JDK
if: env.android_build == 1
if: env.android_build == 1 && env.turbo_cache_hit_android != 1
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: '11'

- name: Finalize Android SDK
if: env.android_build == 1
if: env.android_build == 1 && env.turbo_cache_hit_android != 1
run: |
/bin/bash -c "yes | $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager --licenses > /dev/null"
- name: Cache Gradle
if: env.android_build == 1
if: env.android_build == 1 && env.turbo_cache_hit_android != 1
uses: actions/cache@v3
with:
path: |
~/.gradle/wrapper
~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles(format('{0}/example/android/gradle/wrapper/gradle-wrapper.properties', env.work_dir)) }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Build example (Android)
if: env.android_build == 1
Expand All @@ -212,20 +230,20 @@ jobs:
yarn turbo run build:android --cache-dir=".turbo/cache"
- name: Cache cocoapods
if: env.ios_build == 1
if: env.ios_build == 1 && env.turbo_cache_hit_ios != 1
id: library-cocoapods-cache
uses: actions/cache@v3
with:
path: |
${{ env.work_dir }}/**/ios/Pods
${{ env.work_dir }}/**/ios/Podfile.lock
key: ${{ runner.os }}-library-cocoapods-${{ hashFiles(format('{0}/**/Podfile', env.work_dir)) }}-${{ hashFiles(format('{0}/**/yarn.lock', env.work_dir)) }}
key: ${{ runner.os }}-library-cocoapods-${{ hashFiles(format('{0}/example/ios/Podfile', env.work_dir)) }}-${{ hashFiles(format('{0}/**/yarn.lock', env.work_dir)) }}
restore-keys: |
${{ runner.os }}-library-cocoapods-${{ hashFiles(format('{0}/**/Podfile', env.work_dir)) }}-
${{ runner.os }}-library-cocoapods-${{ hashFiles(format('{0}/example/ios/Podfile', env.work_dir)) }}-
${{ runner.os }}-library-cocoapods-
- name: Install cocoapods
if: steps.library-cocoapods-cache.outputs.cache-hit != 'true' && env.ios_build == 1
if: env.ios_build == 1 && env.turbo_cache_hit_ios != 1 && steps.library-cocoapods-cache.outputs.cache-hit != 'true'
working-directory: ${{ env.work_dir }}
run: |
yarn example pods
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,31 +59,44 @@ jobs:
- name: Setup
uses: ./.github/actions/setup

- name: Cache turborepo for Android
uses: actions/cache@v3
with:
path: ${{ env.TURBO_CACHE_DIR }}
key: ${{ runner.os }}-turborepo-android-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-turborepo-android-
- name: Check turborepo cache for Android
run: |
TURBO_CACHE_STATUS=$(node -p "($(yarn --silent turbo run build:android --cache-dir="${{ env.TURBO_CACHE_DIR }}" --dry=json)).tasks.find(t => t.task === 'build:android').cache.status")
if [[ $TURBO_CACHE_STATUS == "HIT" ]]; then
echo "turbo_cache_hit=1" >> $GITHUB_ENV
fi
- name: Install JDK
if: env.turbo_cache_hit != 1
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: '11'

- name: Finalize Android SDK
if: env.turbo_cache_hit != 1
run: |
/bin/bash -c "yes | $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager --licenses > /dev/null"
- name: Cache turborepo for Android
uses: actions/cache@v3
with:
path: ${{ env.TURBO_CACHE_DIR }}
key: ${{ runner.os }}-turborepo-android-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-library-turborepo-android-
- name: Cache Gradle
if: env.turbo_cache_hit != 1
uses: actions/cache@v3
with:
path: |
~/.gradle/wrapper
~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('example/android/gradle/wrapper/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Build example for Android
run: |
Expand All @@ -106,28 +119,35 @@ jobs:
path: ${{ env.TURBO_CACHE_DIR }}
key: ${{ runner.os }}-turborepo-ios-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-library-turborepo-ios-
${{ runner.os }}-turborepo-ios-
- name: Check turborepo cache for iOS
run: |
TURBO_CACHE_STATUS=$(node -p "($(yarn --silent turbo run build:ios --cache-dir="${{ env.TURBO_CACHE_DIR }}" --dry=json)).tasks.find(t => t.task === 'build:ios').cache.status")
if [[ $TURBO_CACHE_STATUS == "HIT" ]]; then
echo "turbo_cache_hit=1" >> $GITHUB_ENV
fi
- name: Cache cocoapods
if: env.turbo_cache_hit != 1
id: cocoapods-cache
uses: actions/cache@v3
with:
path: |
**/ios/Pods
**/ios/Podfile.lock
key: ${{ runner.os }}-cocoapods-${{ hashFiles('**/Podfile') }}-${{ hashFiles('**/yarn.lock') }}
key: ${{ runner.os }}-cocoapods-${{ hashFiles('example/ios/Podfile.lock') }}
restore-keys: |
${{ runner.os }}-cocoapods-${{ hashFiles('**/Podfile') }}-
${{ runner.os }}-cocoapods-
- name: Install cocoapods
if: steps.cocoapods-cache.outputs.cache-hit != 'true'
if: env.turbo_cache_hit != 1 && steps.cocoapods-cache.outputs.cache-hit != 'true'
run: |
yarn example pods
env:
NO_FLIPPER: 1

- name: Build example (iOS)
- name: Build example for iOS
run: |
yarn turbo run build:ios --cache-dir="${{ env.TURBO_CACHE_DIR }}"
<% } else { -%>
Expand Down

0 comments on commit 6facf3b

Please sign in to comment.