-
Notifications
You must be signed in to change notification settings - Fork 2
257 lines (246 loc) · 8.84 KB
/
main.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
name: CI
on:
push:
branches:
- "master"
pull_request:
release:
types: [published]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
flutter_version: "3.22.2"
flutter_channel: "stable"
jobs:
test:
name: Test
runs-on: ubuntu-latest
outputs:
environment: ${{ steps.setVersion.outputs.environment }}
version: ${{ steps.setVersion.outputs.version }}
release: ${{ steps.setVersion.outputs.release }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set build version
id: setVersion
run: |
VERSION_STRING=$(cat pubspec.yaml | grep -oP "^version: .+" | cut -d" " -f2)
VERSION=$(echo $VERSION_STRING | cut -d"+" -f1)
BUILD_NUMBER=$(echo $VERSION_STRING | cut -d"+" -f2)
COMMIT_ID=$(git rev-parse --short HEAD)
if [[ "${{github.event_name}}" == "release" && "${{github.event.action}}" == "published" ]]; then
echo "environment=prod" >> $GITHUB_OUTPUT
echo "version=$VERSION+$BUILD_NUMBER" >> $GITHUB_OUTPUT
echo "release=xyz.hehome.smarthome@$VERSION+$BUILD_NUMBER" >> $GITHUB_OUTPUT
else
echo "environment=dev" >> $GITHUB_OUTPUT
echo "version=$VERSION-git.$COMMIT_ID+$BUILD_NUMBER" >> $GITHUB_OUTPUT
echo "release=xyz.hehome.smarthome.dev@$VERSION-git.$COMMIT_ID+$BUILD_NUMBER" >> $GITHUB_OUTPUT
fi
- name: Get lcov_cobertura
run: curl -sSL https://raw.github.com/eriwen/lcov-to-cobertura-xml/master/lcov_cobertura/lcov_cobertura.py -o lcov_cobertura.py
- name: Setup Flutter
uses: subosito/flutter-action@44ac965b96f18d999802d4b807e3256d5a3f9fa1
with:
flutter-version: ${{ env.flutter_version }}
channel: ${{ env.flutter_channel }}
cache: true
- name: Flutter test
run: |
flutter pub get
flutter test --coverage
python lcov_cobertura.py coverage/lcov.info
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
android:
name: Android
runs-on: ubuntu-latest
needs: test
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set version name
run: |
sed -ri "s#^version: .+#version: $VERSION#g" pubspec.yaml
env:
VERSION: ${{ needs.test.outputs.version }}
- name: Decrypt large secret
run: ./.github/scripts/decrypt_secret.sh
env:
LARGE_SECRET_PASSPHRASE: ${{ secrets.LARGE_SECRET_PASSPHRASE }}
# https://github.com/incrediblezayed/file_saver/issues/86#issuecomment-2028079330
- name: Setup Java
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: '17'
cache: 'gradle'
check-latest: true
- name: Setup Flutter
uses: subosito/flutter-action@44ac965b96f18d999802d4b807e3256d5a3f9fa1
with:
flutter-version: ${{ env.flutter_version }}
channel: ${{ env.flutter_channel }}
cache: true
- name: Build split-per-abi apks
run: flutter build apk --target-platform android-arm64,android-x64 --split-per-abi -t ./lib/main_$ENVIRONMENT.dart --flavor $ENVIRONMENT
env:
ENVIRONMENT: ${{ needs.test.outputs.environment }}
SENTRY_RELEASE: ${{ needs.test.outputs.release }}
SENTRY_DSN: ${{ secrets.SENTRY_DSN }}
- name: Upload split-per-abi apks
uses: actions/upload-artifact@v4
if: github.event_name != 'pull_request'
with:
name: android
path: ${{ github.workspace }}/build/app/outputs/apk/${{ needs.test.outputs.environment }}/release/*.apk
web:
name: Web
runs-on: ubuntu-latest
needs: test
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set version name
run: |
sed -ri "s#^version: .+#version: $VERSION#g" pubspec.yaml
env:
VERSION: ${{ needs.test.outputs.version }}
- name: Setup Flutter
uses: subosito/flutter-action@44ac965b96f18d999802d4b807e3256d5a3f9fa1
with:
flutter-version: ${{ env.flutter_version }}
channel: ${{ env.flutter_channel }}
cache: true
- name: Build web version
run: |
flutter build web --web-renderer=html --source-maps -t ./lib/main_$ENVIRONMENT.dart
env:
ENVIRONMENT: ${{ needs.test.outputs.environment }}
SENTRY_RELEASE: ${{ needs.test.outputs.release }}
SENTRY_DSN: ${{ secrets.SENTRY_DSN }}
- name: Upload web version
uses: actions/upload-artifact@v4
if: github.event_name != 'pull_request'
with:
name: web
path: ${{ github.workspace }}/build/web
- name: Upload debug symbols
if: github.event_name != 'pull_request'
run: dart run sentry_dart_plugin
env:
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
SENTRY_ORG: ${{ secrets.SENTRY_ORG }}
SENTRY_PROJECT: ${{ secrets.SENTRY_PROJECT }}
windows:
name: Windows
runs-on: windows-latest
needs: test
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set version name
run: |
sed -ri "s#^version: .+#version: $VERSION#g" pubspec.yaml
env:
VERSION: ${{ needs.test.outputs.version }}
- name: Setup Flutter
uses: subosito/flutter-action@44ac965b96f18d999802d4b807e3256d5a3f9fa1
with:
flutter-version: ${{ env.flutter_version }}
channel: ${{ env.flutter_channel }}
cache: true
- name: Build windows version
run: |
flutter build windows -t ./lib/main_${env:ENVIRONMENT}.dart
env:
ENVIRONMENT: ${{ needs.test.outputs.environment }}
SENTRY_RELEASE: ${{ needs.test.outputs.release }}
SENTRY_DSN: ${{ secrets.SENTRY_DSN }}
- name: Upload windows version
uses: actions/upload-artifact@v4
if: github.event_name != 'pull_request'
with:
name: windows
path: ${{ github.workspace }}/build/windows/x64/runner/Release
deploy_web_dev:
name: Deploy Web Dev
runs-on: ubuntu-latest
needs: web
environment:
name: dev
url: https://smart.dev.hehome.xyz
if: github.event_name != 'pull_request'
steps:
- name: Download web files
uses: actions/download-artifact@v4
with:
name: web
- name: Copy file to server
uses: Burnett01/rsync-deployments@796cf0d5e4b535745ce49d7429f77cf39e25ef39
with:
switches: -vzr --delete --exclude ".well-known"
path: "."
remote_path: ${{ secrets.WEBSITES_ROOT }}/smart-home/web
remote_host: ${{ secrets.SSH_HOST }}
remote_user: ${{ secrets.SSH_USERNAME }}
remote_key: ${{ secrets.SSH_KEY }}
deploy_web_prod:
name: Deploy Web Prod
runs-on: ubuntu-latest
needs: web
environment:
name: prod
url: https://smart.hehome.xyz
if: ${{ github.event_name == 'release' && github.event.action == 'published' }}
steps:
- name: Download web files
uses: actions/download-artifact@v4
with:
name: web
- name: Copy file to server
uses: Burnett01/rsync-deployments@796cf0d5e4b535745ce49d7429f77cf39e25ef39
with:
switches: -vzr --delete --exclude ".well-known"
path: "."
remote_path: ${{ secrets.WEBSITES_ROOT }}/smart-home/web
remote_host: ${{ secrets.SSH_HOST }}
remote_user: ${{ secrets.SSH_USERNAME }}
remote_key: ${{ secrets.SSH_KEY }}
deploy_github:
name: Deploy Github
runs-on: ubuntu-latest
needs: [android, web, windows]
if: ${{ github.event_name == 'release' && github.event.action == 'published' }}
steps:
- name: Download artifacts
uses: actions/download-artifact@v4
- name: Compress files
run: |
tar -czvf web.tar.gz web
tar -czvf windows.tar.gz windows
- name: Upload Release Assets
uses: alexellis/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
asset_paths: '["android/*.apk", "web.tar.gz", "windows.tar.gz"]'
sentry_release:
name: Sentry Release
runs-on: ubuntu-latest
needs: [test, android, web, windows]
if: github.event_name != 'pull_request'
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Create Sentry release
uses: getsentry/action-release@v1
env:
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
SENTRY_ORG: ${{ secrets.SENTRY_ORG }}
SENTRY_PROJECT: ${{ secrets.SENTRY_PROJECT }}
with:
environment: ${{ needs.test.outputs.environment }}
version: ${{ needs.test.outputs.version }}