-
Notifications
You must be signed in to change notification settings - Fork 12
325 lines (278 loc) · 11.2 KB
/
ci.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
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
# ==================================================
# This is the main worflow for testing and building
# the app.
# The following is not yet implemented:
# - Use fastlane (?)
# - Obfuscate the build and remove debug symbols
# (https://docs.flutter.dev/deployment/obfuscate)
# ==================================================
name: CI
on:
push:
branches: [master, development]
pull_request:
types: [opened, synchronize]
workflow_dispatch:
env:
flutter_version: "3.7.1"
flutter_channel: "stable"
java_version: "12.x"
jobs:
analyze:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Fetch code from repository
uses: actions/checkout@v2
- name: Cache Flutter install
uses: actions/cache@v3
with:
path: /opt/hostedtoolcache/flutter
key: cache-flutter-${{ env.flutter_channel }}-${{ env.flutter_version }}-${{ runner.os }}
- name: Setup the Flutter environment
uses: subosito/flutter-action@v2
with:
channel: ${{ env.flutter_channel }}
flutter-version: ${{ env.flutter_version }}
- name: Get Flutter dependencies
run: flutter pub get .
- name: Check for any formatting issues
run: flutter format --dry-run --set-exit-if-changed .
- name: Build generated code
run: |
flutter pub run flutter_oss_licenses:generate.dart lib/presentation/licenses/oss_licenses.dart
flutter pub run build_runner build --delete-conflicting-outputs
- name: Cache files including generated
id: code-cache
uses: actions/cache@v3
with:
path: .
key: code-cache-${{ github.sha }}
- name: Statically analyze the Dart code
run: |
echo "" | base64 -d > .env
flutter analyze .
test:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Fetch code from repository
uses: actions/checkout@v2
- name: Cache Flutter install
uses: actions/cache@v3
with:
path: /opt/hostedtoolcache/flutter
key: cache-flutter-${{ env.flutter_channel }}-${{ env.flutter_version }}-${{ runner.os }}
- name: Setup the Flutter environment
uses: subosito/flutter-action@v2
with:
channel: ${{ env.flutter_channel }}
flutter-version: ${{ env.flutter_version }}
- name: Get Flutter dependencies
run: flutter pub get .
- name: Generate test file
run: ./.github/scripts/coverage_gen.sh
- name: Build generated code
run: |
flutter pub run flutter_oss_licenses:generate.dart lib/presentation/licenses/oss_licenses.dart
flutter pub run build_runner build --delete-conflicting-outputs
- name: Run tests and generate coverage
run: |
echo "" | base64 -d > .env
flutter test --coverage -r expanded .
- name: Upload coverage to codecov
uses: codecov/codecov-action@v3
with:
verbose: true
file: coverage/lcov.info
build_android:
if: ${{ github.ref == 'refs/heads/development' || github.ref == 'refs/heads/master' }}
environment: ${{ github.ref == 'refs/heads/master' && 'production' || 'development' }}
needs: [analyze, test]
runs-on: macos-latest
timeout-minutes: 60
steps:
- name: Fetch code from cache
id: code-cache
uses: actions/cache@v3
with:
path: .
key: code-cache-${{ github.sha }}
restore-keys: |
code-cache-${{ github.sha }}
code-cache-
code-cache
- name: Create release notes file
run: |
cat > release_notes.txt <<EOF
Run: $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID
Commit: $(git rev-parse --short HEAD)
Author: $(git log -1 --pretty=format:'%an')
Message: $(git log -1 --pretty=%B)
EOF
- name: Setup Java for Android
uses: actions/setup-java@v1
with:
java-version: ${{ env.java_version }}
- name: Cache Flutter install
uses: actions/cache@v3
with:
# Linux (deprecate):
# path: /opt/hostedtoolcache/flutter
# MacOS:
path: /Users/runner/hostedtoolcache/flutter
key: cache-flutter-${{ env.flutter_channel }}-${{ env.flutter_version }}-${{ runner.os }}
- name: Setup the Flutter environment
uses: subosito/flutter-action@v2
with:
channel: ${{ env.flutter_channel }}
flutter-version: ${{ env.flutter_version }}
- name: Get Flutter dependencies
run: flutter pub get .
- name: Generate app icons
run: flutter pub run flutter_launcher_icons:main
- name: Build appbundle
env:
GOOGLE_SERVICES_JSON: ${{ secrets.GOOGLE_SERVICES_JSON }}
run: |
echo ${{ secrets.ENV }} | base64 -d > .env
echo $GOOGLE_SERVICES_JSON | base64 -d > android/app/google-services.json
flutter build appbundle --release --build-number $GITHUB_RUN_NUMBER --no-tree-shake-icons
cp release_notes.txt build/app/outputs/
- name: Sign appbundle
uses: r0adkll/sign-android-release@v1
id: sign_appbundle
with:
releaseDirectory: build/app/outputs/bundle/release
signingKeyBase64: ${{ secrets.ANDROID_SIGNING_KEY }}
alias: ${{ secrets.ANDROID_ALIAS }}
keyStorePassword: ${{ secrets.ANDROID_KEY_STORE_PASSWORD }}
keyPassword: ${{ secrets.ANDROID_KEY_PASSWORD }}
- name: Upload android build artifacts
uses: actions/upload-artifact@v2
with:
name: android-release
path: |
${{steps.sign_appbundle.outputs.signedReleaseFile}}
build/app/outputs/logs
build/app/outputs/release_notes.txt
# Prerequisites for building iOS
# https://docs.github.com/en/actions/deployment/deploying-xcode-applications/installing-an-apple-certificate-on-macos-runners-for-xcode-development
build_ios:
if: ${{ github.ref == 'refs/heads/development' || github.ref == 'refs/heads/master' }}
environment: ${{ github.ref == 'refs/heads/master' && 'production' || 'development' }}
needs: [analyze, test]
runs-on: macos-latest
timeout-minutes: 60
steps:
- name: Fetch code from cache
id: code-cache
uses: actions/cache@v3
with:
path: .
key: code-cache-${{ github.sha }}
restore-keys: |
code-cache-${{ github.sha }}
code-cache-
code-cache
- name: Create release notes file
run: |
cat > release_notes.txt <<EOF
Run: $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID
Commit: $(git rev-parse --short HEAD)
Author: $(git log -1 --pretty=format:'%an')
Message: $(git log -1 --pretty=%B)
EOF
- name: Cache Flutter install
uses: actions/cache@v3
with:
# Linux (deprecate):
# path: /opt/hostedtoolcache/flutter
# MacOS:
path: /Users/runner/hostedtoolcache/flutter
key: cache-flutter-${{ env.flutter_channel }}-${{ env.flutter_version }}-${{ runner.os }}
- name: Setup the Flutter environment
uses: subosito/flutter-action@v2
with:
channel: ${{ env.flutter_channel }}
flutter-version: ${{ env.flutter_version }}
- name: Get Flutter dependencies
run: flutter pub get .
- name: Generate app icons
run: flutter pub run flutter_launcher_icons:main
- name: Install the Apple certificate and provisioning profile
env:
BUILD_CERTIFICATE_BASE64: ${{ secrets.IOS_CERT_P12 }}
P12_PASSWORD: ${{ secrets.IOS_P12_PASS }}
BUILD_PROVISION_PROFILE_BASE64: ${{ secrets.IOS_MOBILEPROVISION }}
KEYCHAIN_PASSWORD: ${{ secrets.IOS_P12_PASS }}
run: |
# create variables
CERTIFICATE_PATH=$RUNNER_TEMP/build_certificate.p12
PP_PATH=$RUNNER_TEMP/build_pp.mobileprovision
KEYCHAIN_PATH=$RUNNER_TEMP/app-signing.keychain-db
# import certificate and provisioning profile from secrets
echo -n "$BUILD_CERTIFICATE_BASE64" | base64 --decode --output $CERTIFICATE_PATH
echo -n "$BUILD_PROVISION_PROFILE_BASE64" | base64 --decode --output $PP_PATH
# create temporary keychain
security create-keychain -p "$KEYCHAIN_PASSWORD" $KEYCHAIN_PATH
security set-keychain-settings -lut 21600 $KEYCHAIN_PATH
security unlock-keychain -p "$KEYCHAIN_PASSWORD" $KEYCHAIN_PATH
# import certificate to keychain
security import $CERTIFICATE_PATH -P "$P12_PASSWORD" -A -t cert -f pkcs12 -k $KEYCHAIN_PATH
security list-keychain -d user -s $KEYCHAIN_PATH
# apply provisioning profile
mkdir -p ~/Library/MobileDevice/Provisioning\ Profiles
cp $PP_PATH ~/Library/MobileDevice/Provisioning\ Profiles
- name: Build iOS app
env:
IOS_GOOGLESERVICE_INFO_PLIST: ${{ secrets.IOS_GOOGLESERVICE_INFO_PLIST }}
run: |
echo ${{ secrets.ENV }} | base64 -d > .env
echo $IOS_GOOGLESERVICE_INFO_PLIST | base64 --decode > ios/Runner/GoogleService-Info.plist
flutter build ipa --release --export-options-plist=ExportOptions.plist --build-number $GITHUB_RUN_NUMBER --no-tree-shake-icons
cp release_notes.txt build/ios/ipa/
- name: Upload iOS build artifacts
uses: actions/upload-artifact@v2
with:
name: ios-release
path: |
build/ios/ipa/*.ipa
build/ios/ipa/release_notes.txt
- name: Clean up keychain and provisioning profile
run: |
security delete-keychain $RUNNER_TEMP/app-signing.keychain-db
rm ~/Library/MobileDevice/Provisioning\ Profiles/build_pp.mobileprovision
distribute_android:
environment: ${{ github.ref == 'refs/heads/master' && 'production' || 'development' }}
needs: [build_android]
runs-on: ubuntu-latest
steps:
- name: Download generated apk from the artifacts
uses: actions/download-artifact@v2
with:
name: android-release
- name: Upload generated apk to Firebase App Distribution
uses: wzieba/Firebase-Distribution-Github-Action@v1
with:
appId: ${{secrets.FIREBASE_ANDROID_APP_ID}}
serviceCredentialsFileContent: ${{ secrets.CREDENTIAL_FILE_CONTENT }}
groups: internal
file: bundle/release/app-release.aab
releaseNotesFile: release_notes.txt
distribute_ios:
environment: ${{ github.ref == 'refs/heads/master' && 'production' || 'development' }}
needs: [build_ios]
runs-on: macos-latest
steps:
- name: Download generated ipa from the artifacts
uses: actions/download-artifact@v2
with:
name: ios-release
- name: "Upload iOS app to TestFlight"
uses: apple-actions/upload-testflight-build@v1
with:
app-path: "CollAction.ipa"
issuer-id: ${{ secrets.IOS_APPSTORE_ISSUER_ID }}
api-key-id: ${{ secrets.IOS_APPSTORE_API_KEY_ID }}
api-private-key: ${{ secrets.IOS_APPSTORE_API_PRIVATE_KEY }}