-
Notifications
You must be signed in to change notification settings - Fork 0
360 lines (290 loc) · 12.9 KB
/
release.yml
File metadata and controls
360 lines (290 loc) · 12.9 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
name: 构建并发布 SimpleNote
on:
push:
tags:
- 'v*' # 当推送以v开头的标签时触发,如v1.0.0
jobs:
build-windows:
name: 构建 Windows 程序
runs-on: windows-latest
steps:
- name: 检出代码
uses: actions/checkout@v3
- name: 获取版本号
id: get_version
shell: bash
run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
- name: 安装 Qt
uses: jurplel/install-qt-action@v4
with:
version: '6.8.3'
host: 'windows'
target: 'desktop'
arch: 'win64_msvc2022_64'
- name: 设置 MSVC 环境
uses: ilammy/msvc-dev-cmd@v1
with:
arch: x64
- name: 创建构建目录
run: mkdir build
- name: 运行 qmake
run: |
cd build
qmake CONFIG+=release PREFIX=/ ..\SimpleNote.pro
- name: 编译项目
run: |
cd build
nmake
- name: 打包应用程序
run: |
cd build\release
windeployqt --release --no-translations --no-opengl-sw SimpleNote.exe
- name: 创建发布包
id: create_package
run: |
$VERSION = "${{ steps.get_version.outputs.VERSION }}"
$PACKAGE_NAME = "SimpleNote-$VERSION-windows"
# 创建发布目录
New-Item -Path $PACKAGE_NAME -ItemType Directory
# 复制所需可执行文件和DLL
Copy-Item -Path build\release\SimpleNote.exe -Destination $PACKAGE_NAME
# 复制Qt相关DLL和插件,排除DirectX相关依赖
Get-ChildItem -Path build\release -Filter "*.dll" |
Where-Object { $_.Name -notmatch "d3d|dx|Direct" } |
Copy-Item -Destination $PACKAGE_NAME
# 复制必要的Qt插件文件夹
$QtPluginDirs = @("platforms", "styles", "bearer", "sqldrivers", "multimedia")
foreach ($dir in $QtPluginDirs) {
if (Test-Path -Path "build\release\$dir") {
New-Item -Path "$PACKAGE_NAME\$dir" -ItemType Directory -Force
Get-ChildItem -Path "build\release\$dir\*.dll" |
Where-Object { $_.Name -notmatch "d3d|dx|Direct|qwindows" } |
Copy-Item -Destination "$PACKAGE_NAME\$dir" -Force
}
}
# 确保platforms文件夹中有qwindows.dll
if (Test-Path -Path "build\release\platforms\qwindows.dll") {
New-Item -Path "$PACKAGE_NAME\platforms" -ItemType Directory -Force -ErrorAction SilentlyContinue
Copy-Item -Path "build\release\platforms\qwindows.dll" -Destination "$PACKAGE_NAME\platforms\" -Force
}
# 复制文档
Copy-Item -Path README.md -Destination "$PACKAGE_NAME\README.txt"
# 创建版本信息文件
@"
SimpleNote 版本: $VERSION
构建时间: $([System.TimeZoneInfo]::ConvertTimeBySystemTimeZoneId((Get-Date), 'China Standard Time').ToString('yyyy-MM-dd HH:mm:ss'))
构建系统: Windows
"@ | Out-File -FilePath "$PACKAGE_NAME\version.txt" -Encoding utf8
# 创建ZIP包
Compress-Archive -Path $PACKAGE_NAME -DestinationPath "$PACKAGE_NAME.zip"
shell: pwsh
- name: 上传 Windows 构建产物
uses: actions/upload-artifact@v4
with:
name: windows-package
path: SimpleNote-${{ steps.get_version.outputs.VERSION }}-windows.zip
retention-days: 1
build-ubuntu:
name: 构建 Ubuntu 程序
runs-on: ubuntu-latest
steps:
- name: 检出代码
uses: actions/checkout@v3
- name: 获取版本号
id: get_version
shell: bash
run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
- name: 安装依赖
run: |
sudo apt-get update
sudo apt-get install -y build-essential libgl1-mesa-dev
- name: 安装 Qt
uses: jurplel/install-qt-action@v4
with:
version: '6.5.3'
host: 'linux'
target: 'desktop'
arch: 'gcc_64'
aqtversion: '==3.1.*'
- name: 创建构建目录
run: mkdir build
- name: 运行 qmake
run: |
cd build
qmake CONFIG+=release PREFIX=/ ../SimpleNote.pro
- name: 编译项目
run: |
cd build
make -j$(nproc)
- name: 创建AppImage
id: appimage
run: |
# 版本号和包名
VERSION="${{ steps.get_version.outputs.VERSION }}"
PACKAGE_NAME="SimpleNote-$VERSION-ubuntu"
# 打印当前环境变量和路径信息,用于调试
echo "Current working directory: $(pwd)"
echo "QTDIR path: $QTDIR"
echo "PATH: $PATH"
echo "Qt binaries: $(find $QTDIR -name qmake)"
# 确保qmake在PATH中
export PATH=$QTDIR/bin:$PATH
which qmake || echo "qmake not found in PATH"
# 创建AppDir结构
mkdir -p AppDir/usr/{bin,lib,share/applications,share/icons/hicolor/256x256/apps}
# 复制二进制文件和库
cp build/SimpleNote AppDir/usr/bin/
# 创建.desktop文件
cat > AppDir/usr/share/applications/simplenote.desktop << EOF
[Desktop Entry]
Name=SimpleNote
Exec=SimpleNote
Icon=simplenote
Type=Application
Categories=Office;
EOF
# 复制图标
cp icons/simplenote.png AppDir/usr/share/icons/hicolor/256x256/apps/
# 复制README和创建版本信息
cp README.md AppDir/usr/share/README.txt
echo "SimpleNote 版本: $VERSION" > AppDir/usr/share/version.txt
echo "构建时间: $(TZ='Asia/Shanghai' date '+%Y-%m-%d %H:%M:%S')" >> AppDir/usr/share/version.txt
echo "构建系统: Ubuntu" >> AppDir/usr/share/version.txt
# 获取linuxdeploy和linuxdeploy-plugin-qt
wget -c "https://github.com/linuxdeploy/linuxdeploy/releases/download/continuous/linuxdeploy-x86_64.AppImage"
wget -c "https://github.com/linuxdeploy/linuxdeploy-plugin-qt/releases/download/continuous/linuxdeploy-plugin-qt-x86_64.AppImage"
chmod +x linuxdeploy*.AppImage
# 设置环境变量 - 显式指定qmake的完整路径
export QMAKE="$(which qmake)"
echo "Using QMAKE: $QMAKE"
export VERSION=$VERSION
export OUTPUT="SimpleNote-$VERSION-x86_64.AppImage"
# 排除常见的开发文件库和DirectX相关库
EXCLUDE_LIBS="libstdc++.so libgcc_s.so libd3d libDirect"
EXCLUDE_ARGS=""
for lib in $EXCLUDE_LIBS; do
EXCLUDE_ARGS="$EXCLUDE_ARGS --exclude-library=$lib"
done
# 移除任何源代码文件和不需要的文件夹
find AppDir -name "*.cpp" -o -name "*.h" -o -name "*.o" -o -name "*.obj" | xargs rm -f 2>/dev/null || true
# 创建AppImage
./linuxdeploy-x86_64.AppImage --appdir AppDir --plugin qt --output appimage $EXCLUDE_ARGS
# 如果上面的命令失败,尝试直接调用插件
if [ ! -f "$OUTPUT" ]; then
echo "First attempt failed, trying alternative approach..."
./linuxdeploy-x86_64.AppImage --appdir AppDir
QMAKE="$QTDIR/bin/qmake" ./linuxdeploy-plugin-qt-x86_64.AppImage --appdir AppDir
./linuxdeploy-x86_64.AppImage --appdir AppDir --output appimage $EXCLUDE_ARGS
fi
# 创建tar.gz包
mkdir -p $PACKAGE_NAME
if [ -f "$OUTPUT" ]; then
cp "$OUTPUT" $PACKAGE_NAME/
cp README.md $PACKAGE_NAME/README.txt
cp AppDir/usr/share/version.txt $PACKAGE_NAME/
tar -czvf $PACKAGE_NAME.tar.gz $PACKAGE_NAME
else
echo "Failed to create AppImage. Packaging what we have..."
cp build/SimpleNote $PACKAGE_NAME/
cp README.md $PACKAGE_NAME/README.txt
tar -czvf $PACKAGE_NAME.tar.gz $PACKAGE_NAME
fi
- name: 上传 AppImage
uses: actions/upload-artifact@v4
with:
name: appimage
path: SimpleNote-${{ steps.get_version.outputs.VERSION }}-x86_64.AppImage
if-no-files-found: warn
- name: 上传 Ubuntu 压缩包
uses: actions/upload-artifact@v4
with:
name: ubuntu-package
path: SimpleNote-${{ steps.get_version.outputs.VERSION }}-ubuntu.tar.gz
retention-days: 1
create-release:
name: 创建 Release
needs: [build-windows, build-ubuntu]
runs-on: ubuntu-latest
steps:
- name: 检出代码
uses: actions/checkout@v3
with:
fetch-depth: 0 # 获取完整的git历史记录
- name: 获取版本号
id: get_version
shell: bash
run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
- name: 获取版本特性
id: get_changelog
shell: bash
run: |
# 获取当前tag
CURRENT_TAG=${GITHUB_REF#refs/tags/}
# 获取上一个tag,如果没有则获取第一个commit
PREVIOUS_TAG=$(git describe --tags --abbrev=0 $CURRENT_TAG^ 2>/dev/null || git rev-list --max-parents=0 HEAD)
# 如果是第一个tag,就从仓库开始获取所有commit
if [[ "$PREVIOUS_TAG" == $(git rev-list --max-parents=0 HEAD) ]]; then
echo "这是第一个发布版本,包含以下所有更新:" > changelog.md
else
echo "## 本次更新内容($PREVIOUS_TAG 至 $CURRENT_TAG):" > changelog.md
fi
# 获取commit信息并格式化
git log --pretty=format:"- %s" $PREVIOUS_TAG..$CURRENT_TAG >> changelog.md
# 确保文件末尾有换行符
echo "" >> changelog.md
# 检查是否有实际的commit消息(通过grep匹配以"-"开头的行)
COMMIT_COUNT=$(grep -c "^-" changelog.md || true)
# 如果没有commit信息,添加默认信息
if [[ "$COMMIT_COUNT" -eq 0 ]]; then
echo "- 本次发布无重大更新内容" >> changelog.md
fi
# 保存到输出变量中
CHANGELOG=$(cat changelog.md)
echo "CHANGELOG<<EOF" >> $GITHUB_OUTPUT
echo "$CHANGELOG" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: 下载 Windows 构建产物
uses: actions/download-artifact@v4
with:
name: windows-package
- name: 下载 Ubuntu 构建产物
uses: actions/download-artifact@v4
with:
name: ubuntu-package
- name: 下载 AppImage
uses: actions/download-artifact@v4
with:
name: appimage
- name: 列出下载的文件
run: ls -la
- name: 创建 Release
uses: softprops/action-gh-release@v1
with:
name: SimpleNote ${{ steps.get_version.outputs.VERSION }}
tag_name: ${{ github.ref }}
draft: false
prerelease: false
files: |
SimpleNote-${{ steps.get_version.outputs.VERSION }}-windows.zip
SimpleNote-${{ steps.get_version.outputs.VERSION }}-ubuntu.tar.gz
SimpleNote-${{ steps.get_version.outputs.VERSION }}-x86_64.AppImage
body: |
# SimpleNote ${{ steps.get_version.outputs.VERSION }}
简单便签应用程序 - 基于Qt开发的轻量级便签工具
## 发布说明
这是由GitHub Actions自动构建的发布版本。
${{ steps.get_changelog.outputs.CHANGELOG }}
### 安装说明
#### Windows
1. 下载并解压 SimpleNote-${{ steps.get_version.outputs.VERSION }}-windows.zip
2. 运行解压后目录中的 SimpleNote.exe
#### Ubuntu/Linux
方法1: 使用AppImage (推荐)
1. 下载 SimpleNote-${{ steps.get_version.outputs.VERSION }}-x86_64.AppImage
2. 添加执行权限: `chmod +x SimpleNote-${{ steps.get_version.outputs.VERSION }}-x86_64.AppImage`
3. 直接运行: `./SimpleNote-${{ steps.get_version.outputs.VERSION }}-x86_64.AppImage`
方法2: 使用压缩包
1. 下载并解压 SimpleNote-${{ steps.get_version.outputs.VERSION }}-ubuntu.tar.gz
2. 添加执行权限并运行AppImage文件
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}