Skip to content

Commit

Permalink
feat: 自动打包发行版 (#158)
Browse files Browse the repository at this point in the history
* 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: 宁静致远 <172552290+fjwxzde@users.noreply.github.com>

* fix: 还原 resource.rc

* chore(license): 更新安装程序许可文件

* Apply suggestions from code review

Co-authored-by: 宁静致远 <172552290+fjwxzde@users.noreply.github.com>

* fix: 改用 Clang 编译

Co-authored-by: 鸭鸭「カモ」 <Yzcbs123@163.com>

* fix: 修改 \ 为 /

* Apply suggestions from code review

Co-authored-by: 鸭鸭「カモ」 <Yzcbs123@163.com>

* fix: 修正日志写入

* fix: 修正编码问题

* pref: 打包 C++ 文件时输出详细过程

Co-authored-by: 鸭鸭「カモ」 <Yzcbs123@163.com>

* fix: 不接受带 v 的新版本号

Co-authored-by: 宁静致远 <172552290+fjwxzde@users.noreply.github.com>

* fix: 移除重复的条目

Co-authored-by: 鸭鸭「カモ」 <Yzcbs123@163.com>

* fix: 修改工件名

Co-authored-by: 鸭鸭「カモ」 <Yzcbs123@163.com>

* Apply suggestions from code review

Co-authored-by: 鸭鸭「カモ」 <Yzcbs123@163.com>

* fix: 清理安装程序版工作目录

Co-authored-by: 宁静致远 <172552290+fjwxzde@users.noreply.github.com>

* fix: 先下载中文翻译

Co-authored-by: 鸭鸭「カモ」 <Yzcbs123@163.com>

* Apply suggestions from code review

Co-authored-by: 宁静致远 <172552290+fjwxzde@users.noreply.github.com>

* Apply suggestions from code review

Co-authored-by: 鸭鸭「カモ」 <Yzcbs123@163.com>

---------

Co-authored-by: 宁静致远 <172552290+fjwxzde@users.noreply.github.com>
Co-authored-by: 鸭鸭「カモ」 <Yzcbs123@163.com>
  • Loading branch information
3 people authored Jan 9, 2025
1 parent 3fefcc4 commit 85502e7
Show file tree
Hide file tree
Showing 122 changed files with 561 additions and 60 deletions.
4 changes: 4 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ updates:
directory: "/" # Location of package manifests
schedule:
interval: "weekly"
- package-ecosystem: "github-actions" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "weekly"
138 changes: 138 additions & 0 deletions .github/workflows/Pack_Release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
name: Pack Releases

on:
workflow_dispatch:
inputs:
version:
description: 版本号 (不带v)
required: true

jobs:
auto-pack-releases:
runs-on: windows-latest

steps:
- name: 检出代码
uses: actions/checkout@v4

- name: 配置 Python
uses: actions/setup-python@v5
with:
python-version: 3.x

- name: 安装依赖
env:
PYTHONIOENCODING: utf-8
# 环境配置的依赖文件中含有打包所需依赖
run: |
pip install -r "src/环境配置/requirements.txt"
pip list
echo =================UPX====================
$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
Write-Host "[INFO] Latest UPX download URL: $upx_url"
Invoke-WebRequest -Uri $upx_url -OutFile "upx-latest.zip"
7z x "upx-latest.zip" -o"."
del "upx-latest.zip"
tree /a /f
- name: 复制许可文件
run: |
Copy-Item -Path "LICENSE" -Destination "src/LICENSE" -Verbose
- name: 移除Git文件
run: |
Remove-Item -Path "src/Tools/【实验性工具】/定时闹钟/铃声文件/.gitkeep" -Verbose
Remove-Item -Path "src/Tools/进制转换/进制转换(旧).cxx" -Verbose
Remove-Item -Path "src/Tools/WSA小工具(终止更新)" -Recurse -Verbose
- name: 打包 C++ 文件
run: |
windres "src/resource.rc" -o "src/resource.o" -v
# Tools/创建文件
clang++ "src/Tools/创建文件/创建文件.cxx" "src/resource.o" -o "src/Tools/创建文件/创建文件.exe" -finput-charset=UTF-8 -fexec-charset=UTF-8 -v
Remove-Item -Path "src/Tools/创建文件/创建文件.cxx" -Verbose
# Tools/字母大小写互换
clang++ "src/Tools/字母大小写互换/字母大小写互换.cxx" "src/resource.o" -o "src/Tools/字母大小写互换/字母大小写互换.exe" -finput-charset=UTF-8 -fexec-charset=UTF-8 -v
Remove-Item -Path "src/Tools/字母大小写互换/字母大小写互换.cxx" -Verbose
# Tools/摩斯密码
Copy-Item -Path "src/Tools/摩斯密码/源码/编码源码.cxx" -Destination "src/Tools/摩斯密码/编码.cxx" -Verbose
Copy-Item -Path "src/Tools/摩斯密码/源码/解码源码.cxx" -Destination "src/Tools/摩斯密码/解码.cxx" -Verbose
Remove-Item -Path "src/Tools/摩斯密码/源码" -Recurse -Verbose
clang++ "src/Tools/摩斯密码/编码.cxx" "src/resource.o" -o "src/Tools/摩斯密码/编码.exe" -finput-charset=UTF-8 -fexec-charset=UTF-8 -v
clang++ "src/Tools/摩斯密码/解码.cxx" "src/resource.o" -o "src/Tools/摩斯密码/解码.exe" -finput-charset=UTF-8 -fexec-charset=UTF-8 -v
Remove-Item -Path "src/Tools/摩斯密码/编码.cxx" -Verbose
Remove-Item -Path "src/Tools/摩斯密码/解码.cxx" -Verbose
# 移除资源文件
Remove-Item -Path "src/resource.rc" -Verbose
Remove-Item -Path "src/resource.o" -Verbose
- name: 构建 lite 版
# 整理文件 > 压缩文件 > 清理工作目录
env:
PYTHONIOENCODING: utf-8
run: |
Copy-Item -Path "src" -Destination "Release/Fufu_Tools.v${{ github.event.inputs.version }}-lite" -Recurse -Verbose
Remove-Item -Path "Release/Fufu_Tools.v${{ github.event.inputs.version }}-lite/芙芙工具箱(for安装程序).pyw" -Verbose
Remove-Item -Path "Release/Fufu_Tools.v${{ github.event.inputs.version }}-lite/芙芙工具箱(for打包).pyw" -Verbose
Remove-Item -Path "Release/Fufu_Tools.v${{ github.event.inputs.version }}-lite/Tools/【实验性工具】/hosts修改/调用(For-打包版).py" -Verbose
Remove-Item -Path "Release/Fufu_Tools.v${{ github.event.inputs.version }}-lite/Tools/休息一下/自启动设置(For-打包版).py" -Verbose
# 更新版本号
python "自动化脚本/修改版本号.py" "${{ github.event.inputs.version }}" "lite" "Release/Fufu_Tools.v${{ github.event.inputs.version }}-lite"
# 压缩为 zip
7z a -tzip "Release/Fufu_Tools.v${{ github.event.inputs.version }}-lite.zip" "Release/Fufu_Tools.v${{ github.event.inputs.version }}-lite/*"
# 压缩为 7z
7z a -t7z "Release/Fufu_Tools.v${{ github.event.inputs.version }}-lite.7z" "Release/Fufu_Tools.v${{ github.event.inputs.version }}-lite/*"
# 清理工作目录
Remove-Item -Path "Release/Fufu_Tools.v${{ github.event.inputs.version }}-lite" -Recurse -Verbose
- name: 构建打包版与安装程序版
# 顺便为安装程序版一起打包,打包完复制一份
env:
PYTHONIOENCODING: utf-8
run: |
Copy-Item -Path "src" -Destination "Release/Fufu_Tools.v${{ github.event.inputs.version }}" -Recurse -Verbose
Remove-Item -Path "Release/Fufu_Tools.v${{ github.event.inputs.version }}/芙芙工具箱.pyw" -Verbose
Rename-Item -Path "Release/Fufu_Tools.v${{ github.event.inputs.version }}/芙芙工具箱(for打包).pyw" -NewName "芙芙工具箱.pyw" -Verbose
Remove-Item -Path "Release/Fufu_Tools.v${{ github.event.inputs.version }}/Tools/【实验性工具】/hosts修改/调用.py" -Verbose
Rename-Item -Path "Release/Fufu_Tools.v${{ github.event.inputs.version }}/Tools/【实验性工具】/hosts修改/调用(For-打包版).py" -NewName "调用.py" -Verbose
Remove-Item -Path "Release/Fufu_Tools.v${{ github.event.inputs.version }}/Tools/休息一下/自启动设置.py" -Verbose
Rename-Item -Path "Release/Fufu_Tools.v${{ github.event.inputs.version }}/Tools/休息一下/自启动设置(For-打包版).py" -NewName "自启动设置.py" -Verbose
python "DEV-PACK.py" "Release/Fufu_Tools.v${{ github.event.inputs.version }}" "src/ico.ico" "Release/logs/pack-exe" -s
# 分离安装程序版
Copy-Item -Path "Release/Fufu_Tools.v${{ github.event.inputs.version }}" -Destination "Release/Fufu_Tools.v${{ github.event.inputs.version }}-exe" -Recurse -Verbose
Remove-Item -Path "Release/Fufu_Tools.v${{ github.event.inputs.version }}/芙芙工具箱(for安装程序).exe" -Verbose
Remove-Item -Path "Release/Fufu_Tools.v${{ github.event.inputs.version }}-exe/芙芙工具箱.exe" -Verbose
Rename-Item -Path "Release/Fufu_Tools.v${{ github.event.inputs.version }}-exe/芙芙工具箱(for安装程序).exe" -NewName "芙芙工具箱.exe" -Verbose
# 更新版本号 - 分离完后再更新版本号,如果后续有修改需要打包的文件的版本号,请在运行 DEV-PACK.py 之前更新版本号
python "自动化脚本/修改版本号.py" "${{ github.event.inputs.version }}" "pack" "Release/Fufu_Tools.v${{ github.event.inputs.version }}"
python "自动化脚本/修改版本号.py" "${{ github.event.inputs.version }}" "exe" "Release/Fufu_Tools.v${{ github.event.inputs.version }}-exe"
# 压缩为 zip - 打包版
7z a -tzip "Release/Fufu_Tools.v${{ github.event.inputs.version }}.zip" "Release/Fufu_Tools.v${{ github.event.inputs.version }}/*"
# 压缩为 7z - 打包版
7z a -t7z "Release/Fufu_Tools.v${{ github.event.inputs.version }}.7z" "Release/Fufu_Tools.v${{ github.event.inputs.version }}/*"
# 压缩为 7z - 压缩等级 9 - 极限压缩 - 打包版
7z a -t7z -mx9 "Release/Fufu_Tools.v${{ github.event.inputs.version }}-Extreme_compression.7z" "Release/Fufu_Tools.v${{ github.event.inputs.version }}/*"
# 清理工作目录 - 打包版
Remove-Item -Path "Release/Fufu_Tools.v${{ github.event.inputs.version }}" -Recurse -Verbose
# 编译安装程序 - 安装程序版
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"
iscc "Installer/Installer.iss"
# 清理工作目录 - 安装程序版
Remove-Item -Path "Release/Fufu_Tools.v${{ github.event.inputs.version }}-exe" -Recurse -Verbose
- name: 上传构建文件
uses: actions/upload-artifact@v4
with:
name: Release
path: Release/**
16 changes: 10 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,23 @@ build/
版权留存/

# Example
Tools/开发工具/输出示例.py
src/Tools/开发工具/输出示例.py

# Only for me
Tools/开发工具/Script/本地/
src/Tools/开发工具/Script/本地/

# Test
Tools/【实验性工具】/音频处理/test/
Tools/【实验性工具】/音频处理/__pycache__
src/Tools/【实验性工具】/音频处理/__pycache__
test/
test.*

# C++
resource.o

# TEST Output
Tools/【实验性工具】/音频处理/output.txt
Tools/【实验性工具】/音频处理/input.txt
src/Tools/【实验性工具】/音频处理/output.txt
src/Tools/【实验性工具】/音频处理/input.txt
查找结果.txt

# node / npm / JavaScript
package-lock.json
Expand Down
100 changes: 63 additions & 37 deletions DEV-PACK.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import sys
import subprocess
from colorama import init, Fore
from plyer import notification

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

# 文件夹路径
folder_path = input("请输入文件夹路径:")
if sys.argv[4].lower() in ["-s", "--silent", "silent", "quiet", "-q", "--quiet", "/s", "/q", "/silent", "/quiet"]:
silent = True
else:
from plyer import notification

if not sys.argv[1]:
# 文件夹路径
folder_path = input("请输入文件夹路径:")
else:
folder_path = sys.argv[1]

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

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

icon_path = input("请输入图标文件路径:")
log_path = input("请输入日志文件存放文件夹:")
if not sys.argv[2]:
# 图标文件路径
icon_path = input("请输入图标文件路径:")
else:
icon_path = sys.argv[2]

if not sys.argv[3]:
# 日志文件存放文件夹
log_path = input("请输入日志文件存放文件夹:")
else:
log_path = sys.argv[3]

if not icon_path:
icon_path = "None"
Expand All @@ -56,6 +74,8 @@
elif not log_path.endswith('\\'):
log_path += '\\'

os.makedirs(log_path, exist_ok=True)

for root, dirs, files in os.walk(folder_path):
for file in files:
if file.endswith('.py'):
Expand Down Expand Up @@ -110,13 +130,14 @@ def package_py(file_path, log_file="None"):
print(f"{Fore.RED}打包 {Fore.BLUE}{file_path}{Fore.RED} 时出错:\n{e}")
fail += 1
fcount += 1
notification.notify(
title='Pyinstaller快速打包程序提醒您',
message=f'打包程序炸啦!到现在一共炸了{fail}次。',
timeout=10
)
if not silent:
notification.notify(
title='Pyinstaller快速打包程序提醒您',
message=f'打包程序炸啦!到现在一共炸了{fail}次。',
timeout=10
)
print(f"{Fore.GREEN}还剩 {Fore.BLUE}{acount-fcount}{Fore.GREEN} 个文件待打包。")
if input(f"{Fore.BLUE}?{Fore.RESET} 是否继续打包 [Y/N]:").lower() not in ["y", "yes", "是", "继续"]:
if silent or input(f"{Fore.BLUE}?{Fore.RESET} 是否继续打包 [Y/N]:").lower() not in ["y", "yes", "是", "继续"]:
sys.exit(1)
return file_path

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

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

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

# 提示用户打包完成
if fail != 0:
input(f"打包完成,一共炸了{fail}次。请按 Enter 键继续清除原文件...")
notification.notify(
title='Pyinstaller快速打包程序提醒您',
message=f'打包完成,一共炸了{fail}次。',
timeout=10
)
if not silent:
input(f"打包完成,一共炸了{fail}次。请按 Enter 键继续清除原文件...")
notification.notify(
title='Pyinstaller快速打包程序提醒您',
message=f'打包完成,一共炸了{fail}次。',
timeout=10
)
# 输出打包失败的文件
print("以下文件打包失败:")
for failed_file in failed_files:
print(failed_file)
else:
notification.notify(
title='Pyinstaller快速打包程序提醒您',
message=f'打包完成,没炸!',
timeout=10
)
input(f"打包完成,没炸!请按 Enter 键继续清除原文件...")
if not silent:
notification.notify(
title='Pyinstaller快速打包程序提醒您',
message=f'打包完成,没炸!',
timeout=10
)
input(f"打包完成,没炸!请按 Enter 键继续清除原文件...")

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

notification.notify(
title='Pyinstaller快速打包程序提醒您',
message=f'文件删除完成!总共删除了{countd}个原文件',
timeout=10
)
if not silent:
notification.notify(
title='Pyinstaller快速打包程序提醒您',
message=f'文件删除完成!总共删除了{countd}个原文件',
timeout=10
)
print(f"{Fore.GREEN}文件删除完成!总共删除了 {Fore.BLUE}{countd}{Fore.RESET} 个原文件")

input ("按 ENTER 键继续...")
if not silent:
input("按 ENTER 键继续...")
Binary file added Installer/Fufu_Tools_Setup_ico.ico
Binary file not shown.
32 changes: 32 additions & 0 deletions Installer/Installer.iss
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[Setup]
AppName=芙芙工具箱
AppVersion=develop
VersionInfoVersion=develop
AppPublisher=DuckStudio
VersionInfoCopyright=Copyright (c) 鸭鸭「カモ」
AppPublisherURL=https://duckduckstudio.github.io/yazicbs.github.io/
AppSupportURL=https://github.com/DuckDuckStudio/Fufu_Tools/issues
DefaultDirName={autopf}\Fufu_Tools
DefaultGroupName=芙芙工具箱
OutputDir=..\Release
OutputBaseFilename=Fufu_Tools_Setup.vdevelop.exe
SetupIconFile=Fufu_Tools_Setup_ico.ico
LicenseFile=LICENSE
Compression=lzma2
SolidCompression=yes

[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"
Name: "chinesesimplified"; MessagesFile: "compiler:Languages\ChineseSimplified.isl"
Name: "japanese"; MessagesFile: "compiler:Languages\Japanese.isl"

[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked

[Files]
Source: "..\Release\Fufu_Tools.vdevelop-exe\*"; DestDir: "{app}"; Flags: recursesubdirs
; 这里的 v 不要去掉,替换版本号时不会替换 v

[Icons]
Name: "{autoprograms}\芙芙工具箱"; Filename: "{app}\芙芙工具箱.exe"
Name: "{autodesktop}\芙芙工具箱"; Filename: "{app}\芙芙工具箱.exe"; Tasks: desktopicon
Loading

0 comments on commit 85502e7

Please sign in to comment.