-
-
Notifications
You must be signed in to change notification settings - Fork 12
401 lines (340 loc) · 13.7 KB
/
flutter-ci.yml
File metadata and controls
401 lines (340 loc) · 13.7 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
398
399
400
401
name: Flutter CI
permissions:
contents: write
on:
push:
branches: [master]
paths:
- 'client/**'
- '.github/workflows/flutter-ci.yml'
pull_request:
branches: [master]
paths:
- 'client/**'
- '.github/workflows/flutter-ci.yml'
workflow_dispatch:
env:
FLUTTER_WORKING_DIR: client
jobs:
test:
runs-on: ubuntu-latest
if: ${{ vars.BO_EDITION == 'ce' }}
defaults:
run:
working-directory: ${{ env.FLUTTER_WORKING_DIR }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Flutter
uses: subosito/flutter-action@v2
with:
channel: stable
flutter-version-file: client/pubspec.yaml
cache: true
- name: Cache pub dependencies
uses: actions/cache@v4
with:
path: ~/.pub-cache
key: ${{ runner.os }}-pub-cache-${{ hashFiles('client/pubspec.yaml', 'client/pubspec.lock', 'client/packages/*/pubspec.yaml') }}
restore-keys: ${{ runner.os }}-pub-cache-
- name: Add pub cache to PATH
run: echo "$HOME/.pub-cache/bin" >> $GITHUB_PATH
- name: Activate melos and bootstrap
run: |
dart pub global activate melos
melos bootstrap
- name: Run Melos format check
run: melos format --set-exit-if-changed .
- name: Run analyze
run: melos run analyze
- name: Run unit/widget tests
run: |
flutter test
melos run test:dart --no-select
- name: Install requirements for desktop integration tests and Linux builds)
run: sudo apt-get update && sudo apt-get install -y xvfb libgtk-3-dev libstdc++-12-dev
- name: Run linux integration tests
if: runner.os == 'Linux'
# desktop integration tests run on the same container; wrap in Xvfb
run: |
xvfb-run flutter test integration_test/app_test.dart -d linux -r github
get-version:
if: ${{ vars.BO_EDITION == 'ce' }}
runs-on: ubuntu-latest
outputs:
version: ${{ steps.extract.outputs.version }}
version_base: ${{ steps.extract.outputs.version_base }}
build_number: ${{ steps.extract.outputs.build_number }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Extract version & build number
id: extract
run: |
# read base version from pubspec (client folder)
VERSION_BASE=$(grep '^version:' client/pubspec.yaml | head -n1 | awk '{print $2}' | cut -d'+' -f1)
# use the workflow run number provided by GitHub Actions
BUILD_NUM="$GITHUB_RUN_NUMBER"
VERSION_PLUS="${VERSION_BASE}+${BUILD_NUM}"
echo "version_base=${VERSION_BASE}" >> $GITHUB_OUTPUT
echo "build_number=${BUILD_NUM}" >> $GITHUB_OUTPUT
echo "version=${VERSION_PLUS}" >> $GITHUB_OUTPUT
build-apk:
if: ${{ vars.BO_EDITION == 'ce' }}
needs: [test, get-version]
runs-on: ubuntu-latest
defaults:
run:
working-directory: ${{ env.FLUTTER_WORKING_DIR }}
outputs:
version: ${{ needs.get-version.outputs.version }}
version_base: ${{ needs.get-version.outputs.version_base }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Decode keystore from base64
shell: bash
run: |
printf "%s" "$KEYSTORE_BASE64" | base64 -d > android/app/keystore.jks
env:
KEYSTORE_BASE64: ${{ secrets.KEYSTORE_BASE64 }}
- name: Set up signing properties
run: |
cat > android/app/key.properties << EOF
storeFile=keystore.jks
keyAlias=${{ secrets.KEYSTORE_KEY_ALIAS }}
storePassword=${{ secrets.KEYSTORE_PASSWORD }}
keyPassword=${{ secrets.KEYSTORE_PASSWORD }}
EOF
- name: Validate Android keystore
shell: bash
run: |
keytool -list -keystore android/app/keystore.jks -storepass "$KEYSTORE_PASSWORD" -alias "$KEYSTORE_KEY_ALIAS"
env:
KEYSTORE_PASSWORD: ${{ secrets.KEYSTORE_PASSWORD }}
KEYSTORE_KEY_ALIAS: ${{ secrets.KEYSTORE_KEY_ALIAS }}
- name: Setup Flutter
uses: subosito/flutter-action@v2
with:
channel: stable
flutter-version-file: client/pubspec.yaml
cache: true
- name: Cache pub dependencies
uses: actions/cache@v4
with:
path: ~/.pub-cache
key: ${{ runner.os }}-pub-cache-${{ hashFiles('client/pubspec.yaml', 'client/pubspec.lock', 'client/packages/*/pubspec.yaml') }}
restore-keys: ${{ runner.os }}-pub-cache-
- name: Cache Gradle dependencies
uses: actions/cache@v4
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('client/**/*.gradle*', 'client/**/gradle-wrapper.properties') }}
restore-keys: ${{ runner.os }}-gradle-
- name: Add pub cache to PATH
run: echo "$HOME/.pub-cache/bin" >> $GITHUB_PATH
- name: Activate melos and bootstrap
run: |
dart pub global activate melos
melos bootstrap
- name: Get Flutter dependencies
run: flutter pub get
- name: Build APK
run: flutter build apk --release --target-platform android-arm64 --build-number ${{ needs.get-version.outputs.build_number }}
- name: Rename APK with version
run: |
mv build/app/outputs/flutter-apk/app-release.apk \
build/app/outputs/flutter-apk/borneo-app-ce-${{ needs.get-version.outputs.version }}.apk
- name: Upload APK artifact
uses: actions/upload-artifact@v4
with:
name: borneo-app-ce-${{ needs.get-version.outputs.version }}
path: ${{ github.workspace }}/${{ env.FLUTTER_WORKING_DIR }}/build/app/outputs/flutter-apk/borneo-app-ce-${{ needs.get-version.outputs.version }}.apk
build-windows:
if: ${{ vars.BO_EDITION == 'ce' }}
needs: [test, get-version]
runs-on: windows-latest
defaults:
run:
working-directory: ${{ env.FLUTTER_WORKING_DIR }}
outputs:
version: ${{ needs.get-version.outputs.version }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Flutter
uses: subosito/flutter-action@v2
with:
channel: stable
flutter-version-file: client/pubspec.yaml
cache: true
- name: Cache pub dependencies
uses: actions/cache@v4
with:
path: ~/.pub-cache
key: ${{ runner.os }}-pub-cache-${{ hashFiles('client/pubspec.yaml', 'client/pubspec.lock', 'client/packages/*/pubspec.yaml') }}
restore-keys: ${{ runner.os }}-pub-cache-
# Cache NuGet packages to speed MSBuild / CMake native deps
- name: Cache NuGet packages
uses: actions/cache@v4
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('client/windows/**') }}
restore-keys: ${{ runner.os }}-nuget-
- name: Cache MSBuild
uses: actions/cache@v4
with:
path: ~/AppData/Local/Microsoft/VisualStudio
key: ${{ runner.os }}-msbuild-${{ hashFiles('client/windows/**') }}
restore-keys: ${{ runner.os }}-msbuild-
# Pre-download Flutter engine/artifacts for Windows (avoid on-the-fly downloads)
- name: Flutter precache (windows)
run: flutter precache --windows
- name: Activate melos and bootstrap
run: |
dart pub global activate melos
melos bootstrap
- name: Get Flutter dependencies
run: flutter pub get
- name: Build Windows executable
run: flutter build windows --release --build-number ${{ needs.get-version.outputs.build_number }}
- name: Create and zip Windows release
run: |
pwsh ./scripts/windows-dist-pack.ps1 ce-${{ needs.get-version.outputs.version }}
- name: Upload Windows zip artifact
uses: actions/upload-artifact@v4
with:
name: borneo-app-ce-${{ needs.get-version.outputs.version }}-windows-x64
path: client/build/windows/dist/borneo-app-ce-${{ needs.get-version.outputs.version }}-windows-x64.zip
build-ios:
if: ${{ vars.BO_EDITION == 'ce' }}
needs: [test, get-version]
runs-on: macos-14
defaults:
run:
working-directory: ${{ env.FLUTTER_WORKING_DIR }}
outputs:
version: ${{ needs.get-version.outputs.version }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Flutter
uses: subosito/flutter-action@v2
with:
channel: stable
flutter-version-file: client/pubspec.yaml
cache: true
- name: Cache pub dependencies
uses: actions/cache@v4
with:
path: ~/.pub-cache
key: ${{ runner.os }}-pub-cache-${{ hashFiles('client/pubspec.yaml', 'client/pubspec.lock', 'client/packages/*/pubspec.yaml') }}
restore-keys: ${{ runner.os }}-pub-cache-
- name: Cache CocoaPods
uses: actions/cache@v4
with:
path: |
~/.cocoapods
~/Library/Caches/CocoaPods
${{ github.workspace }}/client/ios/Pods
key: ${{ runner.os }}-pods-${{ hashFiles('client/ios/Podfile.lock') }}
restore-keys: ${{ runner.os }}-pods-
- name: Flutter precache (iOS)
run: flutter precache --ios
- name: Activate melos and bootstrap
run: |
dart pub global activate melos
melos bootstrap
- name: Get Flutter dependencies
run: flutter pub get
- name: Build iOS app (no codesign)
run: flutter build ios --release --no-codesign --build-number ${{ needs.get-version.outputs.build_number }}
release:
needs: [build-apk, build-windows, build-ios]
runs-on: ubuntu-latest
if: ${{ github.ref == 'refs/heads/master' && vars.BO_EDITION == 'ce' }}
steps:
- name: Download artifacts
uses: actions/download-artifact@v4
with:
path: ./release-artifacts
merge-multiple: true
- name: Set prerelease flag
id: set_prerelease
run: |
if [[ "${{ needs.build-apk.outputs.version }}" == *beta* || "${{ needs.build-apk.outputs.version }}" == *alpha* ]]; then
echo "prerelease=true" >> $GITHUB_OUTPUT
else
echo "prerelease=false" >> $GITHUB_OUTPUT
fi
- name: Create latest asset aliases
run: |
cp \
"release-artifacts/borneo-app-ce-${{ needs.build-apk.outputs.version }}.apk" \
"release-artifacts/borneo-app-ce-latest.apk"
cp \
"release-artifacts/borneo-app-ce-${{ needs.build-windows.outputs.version }}-windows-x64.zip" \
"release-artifacts/borneo-app-ce-latest.windows-x64.zip"
- name: Create Versionized GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: app-ce-v${{ needs.build-apk.outputs.version_base }}
name: Borneo-IoT App Release app-ce-v${{ needs.build-apk.outputs.version_base }}
draft: false
overwrite_files: true
prerelease: ${{ steps.set_prerelease.outputs.prerelease }}
files: |
release-artifacts/borneo-app-ce-${{ needs.build-apk.outputs.version }}.apk
release-artifacts/borneo-app-ce-${{ needs.build-windows.outputs.version }}-windows-x64.zip
- name: Delete previous latest app release and tag
uses: actions/github-script@v8
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const tag = 'release-app-latest';
const refName = `tags/${tag}`;
const fullRef = `refs/tags/${tag}`;
// Delete the release first (while tag still points to old SHA, so getReleaseByTag works)
try {
const rel = await github.rest.repos.getReleaseByTag({ owner: context.repo.owner, repo: context.repo.repo, tag });
await github.rest.repos.deleteRelease({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: rel.data.id,
});
console.log('Deleted previous latest app release.');
} catch (err) {
if (err.status === 404) {
console.log('Latest app release not found, nothing to delete.');
} else {
throw err;
}
}
// Then delete and recreate the tag pointing to the current commit
try {
await github.rest.git.deleteRef({ owner: context.repo.owner, repo: context.repo.repo, ref: refName });
console.log(`Deleted existing tag ${tag}`);
} catch (err) {
// GitHub returns 404 _or_ 422 when the tag doesn't exist; ignore both
if (err.status === 404 || err.status === 422) {
console.log(`Tag ${tag} did not exist, proceeding to create`);
} else {
throw err;
}
}
await github.rest.git.createRef({ owner: context.repo.owner, repo: context.repo.repo, ref: fullRef, sha: context.sha });
console.log(`Created tag ${tag} pointing to ${context.sha}`);
- name: Create GitHub Latest App Release
uses: softprops/action-gh-release@v2
with:
tag_name: release-app-latest
name: Latest App Release
draft: false
overwrite_files: true
files: |
release-artifacts/borneo-app-ce-${{ needs.build-apk.outputs.version }}.apk
release-artifacts/borneo-app-ce-latest.apk
release-artifacts/borneo-app-ce-${{ needs.build-windows.outputs.version }}-windows-x64.zip
release-artifacts/borneo-app-ce-latest.windows-x64.zip