Skip to content

Commit 6facf3b

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

File tree

2 files changed

+68
-30
lines changed

2 files changed

+68
-30
lines changed

.github/workflows/build-templates.yml

Lines changed: 34 additions & 16 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,25 +201,27 @@ 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: |
204220
~/.gradle/wrapper
205221
~/.gradle/caches
206222
key: ${{ runner.os }}-gradle-${{ hashFiles(format('{0}/example/android/gradle/wrapper/gradle-wrapper.properties', env.work_dir)) }}
223+
restore-keys: |
224+
${{ runner.os }}-gradle-
207225
208226
- name: Build example (Android)
209227
if: env.android_build == 1
@@ -212,20 +230,20 @@ jobs:
212230
yarn turbo run build:android --cache-dir=".turbo/cache"
213231
214232
- name: Cache cocoapods
215-
if: env.ios_build == 1
233+
if: env.ios_build == 1 && env.turbo_cache_hit_ios != 1
216234
id: library-cocoapods-cache
217235
uses: actions/cache@v3
218236
with:
219237
path: |
220238
${{ env.work_dir }}/**/ios/Pods
221239
${{ env.work_dir }}/**/ios/Podfile.lock
222-
key: ${{ runner.os }}-library-cocoapods-${{ hashFiles(format('{0}/**/Podfile', env.work_dir)) }}-${{ hashFiles(format('{0}/**/yarn.lock', env.work_dir)) }}
240+
key: ${{ runner.os }}-library-cocoapods-${{ hashFiles(format('{0}/example/ios/Podfile', env.work_dir)) }}-${{ hashFiles(format('{0}/**/yarn.lock', env.work_dir)) }}
223241
restore-keys: |
224-
${{ runner.os }}-library-cocoapods-${{ hashFiles(format('{0}/**/Podfile', env.work_dir)) }}-
242+
${{ runner.os }}-library-cocoapods-${{ hashFiles(format('{0}/example/ios/Podfile', env.work_dir)) }}-
225243
${{ runner.os }}-library-cocoapods-
226244
227245
- name: Install cocoapods
228-
if: steps.library-cocoapods-cache.outputs.cache-hit != 'true' && env.ios_build == 1
246+
if: env.ios_build == 1 && env.turbo_cache_hit_ios != 1 && steps.library-cocoapods-cache.outputs.cache-hit != 'true'
229247
working-directory: ${{ env.work_dir }}
230248
run: |
231249
yarn example pods

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

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -59,31 +59,44 @@ 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: |
8495
~/.gradle/wrapper
8596
~/.gradle/caches
8697
key: ${{ runner.os }}-gradle-${{ hashFiles('example/android/gradle/wrapper/gradle-wrapper.properties') }}
98+
restore-keys: |
99+
${{ runner.os }}-gradle-
87100
88101
- name: Build example for Android
89102
run: |
@@ -106,28 +119,35 @@ jobs:
106119
path: ${{ env.TURBO_CACHE_DIR }}
107120
key: ${{ runner.os }}-turborepo-ios-${{ hashFiles('**/yarn.lock') }}
108121
restore-keys: |
109-
${{ runner.os }}-library-turborepo-ios-
122+
${{ runner.os }}-turborepo-ios-
123+
124+
- name: Check turborepo cache for iOS
125+
run: |
126+
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")
127+
128+
if [[ $TURBO_CACHE_STATUS == "HIT" ]]; then
129+
echo "turbo_cache_hit=1" >> $GITHUB_ENV
130+
fi
110131
111132
- name: Cache cocoapods
133+
if: env.turbo_cache_hit != 1
112134
id: cocoapods-cache
113135
uses: actions/cache@v3
114136
with:
115137
path: |
116138
**/ios/Pods
117-
**/ios/Podfile.lock
118-
key: ${{ runner.os }}-cocoapods-${{ hashFiles('**/Podfile') }}-${{ hashFiles('**/yarn.lock') }}
139+
key: ${{ runner.os }}-cocoapods-${{ hashFiles('example/ios/Podfile.lock') }}
119140
restore-keys: |
120-
${{ runner.os }}-cocoapods-${{ hashFiles('**/Podfile') }}-
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)