-
Notifications
You must be signed in to change notification settings - Fork 19
317 lines (308 loc) · 11.3 KB
/
build.yaml
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
name: Fastlane
on:
push:
branches:
- main
tags:
- "v*"
pull_request:
types:
- opened
- reopened
- synchronize
workflow_dispatch: # allow manual run
inputs:
push_to_testflight:
type: boolean
description: Upload to TestFlight
required: true
default: false
push_to_playstore:
type: choice
description: Push to PlayStore
options:
- 'false'
- internal
- beta
- production
required: true
version:
type: string
description: App version (vXX.YY.ZZ)
required: true
default: LATEST
build_piece:
type: string
description: Build piece (last 2 digits of build_no)
required: true
jobs:
configure:
name: Configure
runs-on: ubuntu-latest
outputs:
version: ${{ steps.configure.outputs.version }}
build_no: ${{ steps.configure.outputs.build_no }}
push_to_testflight: ${{ steps.configure.outputs.push_to_testflight }}
push_to_playstore: ${{ steps.configure.outputs.push_to_playstore }}
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Get version from tag (new release)
id: tag_version
run: echo "version=${{ github.ref_name }}" >> $GITHUB_OUTPUT
if: |
github.event_name == 'push' &&
github.event.repository.full_name == github.repository &&
github.ref_type == 'tag'
- name: Get version from last release
id: last_release
uses: pozetroninc/github-action-get-latest-release@master
with:
repository: ${{ github.repository }}
excludes: draft
token: ${{ secrets.GITHUB_TOKEN }}
- name: Gather workflow info
id: configure
run: |
VERSION=""
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
# On pull_request event, no need to publish
PUSH_TESTFLIGHT=false
PUSH_PLAYSTORE=false
elif [[ "${{ steps.tag_version.outputs.version }}" != "" ]]; then
# On tag push (release), we're in production
PUSH_TESTFLIGHT=true
PUSH_PLAYSTORE="${{ vars.PLAYSTORE_RELEASE_TRACK }}"
VERSION="${{ steps.tag_version.outputs.version }}"
BUILD_PIECE=0
elif [[ "${{ github.event.inputs.version }}" != "" ]]; then
# On repo manual dispatch
PUSH_TESTFLIGHT="${{ github.event.inputs.push_to_testflight }}"
PUSH_PLAYSTORE="${{ github.event.inputs.push_to_playstore }}"
if [[ "${{ github.event.inputs.version }}" == "LATEST" && "${{ steps.last_release.outputs.release }}" != "" ]]; then
VERSION="${{ steps.last_release.outputs.release }}"
else
VERSION="${{ github.event.inputs.version }}"
fi
BUILD_PIECE="${{ github.event.inputs.build_piece }}"
elif [[ "${{ steps.last_release.outputs.release }}" != "" ]]; then
# we're supposed to be on push on main (e.g. pr merge) here
PUSH_TESTFLIGHT=true
PUSH_PLAYSTORE=beta
VERSION="${{ steps.last_release.outputs.release }}"
BUILD_PIECE=$(git rev-list $VERSION.. --count)
else
echo "UNHANDLED EVENT. CANNOT CONFIG SAFELY."
exit 1
fi
if [[ "$BUILD_PIECE" != "" && ! "$BUILD_PIECE" =~ ^[0-9]{1,2}$ ]]; then
echo "INVALID BUILD PIECE FORMAT: $BUILD_PIECE"
exit 1
fi
if [[ "$VERSION" =~ ^v([0-9]{1,2})\.([0-9]{1,2})\.([0-9]{1,2})$ ]]; then
MAJOR=${BASH_REMATCH[1]}
MINOR=${BASH_REMATCH[2]}
SUBV=${BASH_REMATCH[3]}
BUILD_NO=$(( MAJOR*1000000 + MINOR*10000 + SUBV*100 + BUILD_PIECE ))
echo "build_no=$BUILD_NO" >> $GITHUB_OUTPUT
echo "version=$MAJOR.$MINOR.$SUBV" >> $GITHUB_OUTPUT
elif [[ "$VERSION" != "" ]]; then
echo "INVALID VERSION FORMAT: $VERSION"
exit 2
fi
echo "push_to_playstore=$PUSH_PLAYSTORE" >> $GITHUB_OUTPUT
echo "push_to_testflight=$PUSH_TESTFLIGHT" >> $GITHUB_OUTPUT
echo "CONFIGURED:"
cat $GITHUB_OUTPUT
- name: Cache node modules
uses: actions/cache@v3
with:
path: ./node_modules
key: ${{ runner.os }}-npm-${{ hashFiles('./package-lock.json') }}
- name: Setup .npmrc
run: printf '@polito:registry=https://npm.pkg.github.com\n//npm.pkg.github.com/:_authToken=${{ secrets.GITHUB_TOKEN }}\n' > .npmrc
- name: Install npm dependencies
run: npm install
build-android:
name: ${{ needs.configure.outputs.push_to_playstore == 'false' && 'Build' || 'Build & Deploy' }} Android
needs: configure
runs-on: ubuntu-latest
env:
LANG: en_US.UTF-8
CI: 'true'
BUILD_NO: ${{ needs.configure.outputs.build_no }}
APP_VERSION: ${{ needs.configure.outputs.version }}
SUPPLY_GOOGLE_JSON_PATH: './pc-api-secret.json'
KEYSTORE_PW: ${{ secrets.ANDROID_KEYSTORE_PW }}
KEYSTORE_PATH: './keystore.jks'
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set .env
run:
echo "MAPBOX_TOKEN=${{ secrets.MAPBOX_TOKEN }}" >> .env
- name: Set local.properties
run:
echo "MAPBOX_DOWNLOADS_TOKEN=${{ secrets.MAPBOX_TOKEN }}" >> android/local.properties
- name: Gradle Wrapper Validation
uses: gradle/wrapper-validation-action@v1
- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
working-directory: ./android
ruby-version: '2.7.6'
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: 16
- name: Cache node modules
uses: actions/cache@v3
with:
path: ./node_modules
key: ${{ runner.os }}-npm-${{ hashFiles('./package-lock.json') }}
- name: Cache Gradle artifacts
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: ${{ runner.os }}-gradle-
- name: Setup .npmrc
run: printf '@polito:registry=https://npm.pkg.github.com\n//npm.pkg.github.com/:_authToken=${{ secrets.GITHUB_TOKEN }}\n' > .npmrc
- name: Install npm dependencies
run: npm install
- name: Prepare fastlane
working-directory: ./android
run: |
echo "${{ secrets.SUPPLY_GOOGLE_JSON_SECRET }}" | base64 -d > ${SUPPLY_GOOGLE_JSON_PATH}
echo "${{ secrets.ANDROID_KEYSTORE_B64 }}" | base64 -d > ${KEYSTORE_PATH}
chmod 600 ${KEYSTORE_PATH} ${SUPPLY_GOOGLE_JSON_PATH}
- name: Fastlane VERIFY lane
if: needs.configure.outputs.push_to_playstore == 'false'
working-directory: ./android
run: bundle exec fastlane verify
- name: Fastlane RELEASE lane
if: contains(fromJSON('["internal", "beta", "production"]'), needs.configure.outputs.push_to_playstore)
working-directory: ./android
env:
STORE_TRACK: ${{ needs.configure.outputs.push_to_playstore }}
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
SENTRY_PROJECT: ${{ vars.SENTRY_PROJECT }}
SENTRY_ORG: ${{ vars.SENTRY_ORG }}
run: bundle exec fastlane release
- name: Fastlane APK lane
if: |
github.event_name == 'push' &&
github.ref_type == 'tag'
run: bundle exec fastlane apk
working-directory: ./android
- name: Upload Artifacts
if: |
github.event_name == 'push' &&
github.ref_type == 'tag'
uses: actions/upload-artifact@v3
with:
name: android-release
path: android/app/build/outputs/apk/release/*.apk
build-ios:
name: ${{ needs.configure.outputs.push_to_testflight == 'false' && 'Build' || 'Build & Deploy' }} iOS
env:
ImageOS: macos12
LANG: en_US.UTF-8
CI: 'true'
BUILD_NO: ${{ needs.configure.outputs.build_no }}
APP_VERSION: ${{ needs.configure.outputs.version }}
MATCH_PASSWORD: ${{ secrets.FASTLANE_MATCH_KEY }}
MATCH_GIT_PRIVATE_KEY: "./github_access.pk"
FASTLANE_USERNAME: ${{ secrets.FASTLANE_POLI_MOBILE_USER }}
FASTLANE_PASSWORD: ${{ secrets.FASTLANE_POLI_MOBILE_PW }}
FASTLANE_APPLE_APPLICATION_SPECIFIC_PASSWORD: ${{ secrets.FASTLANE_APPLE_DEV_PW }}
SUPPLY_GOOGLE_SERVICE_INFO_PLIST_PATH: "./GoogleService-Info.plist"
needs: configure
runs-on: [self-hosted, macos-12]
steps:
- name: Select Xcode
uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: '14'
- name: Checkout
uses: actions/checkout@v3
- name: Set .env
run:
echo "MAPBOX_TOKEN=${{ secrets.MAPBOX_TOKEN }}" >> .env
- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
working-directory: ./ios
ruby-version: '2.7.6'
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: 16
- name: Cache node modules
uses: actions/cache@v3
with:
path: ./node_modules
key: ${{ runner.os }}-npm-${{ hashFiles('./package-lock.json') }}
- name: Setup .npmrc
run: printf '@polito:registry=https://npm.pkg.github.com\n//npm.pkg.github.com/:_authToken=${{ secrets.GITHUB_TOKEN }}\n' > .npmrc
- name: Install npm dependencies
run: npm install
- name: Cache pods
uses: actions/cache@v3
with:
path: ./ios/Pods
key: ${{ runner.os }}-pods-${{ hashFiles('**/Podfile.lock') }}
- name: Install pod dependencies
working-directory: ./ios
run: bundle exec pod install --repo-update
- name: Prepare fastlane
working-directory: ./ios
run: |
echo "${{ secrets.MATCH_GIT_AUTH_PK }}" > ${MATCH_GIT_PRIVATE_KEY}
chmod 600 ${MATCH_GIT_PRIVATE_KEY}
echo "${{ secrets.SUPPLY_GOOGLE_SERVICE_INFO_PLIST }}" | base64 -d > ${SUPPLY_GOOGLE_SERVICE_INFO_PLIST_PATH}
chmod 600 ${MATCH_GIT_PRIVATE_KEY} ${SUPPLY_GOOGLE_SERVICE_INFO_PLIST_PATH}
- name: Fastlane VERIFY lane
if: needs.configure.outputs.push_to_testflight == 'false'
working-directory: ./ios
run: |
bundle exec fastlane verify
- name: Fastlane RELEASE lane
if: needs.configure.outputs.push_to_testflight == 'true'
working-directory: ./ios
env:
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
SENTRY_PROJECT: ${{ vars.SENTRY_PROJECT }}
SENTRY_ORG: ${{ vars.SENTRY_ORG }}
run: |
bundle exec fastlane release
create-release:
name: Create GitHub Release
permissions:
contents: write
if: |
github.event_name == 'push' &&
github.event.repository.full_name == github.repository &&
github.ref_type == 'tag'
needs: [build-android, build-ios]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Gather artifacts
uses: actions/download-artifact@v3
with:
name: android-release
path: ./android-release
- name: Create release
uses: ncipollo/release-action@v1
with:
generateReleaseNotes: true
skipIfReleaseExists: true
artifacts: ./android-release/*.apk