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 7b11914
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 25 deletions.
44 changes: 30 additions & 14 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,19 +201,19 @@ 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: |
Expand All @@ -212,7 +228,7 @@ 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:
Expand All @@ -225,7 +241,7 @@ jobs:
${{ 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,25 +59,36 @@ 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: |
Expand Down Expand Up @@ -106,9 +117,18 @@ 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:
Expand All @@ -121,13 +141,13 @@ jobs:
${{ 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 7b11914

Please sign in to comment.