-
Notifications
You must be signed in to change notification settings - Fork 5
390 lines (390 loc) · 14.5 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
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
name: CI
env:
TZ: Asia/Shanghai
on:
push:
paths-ignore:
- '**/README.md'
- '.github/workflows/*'
- '!.github/workflows/main.yml'
pull_request:
paths-ignore:
- '**/README.md'
- '.github/workflows/*'
- '!.github/workflows/main.yml'
workflow_dispatch:
inputs:
debug_enabled:
type: boolean
description: 'Run the build with tmate debugging enabled (https://github.com/marketplace/actions/debugging-with-tmate)'
required: false
default: false
jobs:
build_env:
name: build env
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: init custom env
run: |
set -a
BUILD_NAME="${GITHUB_REPOSITORY#*/}"
if [[ ${GITHUB_REF} == refs/tags* ]]
then
CREATE_RELEASE="true"
BUILD_VERSION=${GITHUB_REF#refs/tags/}
if [[ -x ./latest-changelog.sh ]]
then
RELEASE_BODY=$(./latest-changelog.sh $BUILD_VERSION |sed '1s/[,,]$//;1s/^\(.*\)$/### \1\n/')
TG_CHANGELOG=$(./latest-changelog.sh $BUILD_VERSION |sed -n '{;=;p}' | sed "N;s/\n/. /g")
fi
if [[ -z "$RELEASE_BODY" ]]
then
RELEASE_BODY='### ${{ github.event.head_commit.message }}'
TG_CHANGELOG="$(echo "$RELEASE_BODY"|sed -n "s/### \(.*\)/\1/p" |sed -n '{;=;p}' | sed "N;s/\n/. /g")"
fi
elif [[ ${GITHUB_REF} == refs/pull* ]]
then
CREATE_RELEASE="false"
num=${GITHUB_REF#refs/pull/}
num=${num%/merge}
BUILD_VERSION=pr-${num}-"$(date +'%Y%m%d%H%M%S')"
elif [[ ${GITHUB_EVENT_NAME} == workflow_dispatch ]]
then
CREATE_RELEASE="false"
BUILD_VERSION="$(date +'%Y%m%d%H%M%S')"
elif [[ ${GITHUB_REF} == refs/heads* ]]
then
CREATE_RELEASE="false"
BUILD_VERSION="${GITHUB_REF#refs/heads/}-$(date +'%Y%m%d%H%M%S')"
RELEASE_BODY=$(echo '${{ toJson(github.event.commits) }}' |jq -r 'map("### "+.message)|join("\n\n------\n")')
TG_CHANGELOG="$(echo "$RELEASE_BODY"|sed -n "s/### \(.*\)/\1/p" |sed -n '{;=;p}' | sed "N;s/\n/. /g")"
VERSION_PREFIX='内测版-'
else
CREATE_RELEASE="false"
BUILD_VERSION="$(date +'%Y%m%d%H%M%S')"
fi
BUILD_NAME_WITH_VERSION="$BUILD_NAME-$BUILD_VERSION"
echo BUILD_NAME="$BUILD_NAME" >> .custom_env
echo BUILD_VERSION="$BUILD_VERSION" >> .custom_env
echo BUILD_NAME_WITH_VERSION="$BUILD_NAME_WITH_VERSION" >> .custom_env
echo CREATE_RELEASE="$CREATE_RELEASE" >> .custom_env
if test -n "$RELEASE_BODY"
then
echo 'RELEASE_BODY<<EOF' >> .custom_env
echo "$RELEASE_BODY" >> .custom_env
echo 'EOF' >> .custom_env
if [ -f template-update.md ]
then
echo 'UPDATE_BODY<<EOF' >> .custom_env
envsubst < template-update.md >> .custom_env
echo >> .custom_env
echo 'EOF' >> .custom_env
fi
fi
echo DEPLOY_WEB="true" >> .custom_env
if [[ "$CREATE_RELEASE" == "true" && -n "${{ secrets.TELEGRAM_TO }}" && -n "${{ secrets.TELEGRAM_TOKEN }}" ]]
then
echo SEND_TELEGRAM="true" >> .custom_env
fi
cat .custom_env
cat .custom_env >> $GITHUB_ENV
- name: upload .custom_env
uses: actions/upload-artifact@v4
with:
include-hidden-files: true
name: custom_env
path: ./.custom_env
- name: Setup tmate session
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
uses: mxschmitt/action-tmate@v3
if: ${{ github.event_name == 'workflow_dispatch' && inputs.debug_enabled }}
- name: clean custom env
run: rm .custom_env
build_app:
needs: [ build_env ]
name: Build Flutter (${{ matrix.config }})
runs-on: ${{ matrix.os }}
strategy:
matrix:
name: [ android, android-aab, web, linux, windows, ios, macos ]
include:
- name: android
config: apk
os: ubuntu-latest
FILE_TYPE: apk
BUILD_ARGS: "--target-platform android-arm64"
RELEASE_PATH: '*.apk'
RELEASE_DIRECTORY: build/app/outputs/apk/release
- name: android-aab
config: appbundle
os: ubuntu-latest
FILE_TYPE: aab
BUILD_ARGS: ""
RELEASE_PATH: '*.aab'
RELEASE_DIRECTORY: build/app/outputs/bundle/release
- name: web
config: web
os: ubuntu-latest
FILE_TYPE: zip
RELEASE_PATH: .
RELEASE_DIRECTORY: build/web
- name: linux
config: linux
os: ubuntu-latest
FILE_TYPE: tar.gz
ENABLE_CONFIG: linux-desktop
RELEASE_PATH: .
RELEASE_DIRECTORY: build/linux/x64/release/bundle
PRE_COMMAND: |
sudo apt-get -y update
sudo apt-get -y install clang cmake git ninja-build pkg-config libgtk-3-dev liblzma-dev libstdc++-12-dev
- name: windows
config: windows
os: windows-latest
FILE_TYPE: zip
RELEASE_PATH: .
RELEASE_DIRECTORY: build/windows/x64/runner/Release
- name: ios
config: ios
os: macos-latest
FILE_TYPE: ipa
BUILD_ARGS: "--no-codesign"
RELEASE_PATH: Payload
RELEASE_DIRECTORY: build/ios/iphoneos
POST_COMMAND: |
cd build/ios/iphoneos
mkdir Payload
cd Payload
ln -s ../Runner.app
- name: macos
config: macos
os: macos-latest
FILE_TYPE: dmg
ENABLE_CONFIG: macos-desktop
RELEASE_PATH: "*.app"
RELEASE_DIRECTORY: build/macos/Build/Products/Release
# Disable fail-fast; we want results from all OSes even if one fails.
fail-fast: false
steps:
- name: download custom env
uses: actions/download-artifact@v4
with:
name: custom_env
- name: apply custom env
if: startsWith(matrix.os, 'windows') != true
run: |
cat .custom_env >> $GITHUB_ENV
rm .custom_env
- name: apply custom env - Windows
if: startsWith(matrix.os, 'windows')
run: |
type .custom_env >> $env:GITHUB_ENV
del .custom_env
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: 'oracle'
java-version: '17'
- uses: subosito/flutter-action@v2
with:
channel: 'stable'
- name: pre
run: ${{ matrix.PRE_COMMAND }}
- name: enable config (${{ matrix.config }})
if: "${{ matrix.ENABLE_CONFIG != '' }}"
run: flutter config --enable-${{ matrix.ENABLE_CONFIG }}
- name: prepare android signing key
env:
SIGNING_KEY: ${{ secrets.SIGNING_KEY }}
if: "${{ ( matrix.FILE_TYPE == 'apk' || matrix.FILE_TYPE == 'aab' ) && env.SIGNING_KEY != '' }}"
run: |
cd android
echo "${{ secrets.SIGNING_KEY }}" |base64 -d > ci.jks
echo storeFile=ci.jks > key.properties
echo storePassword=${{ secrets.KEY_STORE_PASSWORD }} >> key.properties
echo keyAlias=${{ secrets.ALIAS }} >> key.properties
echo keyPassword=${{ secrets.KEY_PASSWORD }} >> key.properties
- name: build
run: |
flutter pub get
flutter build ${{ matrix.config }} ${{ matrix.BUILD_ARGS }}
- name: post
run: ${{ matrix.POST_COMMAND }}
- name: cname
env:
CNAME: ${{ secrets.CNAME }}
if: "${{ matrix.name == 'web' && env.CNAME != '' }}"
run: echo ${{ env.CNAME }} > ${{ matrix.RELEASE_DIRECTORY }}/${{ matrix.RELEASE_PATH }}/CNAME
- name: tar.gz
if: "${{ matrix.FILE_TYPE == 'tar.gz' }}"
uses: thedoctor0/zip-release@master
with:
type: tar
path: ${{ matrix.RELEASE_PATH }}
directory: ${{ matrix.RELEASE_DIRECTORY }}
filename: ${{ github.workspace }}/build/${{ env.BUILD_NAME_WITH_VERSION }}-${{ matrix.name }}.${{ matrix.FILE_TYPE }}
- name: zip
if: "${{ matrix.FILE_TYPE == 'zip' || matrix.FILE_TYPE == 'ipa' }}"
uses: thedoctor0/zip-release@master
with:
type: zip
path: ${{ matrix.RELEASE_PATH }}
directory: ${{ matrix.RELEASE_DIRECTORY }}
filename: ${{ github.workspace }}/build/${{ env.BUILD_NAME_WITH_VERSION }}-${{ matrix.name }}.${{ matrix.FILE_TYPE }}
- name: set python version
if: "${{ matrix.FILE_TYPE == 'dmg' }}"
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: dmg
if: "${{ matrix.FILE_TYPE == 'dmg' }}"
run: |
npm install -g appdmg
appPath=$(ls -d ${{ matrix.RELEASE_DIRECTORY }}/${{ matrix.RELEASE_PATH }})
echo '{"title":"###TITLE###","icon":"###PATH###/Contents/Resources/AppIcon.icns","contents":[{"x":448,"y":144,"type":"link","path":"/Applications"},{"x":192,"y":144,"type":"file","path":"###PATH###"}]}' |
sed "s/###TITLE###/${{ env.BUILD_NAME }}/g" |
sed "s/###PATH###/$(echo $appPath | sed 's_/_\\/_g')/g" |
tee ./appdmg.json
appdmg ./appdmg.json build/${{ env.BUILD_NAME_WITH_VERSION }}-${{ matrix.name }}.${{ matrix.FILE_TYPE }}
- name: copy file
if: "${{ matrix.FILE_TYPE == 'apk' || matrix.FILE_TYPE == 'aab' }}"
run: cp ${{ matrix.RELEASE_DIRECTORY }}/${{ matrix.RELEASE_PATH }} build/${{ env.BUILD_NAME_WITH_VERSION }}-${{ matrix.name }}.${{ matrix.FILE_TYPE }}
- name: Archive Production Artifact
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.name }}-build
path: build/${{ env.BUILD_NAME_WITH_VERSION }}-${{ matrix.name }}.${{ matrix.FILE_TYPE }}
- name: Deploy
if: "${{ matrix.name == 'web' && env.DEPLOY_WEB == 'true' }}"
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
force_orphan: true
publish_dir: ${{ matrix.RELEASE_DIRECTORY }}/${{ matrix.RELEASE_PATH }}
release_create:
needs: [ build_app ]
name: create release
runs-on: ubuntu-latest
steps:
- name: download custom env
uses: actions/download-artifact@v4
with:
name: custom_env
- name: apply custom env
run: |
cat .custom_env >> $GITHUB_ENV
rm .custom_env
- name: create release
if: ${{ env.CREATE_RELEASE == 'true' }}
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ env.BUILD_VERSION }}
release_name: ${{ env.BUILD_VERSION }}
body: ${{ env.RELEASE_BODY }}
draft: true
prerelease: ${{ env.PRE_RELEASE == 'true' }}
- name: save release env
if: ${{ env.CREATE_RELEASE == 'true' }}
run: |
echo RELEASE_UPLAOD_URL="${{ steps.create_release.outputs.upload_url }}" >> .release_env
echo RELEASE_UPLAOD_ID="${{ steps.create_release.outputs.id }}" >> .release_env
- name: upload .release_env
if: ${{ env.CREATE_RELEASE == 'true' }}
uses: actions/upload-artifact@v4
with:
include-hidden-files: true
name: release_env
path: ./.release_env
release_upload:
needs: [ release_create ]
name: upload release file
runs-on: ubuntu-latest
strategy:
matrix:
name: [ android, android-aab, web, linux, windows, ios, macos ]
include:
- name: android
FILE_TYPE: apk
- name: android-aab
FILE_TYPE: aab
- name: web
FILE_TYPE: zip
- name: linux
FILE_TYPE: tar.gz
- name: windows
FILE_TYPE: zip
- name: ios
FILE_TYPE: ipa
- name: macos
FILE_TYPE: dmg
# Disable fail-fast; we want results from all OSes even if one fails.
fail-fast: false
steps:
- name: download custom env
uses: actions/download-artifact@v4
with:
name: custom_env
- name: apply custom env
run: |
cat .custom_env >> $GITHUB_ENV
rm .custom_env
- name: download release env
if: ${{ env.CREATE_RELEASE == 'true' }}
uses: actions/download-artifact@v4
with:
name: release_env
- name: apply release env
if: ${{ env.CREATE_RELEASE == 'true' }}
run: |
cat .release_env >> $GITHUB_ENV
rm .release_env
- name: download (${{ matrix.name }})
if: ${{ env.CREATE_RELEASE == 'true' }}
uses: actions/download-artifact@v4
with:
name: ${{ matrix.name }}-build
- name: Upload Release Asset (${{ matrix.name }})
if: ${{ env.CREATE_RELEASE == 'true' }}
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ env.RELEASE_UPLAOD_URL }}
asset_path: ${{ env.BUILD_NAME_WITH_VERSION }}-${{ matrix.name }}.${{ matrix.FILE_TYPE }}
asset_name: ${{ env.BUILD_NAME_WITH_VERSION }}-${{ matrix.name }}.${{ matrix.FILE_TYPE }}
asset_content_type: application/zip
release_publish:
needs: [ release_upload ]
name: publish release
runs-on: ubuntu-latest
steps:
- name: download custom env
uses: actions/download-artifact@v4
with:
name: custom_env
- name: apply custom env
run: |
cat .custom_env >> $GITHUB_ENV
rm .custom_env
- name: download release env
if: ${{ env.CREATE_RELEASE == 'true' }}
uses: actions/download-artifact@v4
with:
name: release_env
- name: apply release env
if: ${{ env.CREATE_RELEASE == 'true' }}
run: |
cat .release_env >> $GITHUB_ENV
rm .release_env
- name: publish release
if: ${{ env.CREATE_RELEASE == 'true' }}
uses: eregon/publish-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
release_id: ${{ env.RELEASE_UPLAOD_ID }}