-
Notifications
You must be signed in to change notification settings - Fork 4
232 lines (194 loc) · 6.55 KB
/
flutter-build.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
name: 构建发布Flutter应用
#on:
# push:
on:
push:
paths:
- "pubspec.yaml"
branches:
- main
jobs:
pre-build:
name: 预构建
runs-on: ubuntu-latest
outputs:
APP_VERSION: ${{ steps.output-version.outputs.APP_VERSION }}
APP_LAST_VERSION: ${{ steps.output-tag-version.outputs.APP_VERSION }}
steps:
- name: 拉取代码
uses: actions/checkout@v3
with:
sparse-checkout: |
pubspec.yaml
sparse-checkout-cone-mode: false
fetch-depth: 0
- name: 读取当前版本号
id: output-version
run: |
VERSION=`grep -iE --regexp="version: ([0-9\.+]*)" pubspec.yaml | grep -io "[0-9\.+]*"`
echo "Version: $VERSION"
echo "APP_VERSION=$VERSION" >> $GITHUB_OUTPUT
- name: 获取最新的TAG
id: output-tag-version
run: |
LAST_VERSION=`git tag --sort=-creatordate | head -1`
echo "Version: $LAST_VERSION"
echo "APP_LAST_VERSION=$LAST_VERSION" >> $GITHUB_OUTPUT
build-apk:
name: 编译android
runs-on: ubuntu-latest
needs: [pre-build]
steps:
- name: 设置Flutter环境
uses: subosito/flutter-action@v2
with:
channel: "stable"
- name: 拉取代码
uses: actions/checkout@v4
- name: 安装依赖项
run: flutter pub get
- name: 设置java环境
uses: actions/setup-java@v4
with:
distribution: "adopt"
java-version: "21"
- name: 运行代码生成器
run: dart run build_runner build
- name: 初始化签名
run: |
touch ./android/key.properties
echo keyPassword='${{ secrets.KEYPASSWORD }}' >> ./android/key.properties
echo storePassword='${{ secrets.STOREPASSWORD }}' >> ./android/key.properties
echo keyAlias='${{ secrets.KEYALIAS }}' >> ./android/key.properties
echo storeFile='./key.jks' >> ./android/key.properties
echo ${{ secrets.KEY_STORE }} | base64 --decode > ./android/app/key.jks
- name: 编译apk
run: flutter build apk --split-per-abi --obfuscate --split-debug-info=build/app/outputs/symbols/release
- name: 上传apk到工作流程
uses: actions/upload-artifact@v4
with:
name: build-apk
path: build/app/outputs/apk/release/*
build-linux:
name: 编译linux
runs-on: ubuntu-latest
needs: [pre-build]
steps:
- name: 拉取代码
uses: actions/checkout@v4
- name: 设置Flutter环境
uses: subosito/flutter-action@v2
with:
channel: "stable"
- name: 安装ninja、libgtk
run: |
sudo apt-get update -y
sudo apt-get install -y ninja-build libgtk-3-dev libmpv-dev mpv
- name: 安装依赖项
run: flutter pub get
- name: 配置桌面
run: flutter config --enable-linux-desktop
- name: 运行代码生成器
run: dart run build_runner build
- name: 编译linux
run: flutter build linux
- name: 压缩生成的文件
run: tar -zcvf "MoeKey-${{ needs.pre-build.outputs.APP_VERSION }}-linux-x86_64-release.tar.gz" --directory=build/linux/x64/release/bundle .
- name: 上传到工作流程
uses: actions/upload-artifact@v4
with:
name: build-linux
path: "MoeKey-${{ needs.pre-build.outputs.APP_VERSION }}-linux-x86_64-release.tar.gz"
build-windows:
name: 编译windows
runs-on: windows-latest
needs: [pre-build]
steps:
- name: 拉取代码
uses: actions/checkout@v4
- name: 设置Flutter环境
uses: subosito/flutter-action@v2
with:
channel: "stable"
- name: 安装依赖项
run: flutter pub get
- name: 启动windows桌面
run: flutter config --enable-windows-desktop
- name: 运行代码生成器
run: dart run build_runner build
- name: 编译windows
run: flutter build windows
- name: 压缩生成的文件
run: |
$sourceFolder = "build\windows\x64\runner\Release"
$destinationPath = "MoeKey-${{ needs.pre-build.outputs.APP_VERSION }}-windows-x86_64-release.zip"
Compress-Archive -Path $sourceFolder -DestinationPath $destinationPath
- name: 上传到工作流程
uses: actions/upload-artifact@v4
with:
name: build-windows
path: "MoeKey-${{ needs.pre-build.outputs.APP_VERSION }}-windows-x86_64-release.zip"
build-macos:
name: 编译macOS
runs-on: macos-latest
needs: [pre-build]
steps:
- name: 拉取代码
uses: actions/checkout@v4
- name: 设置Flutter环境
uses: subosito/flutter-action@v2
with:
channel: "stable"
- name: 安装依赖项
run: flutter pub get
- name: 启动桌面
run: flutter config --enable-macos-desktop
- name: 运行代码生成器
run: dart run build_runner build
- name: 编译macOS
run: flutter build macos
- name: 压缩生成的文件
run: |
cd build/macos/Build/Products/Release
zip -rq MoeKey-${{ needs.pre-build.outputs.APP_VERSION }}-macOS-universal-release.zip MoeKey.app
mv MoeKey-${{ needs.pre-build.outputs.APP_VERSION }}-macOS-universal-release.zip $GITHUB_WORKSPACE
- name: 上传到工作流程
uses: actions/upload-artifact@v4
with:
name: build-macos
path: |
MoeKey-${{ needs.pre-build.outputs.APP_VERSION }}-macOS-universal-release.zip
release:
name: 上传包
needs: [build-apk, build-linux, build-windows, build-macos, pre-build]
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: 下载apk
uses: actions/download-artifact@v4
with:
name: build-apk
path: artifact
- name: 下载linux
uses: actions/download-artifact@v4
with:
name: build-linux
path: artifact
- name: 下载windows
uses: actions/download-artifact@v4
with:
name: build-windows
path: artifact
- name: 下载macOS
uses: actions/download-artifact@v4
with:
name: build-macos
path: artifact
- name: 创建releases
id: create_release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ needs.pre-build.outputs.APP_VERSION }}
files: ./artifact/*
body: "[CHANGELOG.md](CHANGELOG.md)"