-
Notifications
You must be signed in to change notification settings - Fork 191
279 lines (249 loc) · 9.49 KB
/
build-templates.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
name: Build template
on:
workflow_dispatch:
push:
branches:
- main
- next
paths:
- '.github/workflows/build-templates.yml'
- 'packages/create-react-native-library/**'
- '!**.md'
pull_request:
branches:
- main
- next
merge_group:
types:
- checks_requested
jobs:
build:
env:
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: ${{ secrets.TURBO_TEAM }}
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- macos-14 # macos latest defaults to macos 12 at the moment.
type:
- module-legacy
- module-mixed
- module-new
- view-legacy
- view-mixed
- view-new
language:
- java-objc
- java-swift
- kotlin-objc
- kotlin-swift
exclude:
- os: macos-14
language: kotlin-objc
- os: macos-14
language: kotlin-swift
- type: module-new
language: java-swift
- type: module-new
language: kotlin-swift
- type: module-mixed
language: java-swift
- type: module-mixed
language: kotlin-swift
- type: view-new
language: java-swift
- type: view-new
language: kotlin-swift
- type: view-mixed
language: java-swift
- type: view-mixed
language: kotlin-swift
include:
- os: ubuntu-latest
type: library
language: js
- os: ubuntu-latest
type: module-legacy
language: cpp
- os: ubuntu-latest
type: module-mixed
language: cpp
- os: ubuntu-latest
type: module-new
language: cpp
- os: macos-14
type: module-legacy
language: cpp
- os: macos-14
type: module-mixed
language: cpp
- os: macos-14
type: module-new
language: cpp
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-${{ matrix.os }}-${{ matrix.type }}-${{ matrix.language }}
cancel-in-progress: true
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup
uses: ./.github/actions/setup
- name: Build package
run: |
yarn workspace create-react-native-library prepare
- name: Get working directory
run: |
echo "work_dir=${{ matrix.os }}-${{ matrix.type }}-${{ matrix.language }}" >> $GITHUB_ENV
- name: Create library
run: |
rm -rf ${{ env.work_dir }} # Workaround for tests failing intermittently
./packages/create-react-native-library/bin/create-react-native-library ${{ env.work_dir }} \
--slug @bob/react-native-test \
--description test \
--author-name test \
--author-email test@test \
--author-url https://test.test \
--repo-url https://test.test \
--type ${{ matrix.type }} \
--languages ${{ matrix.language }} \
--example ${{ matrix.language == 'js' && 'expo' || 'vanilla' }} \
--no-local
- name: Cache dependencies of library
id: library-yarn-cache
uses: actions/cache@v4
with:
path: |
${{ env.work_dir }}/**/node_modules
${{ env.work_dir }}/yarn.lock
key: ${{ runner.os }}-library-yarn-${{ hashFiles(format('{0}/**/package.json', env.work_dir), format('!{0}/node_modules/**', env.work_dir)) }}
restore-keys: |
${{ runner.os }}-library-yarn-
- name: Install dependencies of library
if: steps.library-yarn-cache.outputs.cache-hit != 'true'
working-directory: ${{ env.work_dir }}
run: |
touch yarn.lock # Without this Yarn will fail due to the parent directory being a Yarn workspace
rm -f example/yarn.lock # Workaround for cached yarn.lock from older version
yarn install --no-immutable
- name: Use local version of react-native-builder-bob
run: |
cd packages/react-native-builder-bob
npm pack
tgz=$(ls react-native-builder-bob-*.tgz)
cd -
cd ${{ env.work_dir }}
YARN_CHECKSUM_BEHAVIOR=ignore yarn add --dev ../packages/react-native-builder-bob/$tgz
- name: Get build target
working-directory: ${{ env.work_dir }}
run: |
# Build Android for only some matrices to skip redundant builds
if [[ ${{ matrix.os }} == ubuntu-latest ]]; then
if [[ ${{ matrix.type }} == view-* && ${{ matrix.language }} == *-objc ]] || [[ ${{ matrix.type }} == module-* && ${{ matrix.language }} == *-objc ]] || [[ ${{ matrix.type }} == module-* && ${{ matrix.language }} == cpp ]]; then
echo "android_build=1" >> $GITHUB_ENV
fi
fi
# Build iOS for only some matrices to skip redundant builds
if [[ ${{ matrix.os }} == macos-14 ]]; then
if [[ ${{ matrix.type }} == view-* && ${{ matrix.language }} == java-* ]] || [[ ${{ matrix.type }} == module-* && ${{ matrix.language }} == java-* ]] || [[ ${{ matrix.type }} == module-* && ${{ matrix.language }} == cpp ]]; then
echo "ios_build=1" >> $GITHUB_ENV
fi
fi
- name: Cache turborepo
if: env.android_build == 1 || env.ios_build == 1
uses: actions/cache@v4
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 turbo run build:android --cache-dir=".turbo" --dry=json)).tasks.find(t => t.task === 'build:android').cache.status")
TURBO_CACHE_STATUS_IOS=$(node -p "($(yarn turbo run build:ios --cache-dir=".turbo" --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: |
yarn lint
- name: Typecheck library
working-directory: ${{ env.work_dir }}
run: |
yarn typecheck
# FIXME: Remove this once we fix the typecheck errors
continue-on-error: true
- name: Test library
working-directory: ${{ env.work_dir }}
run: |
yarn test
- name: Build library
working-directory: ${{ env.work_dir }}
run: |
yarn prepare
- name: Build example (Web)
working-directory: ${{ env.work_dir }}
if: matrix.language == 'js'
run: |
yarn example expo export --platform web
- name: Install JDK
if: env.android_build == 1 && env.turbo_cache_hit_android != 1
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: '17'
- name: Finalize Android SDK
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 && env.turbo_cache_hit_android != 1
uses: actions/cache@v4
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)
env:
JAVA_OPTS: "-XX:MaxHeapSize=6g"
if: env.android_build == 1
working-directory: ${{ env.work_dir }}
run: |
yarn turbo run build:android --cache-dir=".turbo"
- name: Cache cocoapods
if: env.ios_build == 1 && env.turbo_cache_hit_ios != 1
id: library-cocoapods-cache
uses: actions/cache@v4
with:
path: |
${{ env.work_dir }}/**/ios/Pods
${{ env.work_dir }}/**/ios/Podfile.lock
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}/example/ios/Podfile', env.work_dir)) }}-
${{ runner.os }}-library-cocoapods-
- name: Install cocoapods
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: |
cd example/ios
pod install
env:
NO_FLIPPER: 1
- name: Build example (iOS)
if: env.ios_build == 1
working-directory: ${{ env.work_dir }}
run: |
yarn turbo run build:ios --cache-dir=".turbo"