Skip to content

Commit 85502e7

Browse files
Luna-GracefjwxzdeDuckDuckStudio
authored
feat: 自动打包发行版 (#158)
* chore(deps): 添加 GitHub Action 的依赖更新 * chore(dir): 整理目录 * feat: 发布时自动修改版本号 * chore(dir): 整理目录 * chore(git): 更新 .gitignore * feat: 为开发者打包脚本添加可选参数 示例: python DEV-PACK.py src ico.ico src\log -s * fix: 修复参数检查逻辑以确保正确的参数数量 * feat: 自动打包发行版工作流 * chore(license): 更新许可文件 * Apply suggestions from code review Co-authored-by: 宁静致远 <[email protected]> * fix: 还原 resource.rc * chore(license): 更新安装程序许可文件 * Apply suggestions from code review Co-authored-by: 宁静致远 <[email protected]> * fix: 改用 Clang 编译 Co-authored-by: 鸭鸭「カモ」 <[email protected]> * fix: 修改 \ 为 / * Apply suggestions from code review Co-authored-by: 鸭鸭「カモ」 <[email protected]> * fix: 修正日志写入 * fix: 修正编码问题 * pref: 打包 C++ 文件时输出详细过程 Co-authored-by: 鸭鸭「カモ」 <[email protected]> * fix: 不接受带 v 的新版本号 Co-authored-by: 宁静致远 <[email protected]> * fix: 移除重复的条目 Co-authored-by: 鸭鸭「カモ」 <[email protected]> * fix: 修改工件名 Co-authored-by: 鸭鸭「カモ」 <[email protected]> * Apply suggestions from code review Co-authored-by: 鸭鸭「カモ」 <[email protected]> * fix: 清理安装程序版工作目录 Co-authored-by: 宁静致远 <[email protected]> * fix: 先下载中文翻译 Co-authored-by: 鸭鸭「カモ」 <[email protected]> * Apply suggestions from code review Co-authored-by: 宁静致远 <[email protected]> * Apply suggestions from code review Co-authored-by: 鸭鸭「カモ」 <[email protected]> --------- Co-authored-by: 宁静致远 <[email protected]> Co-authored-by: 鸭鸭「カモ」 <[email protected]>
1 parent 3fefcc4 commit 85502e7

File tree

122 files changed

+561
-60
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

122 files changed

+561
-60
lines changed

.github/dependabot.yml

+4
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,7 @@ updates:
99
directory: "/" # Location of package manifests
1010
schedule:
1111
interval: "weekly"
12+
- package-ecosystem: "github-actions" # See documentation for possible values
13+
directory: "/" # Location of package manifests
14+
schedule:
15+
interval: "weekly"

.github/workflows/Pack_Release.yml

+138
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
name: Pack Releases
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
version:
7+
description: 版本号 (不带v)
8+
required: true
9+
10+
jobs:
11+
auto-pack-releases:
12+
runs-on: windows-latest
13+
14+
steps:
15+
- name: 检出代码
16+
uses: actions/checkout@v4
17+
18+
- name: 配置 Python
19+
uses: actions/setup-python@v5
20+
with:
21+
python-version: 3.x
22+
23+
- name: 安装依赖
24+
env:
25+
PYTHONIOENCODING: utf-8
26+
# 环境配置的依赖文件中含有打包所需依赖
27+
run: |
28+
pip install -r "src/环境配置/requirements.txt"
29+
pip list
30+
echo =================UPX====================
31+
$upx_url = (Invoke-WebRequest -Uri https://api.github.com/repos/upx/upx/releases/latest).Content | ConvertFrom-Json | Select-Object -ExpandProperty assets | Where-Object { $_.name -like "*win64.zip" } | Select-Object -ExpandProperty browser_download_url
32+
Write-Host "[INFO] Latest UPX download URL: $upx_url"
33+
Invoke-WebRequest -Uri $upx_url -OutFile "upx-latest.zip"
34+
7z x "upx-latest.zip" -o"."
35+
del "upx-latest.zip"
36+
tree /a /f
37+
38+
- name: 复制许可文件
39+
run: |
40+
Copy-Item -Path "LICENSE" -Destination "src/LICENSE" -Verbose
41+
42+
- name: 移除Git文件
43+
run: |
44+
Remove-Item -Path "src/Tools/【实验性工具】/定时闹钟/铃声文件/.gitkeep" -Verbose
45+
Remove-Item -Path "src/Tools/进制转换/进制转换(旧).cxx" -Verbose
46+
Remove-Item -Path "src/Tools/WSA小工具(终止更新)" -Recurse -Verbose
47+
48+
- name: 打包 C++ 文件
49+
run: |
50+
windres "src/resource.rc" -o "src/resource.o" -v
51+
52+
# Tools/创建文件
53+
clang++ "src/Tools/创建文件/创建文件.cxx" "src/resource.o" -o "src/Tools/创建文件/创建文件.exe" -finput-charset=UTF-8 -fexec-charset=UTF-8 -v
54+
Remove-Item -Path "src/Tools/创建文件/创建文件.cxx" -Verbose
55+
56+
# Tools/字母大小写互换
57+
clang++ "src/Tools/字母大小写互换/字母大小写互换.cxx" "src/resource.o" -o "src/Tools/字母大小写互换/字母大小写互换.exe" -finput-charset=UTF-8 -fexec-charset=UTF-8 -v
58+
Remove-Item -Path "src/Tools/字母大小写互换/字母大小写互换.cxx" -Verbose
59+
60+
# Tools/摩斯密码
61+
Copy-Item -Path "src/Tools/摩斯密码/源码/编码源码.cxx" -Destination "src/Tools/摩斯密码/编码.cxx" -Verbose
62+
Copy-Item -Path "src/Tools/摩斯密码/源码/解码源码.cxx" -Destination "src/Tools/摩斯密码/解码.cxx" -Verbose
63+
Remove-Item -Path "src/Tools/摩斯密码/源码" -Recurse -Verbose
64+
clang++ "src/Tools/摩斯密码/编码.cxx" "src/resource.o" -o "src/Tools/摩斯密码/编码.exe" -finput-charset=UTF-8 -fexec-charset=UTF-8 -v
65+
clang++ "src/Tools/摩斯密码/解码.cxx" "src/resource.o" -o "src/Tools/摩斯密码/解码.exe" -finput-charset=UTF-8 -fexec-charset=UTF-8 -v
66+
Remove-Item -Path "src/Tools/摩斯密码/编码.cxx" -Verbose
67+
Remove-Item -Path "src/Tools/摩斯密码/解码.cxx" -Verbose
68+
69+
# 移除资源文件
70+
Remove-Item -Path "src/resource.rc" -Verbose
71+
Remove-Item -Path "src/resource.o" -Verbose
72+
73+
- name: 构建 lite 版
74+
# 整理文件 > 压缩文件 > 清理工作目录
75+
env:
76+
PYTHONIOENCODING: utf-8
77+
run: |
78+
Copy-Item -Path "src" -Destination "Release/Fufu_Tools.v${{ github.event.inputs.version }}-lite" -Recurse -Verbose
79+
Remove-Item -Path "Release/Fufu_Tools.v${{ github.event.inputs.version }}-lite/芙芙工具箱(for安装程序).pyw" -Verbose
80+
Remove-Item -Path "Release/Fufu_Tools.v${{ github.event.inputs.version }}-lite/芙芙工具箱(for打包).pyw" -Verbose
81+
Remove-Item -Path "Release/Fufu_Tools.v${{ github.event.inputs.version }}-lite/Tools/【实验性工具】/hosts修改/调用(For-打包版).py" -Verbose
82+
Remove-Item -Path "Release/Fufu_Tools.v${{ github.event.inputs.version }}-lite/Tools/休息一下/自启动设置(For-打包版).py" -Verbose
83+
84+
# 更新版本号
85+
python "自动化脚本/修改版本号.py" "${{ github.event.inputs.version }}" "lite" "Release/Fufu_Tools.v${{ github.event.inputs.version }}-lite"
86+
87+
# 压缩为 zip
88+
7z a -tzip "Release/Fufu_Tools.v${{ github.event.inputs.version }}-lite.zip" "Release/Fufu_Tools.v${{ github.event.inputs.version }}-lite/*"
89+
# 压缩为 7z
90+
7z a -t7z "Release/Fufu_Tools.v${{ github.event.inputs.version }}-lite.7z" "Release/Fufu_Tools.v${{ github.event.inputs.version }}-lite/*"
91+
# 清理工作目录
92+
Remove-Item -Path "Release/Fufu_Tools.v${{ github.event.inputs.version }}-lite" -Recurse -Verbose
93+
94+
- name: 构建打包版与安装程序版
95+
# 顺便为安装程序版一起打包,打包完复制一份
96+
env:
97+
PYTHONIOENCODING: utf-8
98+
run: |
99+
Copy-Item -Path "src" -Destination "Release/Fufu_Tools.v${{ github.event.inputs.version }}" -Recurse -Verbose
100+
Remove-Item -Path "Release/Fufu_Tools.v${{ github.event.inputs.version }}/芙芙工具箱.pyw" -Verbose
101+
Rename-Item -Path "Release/Fufu_Tools.v${{ github.event.inputs.version }}/芙芙工具箱(for打包).pyw" -NewName "芙芙工具箱.pyw" -Verbose
102+
Remove-Item -Path "Release/Fufu_Tools.v${{ github.event.inputs.version }}/Tools/【实验性工具】/hosts修改/调用.py" -Verbose
103+
Rename-Item -Path "Release/Fufu_Tools.v${{ github.event.inputs.version }}/Tools/【实验性工具】/hosts修改/调用(For-打包版).py" -NewName "调用.py" -Verbose
104+
Remove-Item -Path "Release/Fufu_Tools.v${{ github.event.inputs.version }}/Tools/休息一下/自启动设置.py" -Verbose
105+
Rename-Item -Path "Release/Fufu_Tools.v${{ github.event.inputs.version }}/Tools/休息一下/自启动设置(For-打包版).py" -NewName "自启动设置.py" -Verbose
106+
107+
python "DEV-PACK.py" "Release/Fufu_Tools.v${{ github.event.inputs.version }}" "src/ico.ico" "Release/logs/pack-exe" -s
108+
109+
# 分离安装程序版
110+
Copy-Item -Path "Release/Fufu_Tools.v${{ github.event.inputs.version }}" -Destination "Release/Fufu_Tools.v${{ github.event.inputs.version }}-exe" -Recurse -Verbose
111+
Remove-Item -Path "Release/Fufu_Tools.v${{ github.event.inputs.version }}/芙芙工具箱(for安装程序).exe" -Verbose
112+
Remove-Item -Path "Release/Fufu_Tools.v${{ github.event.inputs.version }}-exe/芙芙工具箱.exe" -Verbose
113+
Rename-Item -Path "Release/Fufu_Tools.v${{ github.event.inputs.version }}-exe/芙芙工具箱(for安装程序).exe" -NewName "芙芙工具箱.exe" -Verbose
114+
115+
# 更新版本号 - 分离完后再更新版本号,如果后续有修改需要打包的文件的版本号,请在运行 DEV-PACK.py 之前更新版本号
116+
python "自动化脚本/修改版本号.py" "${{ github.event.inputs.version }}" "pack" "Release/Fufu_Tools.v${{ github.event.inputs.version }}"
117+
python "自动化脚本/修改版本号.py" "${{ github.event.inputs.version }}" "exe" "Release/Fufu_Tools.v${{ github.event.inputs.version }}-exe"
118+
119+
# 压缩为 zip - 打包版
120+
7z a -tzip "Release/Fufu_Tools.v${{ github.event.inputs.version }}.zip" "Release/Fufu_Tools.v${{ github.event.inputs.version }}/*"
121+
# 压缩为 7z - 打包版
122+
7z a -t7z "Release/Fufu_Tools.v${{ github.event.inputs.version }}.7z" "Release/Fufu_Tools.v${{ github.event.inputs.version }}/*"
123+
# 压缩为 7z - 压缩等级 9 - 极限压缩 - 打包版
124+
7z a -t7z -mx9 "Release/Fufu_Tools.v${{ github.event.inputs.version }}-Extreme_compression.7z" "Release/Fufu_Tools.v${{ github.event.inputs.version }}/*"
125+
# 清理工作目录 - 打包版
126+
Remove-Item -Path "Release/Fufu_Tools.v${{ github.event.inputs.version }}" -Recurse -Verbose
127+
128+
# 编译安装程序 - 安装程序版
129+
Invoke-WebRequest -Uri "https://raw.githubusercontent.com/jrsoftware/issrc/main/Files/Languages/Unofficial/ChineseSimplified.isl" -OutFile "C:\Program Files (x86)\Inno Setup 6\Languages\ChineseSimplified.isl"
130+
iscc "Installer/Installer.iss"
131+
# 清理工作目录 - 安装程序版
132+
Remove-Item -Path "Release/Fufu_Tools.v${{ github.event.inputs.version }}-exe" -Recurse -Verbose
133+
134+
- name: 上传构建文件
135+
uses: actions/upload-artifact@v4
136+
with:
137+
name: Release
138+
path: Release/**

.gitignore

+10-6
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,23 @@ build/
1313
版权留存/
1414

1515
# Example
16-
Tools/开发工具/输出示例.py
16+
src/Tools/开发工具/输出示例.py
1717

1818
# Only for me
19-
Tools/开发工具/Script/本地/
19+
src/Tools/开发工具/Script/本地/
2020

2121
# Test
22-
Tools/【实验性工具】/音频处理/test/
23-
Tools/【实验性工具】/音频处理/__pycache__
22+
src/Tools/【实验性工具】/音频处理/__pycache__
2423
test/
24+
test.*
25+
26+
# C++
27+
resource.o
2528

2629
# TEST Output
27-
Tools/【实验性工具】/音频处理/output.txt
28-
Tools/【实验性工具】/音频处理/input.txt
30+
src/Tools/【实验性工具】/音频处理/output.txt
31+
src/Tools/【实验性工具】/音频处理/input.txt
32+
查找结果.txt
2933

3034
# node / npm / JavaScript
3135
package-lock.json

DEV-PACK.py

+63-37
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import sys
33
import subprocess
44
from colorama import init, Fore
5-
from plyer import notification
65

76
# ------------------------- 警告 -------------------------
87
# 本工具仅作为开发人员打包发行版时使用,请勿单独使用!!!!
@@ -26,9 +25,18 @@
2625
fcount = 0 # 已打包的文件个数
2726
pyw_acount = 0
2827
py_acount = 0
28+
silent = False
2929

30-
# 文件夹路径
31-
folder_path = input("请输入文件夹路径:")
30+
if sys.argv[4].lower() in ["-s", "--silent", "silent", "quiet", "-q", "--quiet", "/s", "/q", "/silent", "/quiet"]:
31+
silent = True
32+
else:
33+
from plyer import notification
34+
35+
if not sys.argv[1]:
36+
# 文件夹路径
37+
folder_path = input("请输入文件夹路径:")
38+
else:
39+
folder_path = sys.argv[1]
3240

3341
if folder_path.startswith(("'", '"')) and folder_path.endswith(("'", '"')):
3442
folder_path = folder_path[1:-1]
@@ -38,11 +46,21 @@
3846

3947
if not os.path.exists(folder_path):
4048
print(f"{Fore.RED}{Fore.RESET} 指定的目录路径不存在,请重新运行程序并输入有效的目录路径。")
41-
input("按 ENTER 键继续...")
49+
if not silent:
50+
input("按 ENTER 键继续...")
4251
exit(1)
4352

44-
icon_path = input("请输入图标文件路径:")
45-
log_path = input("请输入日志文件存放文件夹:")
53+
if not sys.argv[2]:
54+
# 图标文件路径
55+
icon_path = input("请输入图标文件路径:")
56+
else:
57+
icon_path = sys.argv[2]
58+
59+
if not sys.argv[3]:
60+
# 日志文件存放文件夹
61+
log_path = input("请输入日志文件存放文件夹:")
62+
else:
63+
log_path = sys.argv[3]
4664

4765
if not icon_path:
4866
icon_path = "None"
@@ -56,6 +74,8 @@
5674
elif not log_path.endswith('\\'):
5775
log_path += '\\'
5876

77+
os.makedirs(log_path, exist_ok=True)
78+
5979
for root, dirs, files in os.walk(folder_path):
6080
for file in files:
6181
if file.endswith('.py'):
@@ -110,13 +130,14 @@ def package_py(file_path, log_file="None"):
110130
print(f"{Fore.RED}打包 {Fore.BLUE}{file_path}{Fore.RED} 时出错:\n{e}")
111131
fail += 1
112132
fcount += 1
113-
notification.notify(
114-
title='Pyinstaller快速打包程序提醒您',
115-
message=f'打包程序炸啦!到现在一共炸了{fail}次。',
116-
timeout=10
117-
)
133+
if not silent:
134+
notification.notify(
135+
title='Pyinstaller快速打包程序提醒您',
136+
message=f'打包程序炸啦!到现在一共炸了{fail}次。',
137+
timeout=10
138+
)
118139
print(f"{Fore.GREEN}还剩 {Fore.BLUE}{acount-fcount}{Fore.GREEN} 个文件待打包。")
119-
if input(f"{Fore.BLUE}?{Fore.RESET} 是否继续打包 [Y/N]:").lower() not in ["y", "yes", "是", "继续"]:
140+
if silent or input(f"{Fore.BLUE}?{Fore.RESET} 是否继续打包 [Y/N]:").lower() not in ["y", "yes", "是", "继续"]:
120141
sys.exit(1)
121142
return file_path
122143

@@ -153,13 +174,14 @@ def package_pyw(file_path, log_file="None"):
153174
print(f"{Fore.RED}打包 {Fore.BLUE}{file_path}{Fore.RED} 时出错:\n{e}")
154175
fail += 1
155176
fcount += 1
156-
notification.notify(
157-
title='Pyinstaller快速打包程序提醒您',
158-
message=f'打包程序炸啦!到现在一共炸了{fail}次。',
159-
timeout=10
160-
)
177+
if not silent:
178+
notification.notify(
179+
title='Pyinstaller快速打包程序提醒您',
180+
message=f'打包程序炸啦!到现在一共炸了{fail}次。',
181+
timeout=10
182+
)
161183
print(f"{Fore.GREEN}还剩 {Fore.BLUE}{acount-fcount}{Fore.GREEN} 个文件待打包。")
162-
if input(f"{Fore.BLUE}?{Fore.RESET} 是否继续打包 [Y/N]:").lower() not in ["y", "yes", "是", "继续"]:
184+
if silent or input(f"{Fore.BLUE}?{Fore.RESET} 是否继续打包 [Y/N]:").lower() not in ["y", "yes", "是", "继续"]:
163185
sys.exit(1)
164186
return file_path
165187

@@ -180,7 +202,7 @@ def package_pyw(file_path, log_file="None"):
180202
if failed_file:
181203
failed_files.append(failed_file)
182204
else:
183-
with open(os.path.join(log_path, "packaging.log"), "a") as log_file:
205+
with open(os.path.join(log_path, "packaging.log"), "a", encoding="utf-8") as log_file:
184206
# 打开日志文件,准备记录日志
185207
log_message(f"开始打包,需要打包的文件数量:{acount}", log_file)
186208

@@ -204,23 +226,25 @@ def package_pyw(file_path, log_file="None"):
204226

205227
# 提示用户打包完成
206228
if fail != 0:
207-
input(f"打包完成,一共炸了{fail}次。请按 Enter 键继续清除原文件...")
208-
notification.notify(
209-
title='Pyinstaller快速打包程序提醒您',
210-
message=f'打包完成,一共炸了{fail}次。',
211-
timeout=10
212-
)
229+
if not silent:
230+
input(f"打包完成,一共炸了{fail}次。请按 Enter 键继续清除原文件...")
231+
notification.notify(
232+
title='Pyinstaller快速打包程序提醒您',
233+
message=f'打包完成,一共炸了{fail}次。',
234+
timeout=10
235+
)
213236
# 输出打包失败的文件
214237
print("以下文件打包失败:")
215238
for failed_file in failed_files:
216239
print(failed_file)
217240
else:
218-
notification.notify(
219-
title='Pyinstaller快速打包程序提醒您',
220-
message=f'打包完成,没炸!',
221-
timeout=10
222-
)
223-
input(f"打包完成,没炸!请按 Enter 键继续清除原文件...")
241+
if not silent:
242+
notification.notify(
243+
title='Pyinstaller快速打包程序提醒您',
244+
message=f'打包完成,没炸!',
245+
timeout=10
246+
)
247+
input(f"打包完成,没炸!请按 Enter 键继续清除原文件...")
224248

225249
# 删除指定格式的文件
226250
for root, dirs, files in os.walk(folder_path):
@@ -231,11 +255,13 @@ def package_pyw(file_path, log_file="None"):
231255
os.remove(file_path)
232256
print(f'{Fore.GREEN}{Fore.RESET} 已删除源文件: {file_path} (还剩 {acount-countd} 个源文件)')
233257

234-
notification.notify(
235-
title='Pyinstaller快速打包程序提醒您',
236-
message=f'文件删除完成!总共删除了{countd}个原文件',
237-
timeout=10
238-
)
258+
if not silent:
259+
notification.notify(
260+
title='Pyinstaller快速打包程序提醒您',
261+
message=f'文件删除完成!总共删除了{countd}个原文件',
262+
timeout=10
263+
)
239264
print(f"{Fore.GREEN}文件删除完成!总共删除了 {Fore.BLUE}{countd}{Fore.RESET} 个原文件")
240265

241-
input ("按 ENTER 键继续...")
266+
if not silent:
267+
input("按 ENTER 键继续...")

Installer/Fufu_Tools_Setup_ico.ico

13.3 KB
Binary file not shown.

Installer/Installer.iss

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
[Setup]
2+
AppName=芙芙工具箱
3+
AppVersion=develop
4+
VersionInfoVersion=develop
5+
AppPublisher=DuckStudio
6+
VersionInfoCopyright=Copyright (c) 鸭鸭「カモ」
7+
AppPublisherURL=https://duckduckstudio.github.io/yazicbs.github.io/
8+
AppSupportURL=https://github.com/DuckDuckStudio/Fufu_Tools/issues
9+
DefaultDirName={autopf}\Fufu_Tools
10+
DefaultGroupName=芙芙工具箱
11+
OutputDir=..\Release
12+
OutputBaseFilename=Fufu_Tools_Setup.vdevelop.exe
13+
SetupIconFile=Fufu_Tools_Setup_ico.ico
14+
LicenseFile=LICENSE
15+
Compression=lzma2
16+
SolidCompression=yes
17+
18+
[Languages]
19+
Name: "english"; MessagesFile: "compiler:Default.isl"
20+
Name: "chinesesimplified"; MessagesFile: "compiler:Languages\ChineseSimplified.isl"
21+
Name: "japanese"; MessagesFile: "compiler:Languages\Japanese.isl"
22+
23+
[Tasks]
24+
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked
25+
26+
[Files]
27+
Source: "..\Release\Fufu_Tools.vdevelop-exe\*"; DestDir: "{app}"; Flags: recursesubdirs
28+
; 这里的 v 不要去掉,替换版本号时不会替换 v
29+
30+
[Icons]
31+
Name: "{autoprograms}\芙芙工具箱"; Filename: "{app}\芙芙工具箱.exe"
32+
Name: "{autodesktop}\芙芙工具箱"; Filename: "{app}\芙芙工具箱.exe"; Tasks: desktopicon

0 commit comments

Comments
 (0)