-
-
Notifications
You must be signed in to change notification settings - Fork 81
230 lines (209 loc) · 10.1 KB
/
build-ios-test-app.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
name: Build iOS Test Development Container App
env:
# Relative path from the monorepo root to the app
test_app_path: tests/test
# Package name in the monorepo
test_app_package_name: test-test
# Used for cache keys, must be unique among all workflows
app_identifier: ios-test-app
# Should match the name of "ios/<app_name>.xcworkspace"
app_name: OneTestApp
on:
workflow_call:
inputs:
configuration:
required: true
type: string
description: "Either 'Debug' or 'Release'."
outputs:
build-hash:
description: "A hash to identify the build."
value: ${{ jobs.build-ios.outputs.build-hash }}
built-app-cache-key:
description: "The cache key of the built .app."
value: ${{ jobs.build-ios.outputs.built-app-cache-key }}
built-app-path:
description: "The path to the built .app relative to the repository root."
value: ${{ jobs.build-ios.outputs.built-app-path }}
jobs:
build-ios:
name: Build
runs-on: macos-13
permissions:
contents: read
pull-requests: read
timeout-minutes: 60
outputs:
build-hash: ${{ steps.caculate-build-hash.outputs.build_hash }}
built-app-cache-key: ${{ steps.check-previous-build.outputs.cache-primary-key || steps.pre-check-previous-build.outputs.cache-primary-key }}
built-app-path: ${{ steps.get-built-app-path.outputs.built_app_path }}
defaults:
run:
working-directory: ${{ env.test_app_path }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Get Built App Path
id: get-built-app-path
env:
BUILT_APP_PATH: ${{ env.test_app_path }}/build/Build/Products/${{ inputs.configuration }}-iphonesimulator/${{ env.app_name }}.app
run: |
echo "Built app path: $BUILT_APP_PATH"
echo "built_app_path=$BUILT_APP_PATH" >> $GITHUB_OUTPUT
- name: Caculate Pre-Build Hash
id: caculate-pre-build-hash
env:
# A hash that can save us more time if we can already know that the build hash will not change.
#
# Calculating the build_hash relies on generated files, for example, `Podfile.lock`, and it’ll take some time to run `yarn install`, `expo prebuild` and `pod install` in order to get that. But if `yarn.lock` didn’t change, there’s no likely that `Podfile.lock` will change - we can leverage that and skip some installation steps.
#
# This hash MUST be different if the build_hash will be different.
#
# This hash can be different if the build_hash remains the same. For example, if `yarn.lock` changes, `Podfile.lock` may not change if the updated package contains no native code.
PRE_BUILD_HASH: ${{ hashFiles(format('{0}/yarn.lock', env.test_app_path), format('{0}/app.json', env.test_app_path), 'packages/vxrn/expo-plugin.cjs') }}
run: |
if [ -z "$PRE_BUILD_HASH" ]; then
echo '[ERROR] Failed to calculate pre-build hash.'
fi
echo "Pre-build hash: $PRE_BUILD_HASH"
echo "pre_build_hash=$PRE_BUILD_HASH" >> $GITHUB_OUTPUT
- name: Get Pre-Build Hash Mapping Key
id: get-pre-build-hash-mapping-key
env:
PRE_BUILD_HASH_MAPPING_KEY: ${{ env.app_identifier }}-${{ inputs.configuration }}-pre-build-hash-to-hash-mapping-${{ steps.caculate-pre-build-hash.outputs.pre_build_hash }}
BUILD_HASH_MAPPING_FILE_PATH: ${{ env.test_app_path }}/build-hash.txt
run: |
echo "Pre-build hash mapping key: $PRE_BUILD_HASH_MAPPING_KEY"
echo "pre_build_hash_mapping_key=$PRE_BUILD_HASH_MAPPING_KEY" >> $GITHUB_OUTPUT
echo "Build hash mapping file path: $BUILD_HASH_MAPPING_FILE_PATH"
echo "build_hash_mapping_file_path=$BUILD_HASH_MAPPING_FILE_PATH" >> $GITHUB_OUTPUT
- name: Get Pre-Build Hash Mapping
uses: actions/cache/restore@v4
with:
key: ${{ steps.get-pre-build-hash-mapping-key.outputs.pre_build_hash_mapping_key }}
path: ${{ steps.get-pre-build-hash-mapping-key.outputs.build_hash_mapping_file_path }}
- name: Read Build Hash from Mapping
id: read-build-hash
run: |
if [ -f build-hash.txt ]; then
BUILD_HASH=$(tr -d '[:space:]' < build-hash.txt)
echo "Build hash: $BUILD_HASH"
echo "build_hash=$BUILD_HASH" >> $GITHUB_OUTPUT
else
echo 'No cached build hash found.'
echo "build_hash=NULL" >> $GITHUB_OUTPUT
fi
- name: Check If Previous Build Exists
uses: actions/cache/restore@v4
id: pre-check-previous-build
with:
key: ${{ env.app_identifier }}-${{ inputs.configuration }}-${{ steps.read-build-hash.outputs.build_hash }}
lookup-only: true
path: ${{ steps.get-built-app-path.outputs.built_app_path }}
- name: Install
uses: ./.github/actions/install
if: ${{ !steps.pre-check-previous-build.outputs.cache-hit }}
with:
workspace-focus: ${{ env.test_app_package_name }}
- name: Prebuild
if: ${{ !steps.pre-check-previous-build.outputs.cache-hit }}
run: |
node_modules/.bin/expo prebuild --platform ios --no-install # --no-install is used to skip installing dependencies, specifically `pod install` as we want to do it after the Cache Pods step
- name: Cache Pods
uses: actions/cache@v4
if: ${{ !steps.pre-check-previous-build.outputs.cache-hit }}
env:
cache-name: ${{ env.app_identifier }}-pods
with:
path: ${{ env.test_app_path }}/ios/Pods
key: ${{ runner.os }}-${{ env.cache-name }}-${{ hashFiles(format('{0}/ios/Podfile.lock', env.test_app_path)) }}
restore-keys: |
${{ runner.os }}-${{ env.cache-name }}-
- name: Pod Install
if: ${{ !steps.pre-check-previous-build.outputs.cache-hit }}
run: |
cd ios && pod install
- name: Caculate Build Hash
id: caculate-build-hash
if: ${{ !steps.pre-check-previous-build.outputs.cache-hit }}
env:
# We need to list all files that will affect native code in hashFiles.
BUILD_HASH: ${{ hashFiles(format('{0}/ios/Podfile.lock', env.test_app_path), format('{0}/app.json', env.test_app_path), 'packages/vxrn/expo-plugin.cjs') }}
run: |
if [ -z "$BUILD_HASH" ]; then
echo '[ERROR] Failed to calculate build hash.'
exit 1
fi
echo "Build hash: $BUILD_HASH"
echo "build_hash=$BUILD_HASH" >> $GITHUB_OUTPUT
- name: Write Build Hash
if: ${{ !steps.pre-check-previous-build.outputs.cache-hit }}
env:
BUILD_HASH: ${{ steps.caculate-build-hash.outputs.build_hash }}
run: |
echo $BUILD_HASH > build-hash.txt
- name: Save Pre-Build Hash Mapping
uses: actions/cache/save@v4
if: ${{ !steps.pre-check-previous-build.outputs.cache-hit }}
with:
key: ${{ steps.get-pre-build-hash-mapping-key.outputs.pre_build_hash_mapping_key }}
path: ${{ steps.get-pre-build-hash-mapping-key.outputs.build_hash_mapping_file_path }}
- name: Check If Previous Build Exists
uses: actions/cache/restore@v4
id: check-previous-build
if: ${{ !steps.pre-check-previous-build.outputs.cache-hit }}
with:
key: ${{ env.app_identifier }}-${{ inputs.configuration }}-${{ steps.caculate-build-hash.outputs.build_hash }}
lookup-only: true
path: ${{ steps.get-built-app-path.outputs.built_app_path }}
- name: Restore Build Cache
id: restore-build-cache
uses: actions/cache/restore@v4
if: ${{ !steps.pre-check-previous-build.outputs.cache-hit && !steps.check-previous-build.outputs.cache-hit }}
env:
cache-name: ${{ env.app_identifier }}-build
with:
key: ${{ runner.os }}-${{ env.cache-name }}-${{ inputs.configuration }}-${{ steps.caculate-build-hash.outputs.build_hash }}
restore-keys: |
${{ runner.os }}-${{ env.cache-name }}-${{ inputs.configuration }}-
${{ runner.os }}-${{ env.cache-name }}-
path: |
${{ env.test_app_path }}/build
- name: Build
if: ${{ !steps.pre-check-previous-build.outputs.cache-hit && !steps.check-previous-build.outputs.cache-hit }}
run: |
set -o pipefail
xcrun xcodebuild -scheme '${{ env.app_name }}' \
-workspace 'ios/${{ env.app_name }}.xcworkspace' \
-configuration ${{ inputs.configuration }} \
-sdk 'iphonesimulator' \
-destination 'generic/platform=iOS Simulator' \
-derivedDataPath build | tee xcodebuild.log | xcpretty
- name: Upload Built App
uses: actions/[email protected]
if: ${{ !steps.pre-check-previous-build.outputs.cache-hit && !steps.check-previous-build.outputs.cache-hit }}
continue-on-error: true
with:
name: built-app # TODO: dynamic name?
path: |
${{ steps.get-built-app-path.outputs.built_app_path }}
- name: Cache Built App
uses: actions/cache/save@v4
if: ${{ !steps.pre-check-previous-build.outputs.cache-hit && !steps.check-previous-build.outputs.cache-hit }}
with:
key: ${{ steps.check-previous-build.outputs.cache-primary-key }}
path: ${{ steps.get-built-app-path.outputs.built_app_path }}
- name: Save Build Cache
uses: actions/cache/save@v4
if: ${{ always() && !steps.pre-check-previous-build.outputs.cache-hit && !steps.check-previous-build.outputs.cache-hit }}
with:
key: ${{ steps.restore-build-cache.outputs.cache-primary-key }}
path: |
${{ env.test_app_path }}/build
- name: Upload Build Log
uses: actions/[email protected]
if: ${{ always() && !steps.pre-check-previous-build.outputs.cache-hit && !steps.check-previous-build.outputs.cache-hit }}
with:
name: xcodebuild-${{ inputs.configuration }}.log
path: |
${{ env.test_app_path }}/xcodebuild.log