-
Notifications
You must be signed in to change notification settings - Fork 93
213 lines (213 loc) · 9.79 KB
/
rnx-build.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
name: rnx-build
on:
workflow_dispatch:
inputs:
architecture:
description: Supported architectures are `arm64`, `x64`
required: true
default: x64
deviceType:
description: Supported device types are `device`, `emulator`, `simulator`
required: true
default: simulator
distribution:
description: Distribution config string, e.g. `local` or `firebase:<appId>`
required: true
default: local
packageManager:
description: Binary name of the package manager used in the current repo
required: true
default: yarn
platform:
description: Supported platforms are `android`, `ios`, `macos`, `windows`
required: true
projectRoot:
description: Root of the project
required: true
scheme:
description: The workspace scheme to build (iOS and macOS only)
default: ReactTestApp
jobs:
build-android:
name: Build Android
if: ${{ github.event.inputs.platform == 'android' }}
runs-on: ubuntu-24.04
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up toolchain
uses: microsoft/react-native-test-app/.github/actions/setup-toolchain@trunk
with:
platform: android
cache-npm-dependencies: ${{ github.event.inputs.packageManager }}
- name: Install npm dependencies
run: ${{ github.event.inputs.packageManager }} install
- name: Build Android app
uses: gradle/actions/setup-gradle@v4
with:
gradle-version: wrapper
arguments: --no-daemon clean assembleDebug
build-root-directory: ${{ github.event.inputs.projectRoot }}/android
- name: Upload build artifact
uses: actions/upload-artifact@v4
with:
name: android-artifact
path: ${{ github.event.inputs.projectRoot }}/android/app/build/outputs/apk/debug/app-debug.apk
if-no-files-found: error
retention-days: 14
build-ios:
name: Build iOS
if: ${{ github.event.inputs.platform == 'ios' }}
runs-on: macos-14
env:
CERTIFICATE_FILE: build-certificate.p12
KEYCHAIN_FILE: app-signing.keychain-db
PROVISION_PATH: "Library/MobileDevice/Provisioning Profiles/Provisioning_Profile.mobileprovision"
XCARCHIVE_FILE: app.xcarchive
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up toolchain
uses: microsoft/react-native-test-app/.github/actions/setup-toolchain@trunk
with:
platform: ios
project-root: ${{ github.event.inputs.projectRoot }}
cache-npm-dependencies: ${{ github.event.inputs.packageManager }}
- name: Install npm dependencies
run: ${{ github.event.inputs.packageManager }} install
- name: Install Pods
run: pod install --project-directory=ios --verbose
working-directory: ${{ github.event.inputs.projectRoot }}
- name: Install Apple signing certificate and provisioning profile
if: ${{ github.event.inputs.deviceType == 'device' }}
env:
BUILD_CERTIFICATE_BASE64: ${{ secrets.BUILD_CERTIFICATE_BASE64 }}
BUILD_PROVISION_PROFILE_BASE64: ${{ secrets.BUILD_PROVISION_PROFILE_BASE64 }}
KEYCHAIN_PASSWORD: ${{ secrets.KEYCHAIN_PASSWORD }}
P12_PASSWORD: ${{ secrets.P12_PASSWORD }}
run: npx --prefix . rnx-build-apple install-certificate
- name: Build iOS app
run: npx --prefix . rnx-build-apple build-ios --scheme ${{ github.event.inputs.scheme }} --device-type ${{ github.event.inputs.deviceType }} --archs ${{ github.event.inputs.architecture }}
working-directory: ${{ github.event.inputs.projectRoot }}/ios
- name: Remove Apple signing certificate and provisioning profile
# Always run this job step, even if previous ones fail. See also
# https://docs.github.com/en/actions/deployment/deploying-xcode-applications/installing-an-apple-certificate-on-macos-runners-for-xcode-development#required-clean-up-on-self-hosted-runners
if: ${{ always() && github.event.inputs.deviceType == 'device' }}
run: npx --prefix . rnx-build-apple uninstall-certificate
- name: Prepare build artifact
id: prepare-build-artifact
run: |
if [[ ${{ github.event.inputs.distribution }} == 'local' ]]; then
app=$(find ${XCARCHIVE_FILE}/Products/Applications -maxdepth 1 -name '*.app' -type d | head -1)
npx --prefix . rnx-build-apple archive ios-artifact.tar "${app}"
echo 'filename=ios-artifact.tar' >> $GITHUB_OUTPUT
else
xcodebuild -exportArchive -archivePath ${XCARCHIVE_FILE} -exportPath export -exportOptionsPlist ExportOptions.plist 2>&1
ipa=$(find export -maxdepth 1 -name '*.ipa' -type d | head -1)
echo "filename=${ipa}" >> $GITHUB_OUTPUT
fi
working-directory: ${{ github.event.inputs.projectRoot }}/ios
- name: Upload build artifact
uses: actions/upload-artifact@v4
with:
name: ios-artifact
path: ${{ github.event.inputs.projectRoot }}/ios/${{ steps.prepare-build-artifact.outputs.filename }}
if-no-files-found: error
retention-days: 14
build-macos:
name: Build macOS
if: ${{ github.event.inputs.platform == 'macos' }}
runs-on: macos-14
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up toolchain
uses: microsoft/react-native-test-app/.github/actions/setup-toolchain@trunk
with:
platform: macos
project-root: ${{ github.event.inputs.projectRoot }}
cache-npm-dependencies: ${{ github.event.inputs.packageManager }}
- name: Install npm dependencies
run: ${{ github.event.inputs.packageManager }} install
- name: Install Pods
run: pod install --project-directory=macos --verbose
working-directory: ${{ github.event.inputs.projectRoot }}
- name: Build macOS app
run: npx --prefix . rnx-build-apple build-macos --scheme ${{ github.event.inputs.scheme }}
working-directory: ${{ github.event.inputs.projectRoot }}/macos
- name: Prepare build artifact
run: |
output_path=DerivedData/Build/Products
app=$(find ${output_path} -maxdepth 2 -name '*.app' -type d | head -1)
npx --prefix . rnx-build-apple archive macos-artifact.tar "${app}"
working-directory: ${{ github.event.inputs.projectRoot }}/macos
- name: Upload build artifact
uses: actions/upload-artifact@v4
with:
name: macos-artifact
path: ${{ github.event.inputs.projectRoot }}/macos/macos-artifact.tar
if-no-files-found: error
retention-days: 14
build-windows:
name: Build Windows
if: ${{ github.event.inputs.platform == 'windows' }}
runs-on: windows-2022
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up toolchain
uses: microsoft/react-native-test-app/.github/actions/setup-toolchain@trunk
with:
platform: windows
cache-npm-dependencies: ${{ github.event.inputs.packageManager }}
- name: Install npm dependencies
run: ${{ github.event.inputs.packageManager }} install
- name: Install Windows test app
run: |
npx --package react-native-test-app -- install-windows-test-app --use-nuget
working-directory: ${{ github.event.inputs.projectRoot }}
- name: Install NuGet packages
run: |
nuget restore
working-directory: ${{ github.event.inputs.projectRoot }}/windows
- name: Build Windows app
run: |
MSBuild -maxCpuCount -property:Configuration=Debug -property:Platform=${{ github.event.inputs.architecture }} -property:AppxBundlePlatforms=${{ github.event.inputs.architecture }} -property:AppxBundle=Always -property:UapAppxPackageBuildMode=SideloadOnly -property:UseBundle=false -target:Build
working-directory: ${{ github.event.inputs.projectRoot }}/windows
- name: Prepare build artifact
id: prepare-build-artifact
run: |
appx_manifest=$(find ${{ github.event.inputs.architecture }}/Debug -name AppxManifest.xml -type f | head -1)
app_name=$(basename $(dirname ${appx_manifest}))
cp ${appx_manifest} AppPackages/${app_name}/*
echo "app-name=${app_name}" >> $GITHUB_OUTPUT
shell: bash
working-directory: ${{ github.event.inputs.projectRoot }}/windows
- name: Upload build artifact
uses: actions/upload-artifact@v4
with:
name: windows-artifact
path: ${{ github.event.inputs.projectRoot }}/windows/AppPackages/${{ steps.prepare-build-artifact.outputs.app-name }}
if-no-files-found: error
retention-days: 14
distribute:
name: Distribute build
needs: [build-android, build-ios]
runs-on: ubuntu-24.04
if: ${{ github.event.inputs.distribution != 'local' && !cancelled() && !failure() }} # `success()` excludes skipped jobs
steps:
- name: Download build artifact
uses: actions/download-artifact@v4
with:
name: ${{ github.event.inputs.platform }}-artifact
- name: Display structure of build artifact
run: ls -R
- name: Upload to Firebase
if: ${{ startsWith(github.event.inputs.distribution, 'firebase:') }}
env:
FIREBASE_APP_ID: ${{ github.event.inputs.distribution }}
GOOGLE_APPLICATION_CREDENTIALS: credentials.json
run: |
artifact=$(find . -maxdepth 1 -type f | head -1)
echo -n "${{ secrets.GOOGLE_APPLICATION_CREDENTIALS_BASE64 }}" | base64 --decode > ${GOOGLE_APPLICATION_CREDENTIALS}
npx --package firebase-tools@11 firebase appdistribution:distribute "${artifact}" --app ${FIREBASE_APP_ID:9} --release-notes "${{ github.ref_name }}"