-
-
Notifications
You must be signed in to change notification settings - Fork 4
397 lines (336 loc) · 13.8 KB
/
Copy pathci.yml
File metadata and controls
397 lines (336 loc) · 13.8 KB
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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
name: CI
on:
push:
branches:
- main
- master
pull_request:
branches:
- main
- master
merge_group:
types:
- checks_requested
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
- name: Setup
uses: ./.github/actions/setup
- name: Lint files
run: yarn lint
- name: Typecheck files
run: yarn typecheck
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
- name: Setup
uses: ./.github/actions/setup
- name: Run unit tests
run: yarn test --maxWorkers=2 --coverage
build-library:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
- name: Setup
uses: ./.github/actions/setup
- name: Build package
run: yarn prepare
expo-prebuild:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
features: [none, barcode, 'barcode,text', all]
env:
EXPO_WORK_DIR: ${{ github.workspace }}/.tmp/expo-prebuild-${{ matrix.features }}
steps:
- name: Checkout
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
- name: Setup
uses: ./.github/actions/setup
- name: Expo prebuild smoke test (analysisFeatures=${{ matrix.features }})
env:
DS_FEATURES: ${{ matrix.features }}
run: |
set -euo pipefail
PACKAGE_TGZ="$(npm pack --silent --ignore-scripts | tail -n1)"
rm -rf "$EXPO_WORK_DIR"
mkdir -p "$EXPO_WORK_DIR"
npx --yes create-expo-app@latest "$EXPO_WORK_DIR/app" --template blank-typescript --yes --no-install
cd "$EXPO_WORK_DIR/app"
npm install
npm install --ignore-scripts "$GITHUB_WORKSPACE/$PACKAGE_TGZ"
node <<'NODE'
const fs = require('node:fs');
const path = 'app.json';
const app = JSON.parse(fs.readFileSync(path, 'utf8'));
app.expo = app.expo || {};
app.expo.plugins = [
['@preeternal/react-native-document-scanner-plugin', { analysisFeatures: process.env.DS_FEATURES }],
];
fs.writeFileSync(path, JSON.stringify(app, null, 2) + '\n');
NODE
CI=1 npx expo config --json > "$EXPO_WORK_DIR/expo-config.json" 2> "$EXPO_WORK_DIR/expo-config.stderr.log" || {
echo "::error::expo config failed for analysisFeatures='${DS_FEATURES}'"
if [[ -f "$EXPO_WORK_DIR/expo-config.stderr.log" ]]; then
echo "::group::expo config stderr"
cat "$EXPO_WORK_DIR/expo-config.stderr.log"
echo "::endgroup::"
fi
if [[ -f "$EXPO_WORK_DIR/expo-config.json" ]]; then
echo "::group::expo config stdout"
cat "$EXPO_WORK_DIR/expo-config.json"
echo "::endgroup::"
fi
exit 1
}
node -e "JSON.parse(require(\"node:fs\").readFileSync(process.argv[1], \"utf8\"))" "$EXPO_WORK_DIR/expo-config.json" || {
echo "::error::expo config output is not valid JSON for analysisFeatures='${DS_FEATURES}'"
echo "::group::expo config stdout (raw)"
cat "$EXPO_WORK_DIR/expo-config.json" || true
echo "::endgroup::"
if [[ -f "$EXPO_WORK_DIR/expo-config.stderr.log" ]]; then
echo "::group::expo config stderr"
cat "$EXPO_WORK_DIR/expo-config.stderr.log"
echo "::endgroup::"
fi
exit 1
}
CI=1 npx expo prebuild --platform android --clean --no-install 2>&1 | tee "$EXPO_WORK_DIR/prebuild.log"
ACTUAL_FEATURES="$(awk -F= '/^DocumentScanner_analysisFeatures=/{print $2}' android/gradle.properties | tail -n1 | tr -d '\r')"
if [[ -z "$ACTUAL_FEATURES" ]]; then
echo "::error::Missing DocumentScanner_analysisFeatures in android/gradle.properties"
exit 1
fi
if [[ "$ACTUAL_FEATURES" != "$DS_FEATURES" ]]; then
echo "::error::DocumentScanner_analysisFeatures mismatch. expected='${DS_FEATURES}' actual='${ACTUAL_FEATURES}'"
exit 1
fi
- name: Print Expo prebuild diagnostics (${{ matrix.features }})
if: always()
run: |
set -euo pipefail
echo "::group::app.json"
if [[ -f "$EXPO_WORK_DIR/app/app.json" ]]; then
cat "$EXPO_WORK_DIR/app/app.json"
else
echo "Missing: $EXPO_WORK_DIR/app/app.json"
fi
echo "::endgroup::"
echo "::group::expo config"
if [[ -f "$EXPO_WORK_DIR/expo-config.json" ]]; then
cat "$EXPO_WORK_DIR/expo-config.json"
else
echo "Missing: $EXPO_WORK_DIR/expo-config.json"
fi
echo "::endgroup::"
echo "::group::android/gradle.properties (DocumentScanner lines)"
if [[ -f "$EXPO_WORK_DIR/app/android/gradle.properties" ]]; then
grep -n "DocumentScanner" "$EXPO_WORK_DIR/app/android/gradle.properties" || echo "(no DocumentScanner entries)"
else
echo "Missing: $EXPO_WORK_DIR/app/android/gradle.properties"
fi
echo "::endgroup::"
- name: Upload Expo prebuild diagnostics (${{ matrix.features }})
if: always()
uses: actions/upload-artifact@v4
with:
name: expo-prebuild-${{ matrix.features }}-diagnostics
if-no-files-found: warn
path: |
${{ env.EXPO_WORK_DIR }}/prebuild.log
${{ env.EXPO_WORK_DIR }}/app/app.json
${{ env.EXPO_WORK_DIR }}/expo-config.json
${{ env.EXPO_WORK_DIR }}/expo-config.stderr.log
${{ env.EXPO_WORK_DIR }}/app/android/gradle.properties
- name: Cleanup Expo prebuild workspace (${{ matrix.features }})
if: always()
run: rm -rf "$EXPO_WORK_DIR"
build-android:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
features: [none, barcode, text, all]
env:
TURBO_CACHE_DIR: .turbo/android-${{ matrix.features }}
steps:
- name: Checkout
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
- name: Setup
uses: ./.github/actions/setup
- name: Cache turborepo for Android (${{ matrix.features }})
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
with:
path: ${{ env.TURBO_CACHE_DIR }}
key: ${{ runner.os }}-turborepo-android-${{ matrix.features }}-${{ hashFiles('yarn.lock') }}
restore-keys: |
${{ runner.os }}-turborepo-android-${{ matrix.features }}-
- name: Check turborepo cache for Android (${{ matrix.features }})
run: |
TURBO_CACHE_STATUS=$(node -p "($(yarn turbo run build:android --filter=@preeternal/react-native-document-scanner-plugin-example --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@c5195efecf7bdfc987ee8bae7a71cb8b11521c00 # v4.7.1
with:
distribution: 'zulu'
java-version: '17'
- 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 Gradle
if: env.turbo_cache_hit != 1
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
with:
path: |
~/.gradle/wrapper
~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ matrix.features }}-${{ hashFiles('example/android/gradle/wrapper/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-${{ matrix.features }}-
${{ runner.os }}-gradle-
- name: Build example for Android (features=${{ matrix.features }})
env:
JAVA_OPTS: "-XX:MaxHeapSize=6g"
ORG_GRADLE_PROJECT_DocumentScanner_analysisFeatures: ${{ matrix.features }}
run: |
yarn turbo run build:android --filter=@preeternal/react-native-document-scanner-plugin-example --cache-dir="${{ env.TURBO_CACHE_DIR }}"
build-ios:
runs-on: macos-latest
env:
XCODE_VERSION: latest-stable
TURBO_CACHE_DIR: .turbo/ios
RCT_REMOVE_LEGACY_ARCH: 1
RCT_USE_RN_DEP: 1
RCT_USE_PREBUILT_RNCORE: 1
steps:
- name: Checkout
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
- name: Setup
uses: ./.github/actions/setup
- name: Cache turborepo for iOS
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
with:
path: ${{ env.TURBO_CACHE_DIR }}
key: ${{ runner.os }}-turborepo-ios-${{ hashFiles('yarn.lock') }}
restore-keys: |
${{ runner.os }}-turborepo-ios-
- name: Check turborepo cache for iOS
run: |
TURBO_CACHE_STATUS=$(node -p "($(yarn turbo run build:ios --filter=@preeternal/react-native-document-scanner-plugin-example --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: Use appropriate Xcode version
if: env.turbo_cache_hit != 1
uses: maxim-lobanov/setup-xcode@60606e260d2fc5762a71e64e74b2174e8ea3c8bd # v1.6.0
with:
xcode-version: ${{ env.XCODE_VERSION }}
- name: Install cocoapods
if: env.turbo_cache_hit != 1 && steps.cocoapods-cache.outputs.cache-hit != 'true'
run: |
cd example
bundle install
bundle exec pod repo update --verbose
bundle exec pod install --project-directory=ios
- name: Build example for iOS
run: |
set -euo pipefail
IOS_BUILD_LOG="$RUNNER_TEMP/ios-build.log"
if ! yarn turbo run build:ios --filter=@preeternal/react-native-document-scanner-plugin-example --cache-dir="${{ env.TURBO_CACHE_DIR }}" 2>&1 | tee "$IOS_BUILD_LOG"; then
echo "::group::First iOS errors"
grep -nE " error: |fatal error:|Command PhaseScriptExecution failed|No such file|cannot find type " \
"$IOS_BUILD_LOG" | head -n 80 || true
echo "::endgroup::"
exit 1
fi
- name: Upload iOS build log
if: always()
uses: actions/upload-artifact@v4
with:
name: ios-build-log
if-no-files-found: warn
path: ${{ runner.temp }}/ios-build.log
build-android-rn87:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
- name: Setup
uses: ./.github/actions/setup
- name: Install JDK
uses: actions/setup-java@c5195efecf7bdfc987ee8bae7a71cb8b11521c00 # v4.7.1
with:
distribution: 'zulu'
java-version: '17'
- name: Finalize Android SDK
run: |
/bin/bash -c "yes | $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager --licenses > /dev/null"
- name: Cache Gradle
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
with:
path: |
~/.gradle/wrapper
~/.gradle/caches
key: ${{ runner.os }}-gradle-rn87-${{ hashFiles('example-spm/android/gradle/wrapper/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-rn87-
${{ runner.os }}-gradle-
- name: Build RN 0.87 example for Android
env:
JAVA_OPTS: "-XX:MaxHeapSize=6g"
ORG_GRADLE_PROJECT_DocumentScanner_analysisFeatures: all
run: yarn example:spm build:android
build-ios-spm-rn87:
runs-on: macos-latest
env:
XCODE_VERSION: latest-stable
steps:
- name: Checkout
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
- name: Setup
uses: ./.github/actions/setup
- name: Use appropriate Xcode version
uses: maxim-lobanov/setup-xcode@60606e260d2fc5762a71e64e74b2174e8ea3c8bd # v1.6.0
with:
xcode-version: ${{ env.XCODE_VERSION }}
- name: Cache React Native SwiftPM artifacts
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
with:
path: ~/Library/Caches/ReactNative/spm-artifacts
key: ${{ runner.os }}-react-native-spm-${{ hashFiles('example-spm/package.json') }}
restore-keys: |
${{ runner.os }}-react-native-spm-
- name: Generate SwiftPM integration
run: yarn example:spm spm:setup
- name: Build RN 0.87 SwiftPM example for iOS
run: |
set -euo pipefail
IOS_BUILD_LOG="$RUNNER_TEMP/ios-spm-build.log"
if ! yarn example:spm build:ios 2>&1 | tee "$IOS_BUILD_LOG"; then
echo "::group::First iOS SwiftPM errors"
grep -nE " error: |fatal error:|Command PhaseScriptExecution failed|No such file|cannot find type " \
"$IOS_BUILD_LOG" | head -n 80 || true
echo "::endgroup::"
exit 1
fi
- name: Upload iOS SwiftPM build log
if: always()
uses: actions/upload-artifact@v4
with:
name: ios-spm-rn87-build-log
if-no-files-found: warn
path: ${{ runner.temp }}/ios-spm-build.log