-
Notifications
You must be signed in to change notification settings - Fork 0
329 lines (272 loc) · 10.2 KB
/
Copy pathflutter.yml
File metadata and controls
329 lines (272 loc) · 10.2 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
name: Flutter Build & Release
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
workflow_dispatch:
permissions:
contents: write
checks: write
pull-requests: write
packages: write
env:
WEB_ARTIFACT_NAME: tablemaster-web-prod.zip
IMAGE_NAME: ghcr.io/${{ github.repository_owner }}/tablemaster-mobile-web
jobs:
build-and-test:
runs-on: ubuntu-latest
strategy:
matrix:
flutter-version: ['3.38.9']
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Flutter
uses: subosito/flutter-action@v2
with:
flutter-version: ${{ matrix.flutter-version }}
channel: stable
cache: true
- name: Show Flutter version
run: flutter --version
- name: Check prod config exists
run: test -f config/prod.json
- name: Check Sentry Flutter secret exists
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
env:
SENTRY_DSN: ${{ secrets.SENTRY_DSN_FLUTTER }}
run: test -n "$SENTRY_DSN"
- name: Define release version
run: |
VERSION_NAME=$(awk '/^version:/ { split($2, parts, "+"); print parts[1] }' pubspec.yaml)
test -n "$VERSION_NAME"
echo "MOBILE_VERSION_NAME=$VERSION_NAME" >> "$GITHUB_ENV"
echo "MOBILE_VERSION=$VERSION_NAME+${GITHUB_RUN_NUMBER}" >> "$GITHUB_ENV"
echo "SENTRY_RELEASE=tablemaster-mobile@$VERSION_NAME+${GITHUB_RUN_NUMBER}" >> "$GITHUB_ENV"
- name: Get dependencies
run: flutter pub get
- name: Audit outdated dependencies
run: flutter pub outdated | tee flutter-dependencies-report.txt
- name: Run Flutter Analyze
run: flutter analyze
- name: Run Flutter Tests
run: |
set +e
flutter test --machine > flutter-test-output.log 2>&1
test_exit_code=$?
awk '/^\{/ { print }' flutter-test-output.log > flutter-test-results.json
if [ ! -s flutter-test-results.json ]; then
cat flutter-test-output.log
echo "No valid Flutter JSON test output was generated."
exit 1
fi
exit "$test_exit_code"
- name: Upload Flutter Test Results
if: always()
uses: actions/upload-artifact@v4
with:
name: flutter-test-results
path: |
flutter-test-results.json
flutter-test-output.log
- name: Test Report
if: always()
uses: dorny/test-reporter@v1
with:
name: Flutter Test Results
path: flutter-test-results.json
reporter: 'flutter-json'
- name: Run Flutter Format Check
run: dart format --output=none --set-exit-if-changed lib test
- name: Build Web Production
env:
SENTRY_DSN: ${{ secrets.SENTRY_DSN_FLUTTER }}
run: >
flutter build web --release
--dart-define-from-file=config/prod.json
--dart-define=SENTRY_DSN="$SENTRY_DSN"
--dart-define=SENTRY_RELEASE="$SENTRY_RELEASE"
--build-name="$MOBILE_VERSION_NAME"
--build-number="$GITHUB_RUN_NUMBER"
- name: Zip Web Build
run: |
cd build/web
zip -r ../../${WEB_ARTIFACT_NAME} .
- name: Prepare stable Android signing
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
env:
ANDROID_KEYSTORE_BASE64: ${{ secrets.ANDROID_KEYSTORE_BASE64 }}
ANDROID_KEY_ALIAS: ${{ secrets.ANDROID_KEY_ALIAS }}
ANDROID_STORE_PASSWORD: ${{ secrets.ANDROID_STORE_PASSWORD }}
ANDROID_KEY_PASSWORD: ${{ secrets.ANDROID_KEY_PASSWORD }}
run: |
set -euo pipefail
test -n "$ANDROID_KEYSTORE_BASE64"
test -n "$ANDROID_KEY_ALIAS"
test -n "$ANDROID_STORE_PASSWORD"
test -n "$ANDROID_KEY_PASSWORD"
printf '%s' "$ANDROID_KEYSTORE_BASE64" | base64 --decode > android/app/upload-keystore.jks
chmod 600 android/app/upload-keystore.jks
{
printf 'storePassword=%s\n' "$ANDROID_STORE_PASSWORD"
printf 'keyPassword=%s\n' "$ANDROID_KEY_PASSWORD"
printf 'keyAlias=%s\n' "$ANDROID_KEY_ALIAS"
printf 'storeFile=app/upload-keystore.jks\n'
} > android/key.properties
chmod 600 android/key.properties
- name: Build APK Production
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
env:
SENTRY_DSN: ${{ secrets.SENTRY_DSN_FLUTTER }}
run: >
flutter build apk --release
--dart-define-from-file=config/prod.json
--dart-define=SENTRY_DSN="$SENTRY_DSN"
--dart-define=SENTRY_RELEASE="$SENTRY_RELEASE"
--build-name="$MOBILE_VERSION_NAME"
--build-number="$GITHUB_RUN_NUMBER"
- name: Rename APK
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
run: |
cp build/app/outputs/flutter-apk/app-release.apk tablemaster-prod.apk
- name: Prepare release checksums
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
run: |
sha256sum \
tablemaster-prod.apk \
"${WEB_ARTIFACT_NAME}" \
CHANGELOG.md \
flutter-test-results.json \
> SHA256SUMS
- name: Upload workflow artifacts
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
uses: actions/upload-artifact@v4
with:
name: flutter-builds
path: |
tablemaster-prod.apk
${{ env.WEB_ARTIFACT_NAME }}
SHA256SUMS
CHANGELOG.md
flutter-dependencies-report.txt
- name: Create GitHub Release
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
env:
GH_TOKEN: ${{ github.token }}
run: |
TAG="mobile-v${MOBILE_VERSION}"
TITLE="TableMaster Mobile ${MOBILE_VERSION}"
gh release create "$TAG" \
tablemaster-prod.apk \
"${WEB_ARTIFACT_NAME}" \
SHA256SUMS \
CHANGELOG.md \
flutter-test-results.json \
flutter-test-output.log \
flutter-dependencies-report.txt \
--title "$TITLE" \
--notes "Release Flutter de production depuis main.
Version: ${MOBILE_VERSION}
Commit: ${{ github.sha }}
Release Sentry: ${SENTRY_RELEASE}
Validation:
- flutter analyze
- flutter test
- dart format
- audit flutter pub outdated
- build web release
- APK release avec signature stable
Fichiers principaux:
- tablemaster-prod.apk
- ${WEB_ARTIFACT_NAME}
- SHA256SUMS
- CHANGELOG.md" \
--latest
docker-build-and-push:
name: Build and push web Docker image
runs-on: ubuntu-latest
needs: build-and-test
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Download web artifact
uses: actions/download-artifact@v4
with:
name: flutter-builds
- name: Extract web build
run: |
mkdir -p web-deploy
unzip -q "${WEB_ARTIFACT_NAME}" -d web-deploy
mkdir -p build
mv web-deploy build/web
- name: Normalize image name
run: |
IMAGE_NAME_LOWER=$(echo "${IMAGE_NAME}" | tr '[:upper:]' '[:lower:]')
echo "IMAGE_NAME_LOWER=$IMAGE_NAME_LOWER" >> $GITHUB_ENV
- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push web image
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
push: true
tags: |
${{ env.IMAGE_NAME_LOWER }}:prod
${{ env.IMAGE_NAME_LOWER }}:${{ github.sha }}
deploy-web:
name: Deploy web to Oracle VPS
runs-on: ubuntu-latest
needs: docker-build-and-push
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Prepare SSH key
run: |
mkdir -p ~/.ssh
echo "${{ secrets.ORACLE_SSH_KEY_B64 }}" | base64 -d > ~/.ssh/oracle_key
chmod 600 ~/.ssh/oracle_key
ssh-keyscan -H ${{ secrets.ORACLE_HOST }} >> ~/.ssh/known_hosts
- name: Copy Docker Compose file
env:
ORACLE_USER: ${{ secrets.ORACLE_USER }}
ORACLE_HOST: ${{ secrets.ORACLE_HOST }}
run: |
set -e
REMOTE_APP_DIR="/opt/tablemaster/prod/TableMasterMobile"
test -n "$ORACLE_USER"
test -n "$ORACLE_HOST"
ssh -i ~/.ssh/oracle_key "$ORACLE_USER@$ORACLE_HOST" "mkdir -p '$REMOTE_APP_DIR'"
scp -i ~/.ssh/oracle_key docker-compose.prod.yml "$ORACLE_USER@$ORACLE_HOST:$REMOTE_APP_DIR/docker-compose.yml"
- name: Deploy with Docker Compose
env:
ORACLE_USER: ${{ secrets.ORACLE_USER }}
ORACLE_HOST: ${{ secrets.ORACLE_HOST }}
GHCR_OWNER: ${{ github.repository_owner }}
GHCR_USERNAME: ${{ secrets.GHCR_USERNAME }}
GHCR_READ_TOKEN: ${{ secrets.GHCR_READ_TOKEN }}
run: |
set -e
REMOTE_APP_DIR="/opt/tablemaster/prod/TableMasterMobile"
test -n "$ORACLE_USER"
test -n "$ORACLE_HOST"
test -n "$GHCR_USERNAME"
test -n "$GHCR_READ_TOKEN"
GHCR_OWNER_LOWER=$(echo "$GHCR_OWNER" | tr '[:upper:]' '[:lower:]')
ssh -i ~/.ssh/oracle_key "$ORACLE_USER@$ORACLE_HOST" << EOF
set -e
cd "$REMOTE_APP_DIR"
export GHCR_OWNER="$GHCR_OWNER_LOWER"
echo "$GHCR_READ_TOKEN" | docker login ghcr.io -u "$GHCR_USERNAME" --password-stdin
docker compose pull
docker compose up -d
docker image prune -f
docker compose ps
EOF