Skip to content

Commit 7b11914

Browse files
committed
chore: check for turborepo cache before build
1 parent 325b7ca commit 7b11914

File tree

2 files changed

+61
-25
lines changed

2 files changed

+61
-25
lines changed

.github/workflows/build-templates.yml

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -132,15 +132,6 @@ jobs:
132132
yarn install --cwd example
133133
yarn install
134134
135-
- name: Cache turborepo
136-
uses: actions/cache@v3
137-
with:
138-
path: |
139-
${{ env.work_dir }}/.turbo
140-
key: ${{ runner.os }}-library-turborepo-${{ matrix.type }}-${{ matrix.language }}-${{ hashFiles(format('{0}/**/yarn.lock', env.work_dir)) }}
141-
restore-keys: |
142-
${{ runner.os }}-library-turborepo-${{ matrix.type }}-${{ matrix.language }}-
143-
144135
- name: Get build target
145136
working-directory: ${{ env.work_dir }}
146137
run: |
@@ -158,6 +149,31 @@ jobs:
158149
fi
159150
fi
160151
152+
- name: Cache turborepo
153+
if: env.android_build == 1 || env.ios_build == 1
154+
uses: actions/cache@v3
155+
with:
156+
path: |
157+
${{ env.work_dir }}/.turbo
158+
key: ${{ runner.os }}-library-turborepo-${{ matrix.type }}-${{ matrix.language }}-${{ hashFiles(format('{0}/**/yarn.lock', env.work_dir)) }}
159+
restore-keys: |
160+
${{ runner.os }}-library-turborepo-${{ matrix.type }}-${{ matrix.language }}-
161+
162+
- name: Check turborepo cache
163+
if: env.android_build == 1 || env.ios_build == 1
164+
working-directory: ${{ env.work_dir }}
165+
run: |
166+
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")
167+
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")
168+
169+
if [[ $TURBO_CACHE_STATUS_ANDROID == "HIT" ]]; then
170+
echo "turbo_cache_hit_android=1" >> $GITHUB_ENV
171+
fi
172+
173+
if [[ $TURBO_CACHE_STATUS_IOS == "HIT" ]]; then
174+
echo "turbo_cache_hit_ios=1" >> $GITHUB_ENV
175+
fi
176+
161177
- name: Lint library
162178
working-directory: ${{ env.work_dir }}
163179
run: |
@@ -185,19 +201,19 @@ jobs:
185201
yarn example expo export:web
186202
187203
- name: Install JDK
188-
if: env.android_build == 1
204+
if: env.android_build == 1 && env.turbo_cache_hit_android != 1
189205
uses: actions/setup-java@v3
190206
with:
191207
distribution: 'zulu'
192208
java-version: '11'
193209

194210
- name: Finalize Android SDK
195-
if: env.android_build == 1
211+
if: env.android_build == 1 && env.turbo_cache_hit_android != 1
196212
run: |
197213
/bin/bash -c "yes | $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager --licenses > /dev/null"
198214
199215
- name: Cache Gradle
200-
if: env.android_build == 1
216+
if: env.android_build == 1 && env.turbo_cache_hit_android != 1
201217
uses: actions/cache@v3
202218
with:
203219
path: |
@@ -212,7 +228,7 @@ jobs:
212228
yarn turbo run build:android --cache-dir=".turbo/cache"
213229
214230
- name: Cache cocoapods
215-
if: env.ios_build == 1
231+
if: env.ios_build == 1 && env.turbo_cache_hit_ios != 1
216232
id: library-cocoapods-cache
217233
uses: actions/cache@v3
218234
with:
@@ -225,7 +241,7 @@ jobs:
225241
${{ runner.os }}-library-cocoapods-
226242
227243
- name: Install cocoapods
228-
if: steps.library-cocoapods-cache.outputs.cache-hit != 'true' && env.ios_build == 1
244+
if: env.ios_build == 1 && env.turbo_cache_hit_ios != 1 && steps.library-cocoapods-cache.outputs.cache-hit != 'true'
229245
working-directory: ${{ env.work_dir }}
230246
run: |
231247
yarn example pods

packages/create-react-native-library/templates/common/$.github/workflows/ci.yml

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,25 +59,36 @@ jobs:
5959
- name: Setup
6060
uses: ./.github/actions/setup
6161

62+
- name: Cache turborepo for Android
63+
uses: actions/cache@v3
64+
with:
65+
path: ${{ env.TURBO_CACHE_DIR }}
66+
key: ${{ runner.os }}-turborepo-android-${{ hashFiles('**/yarn.lock') }}
67+
restore-keys: |
68+
${{ runner.os }}-turborepo-android-
69+
70+
- name: Check turborepo cache for Android
71+
run: |
72+
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")
73+
74+
if [[ $TURBO_CACHE_STATUS == "HIT" ]]; then
75+
echo "turbo_cache_hit=1" >> $GITHUB_ENV
76+
fi
77+
6278
- name: Install JDK
79+
if: env.turbo_cache_hit != 1
6380
uses: actions/setup-java@v3
6481
with:
6582
distribution: 'zulu'
6683
java-version: '11'
6784

6885
- name: Finalize Android SDK
86+
if: env.turbo_cache_hit != 1
6987
run: |
7088
/bin/bash -c "yes | $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager --licenses > /dev/null"
7189
72-
- name: Cache turborepo for Android
73-
uses: actions/cache@v3
74-
with:
75-
path: ${{ env.TURBO_CACHE_DIR }}
76-
key: ${{ runner.os }}-turborepo-android-${{ hashFiles('**/yarn.lock') }}
77-
restore-keys: |
78-
${{ runner.os }}-library-turborepo-android-
79-
8090
- name: Cache Gradle
91+
if: env.turbo_cache_hit != 1
8192
uses: actions/cache@v3
8293
with:
8394
path: |
@@ -106,9 +117,18 @@ jobs:
106117
path: ${{ env.TURBO_CACHE_DIR }}
107118
key: ${{ runner.os }}-turborepo-ios-${{ hashFiles('**/yarn.lock') }}
108119
restore-keys: |
109-
${{ runner.os }}-library-turborepo-ios-
120+
${{ runner.os }}-turborepo-ios-
121+
122+
- name: Check turborepo cache for iOS
123+
run: |
124+
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")
125+
126+
if [[ $TURBO_CACHE_STATUS == "HIT" ]]; then
127+
echo "turbo_cache_hit=1" >> $GITHUB_ENV
128+
fi
110129
111130
- name: Cache cocoapods
131+
if: env.turbo_cache_hit != 1
112132
id: cocoapods-cache
113133
uses: actions/cache@v3
114134
with:
@@ -121,13 +141,13 @@ jobs:
121141
${{ runner.os }}-cocoapods-
122142
123143
- name: Install cocoapods
124-
if: steps.cocoapods-cache.outputs.cache-hit != 'true'
144+
if: env.turbo_cache_hit != 1 && steps.cocoapods-cache.outputs.cache-hit != 'true'
125145
run: |
126146
yarn example pods
127147
env:
128148
NO_FLIPPER: 1
129149

130-
- name: Build example (iOS)
150+
- name: Build example for iOS
131151
run: |
132152
yarn turbo run build:ios --cache-dir="${{ env.TURBO_CACHE_DIR }}"
133153
<% } else { -%>

0 commit comments

Comments
 (0)