Skip to content

Commit 702475a

Browse files
committed
新增:自动构建
1 parent 9c63cd9 commit 702475a

File tree

5 files changed

+174
-21
lines changed

5 files changed

+174
-21
lines changed

.github/workflows/release.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Build and Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
# 添加权限配置
9+
permissions:
10+
contents: write # 添加写入权限
11+
12+
jobs:
13+
build:
14+
runs-on: windows-latest
15+
16+
steps:
17+
- uses: actions/checkout@v4
18+
19+
- name: Set up Python
20+
uses: actions/setup-python@v5
21+
with:
22+
python-version: '3.13.2'
23+
24+
- name: Install dependencies
25+
run: |
26+
python -m pip install --upgrade pip
27+
pip install -r requirements.txt
28+
29+
- name: Build with PyInstaller
30+
run: python build.py
31+
32+
- name: Create Release
33+
uses: softprops/action-gh-release@v1
34+
with:
35+
files: dist/SD_Prompt_Manager_v*.exe
36+
draft: false
37+
prerelease: false
38+
env:
39+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,5 @@ config.json
7070
models_info.json
7171

7272
static/images/
73+
74+
version_info.txt

build.py

Lines changed: 95 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,102 @@
11
import PyInstaller.__main__
22
import os
33
import shutil
4+
from string import Template
5+
from version import *
46

5-
# 确保 static 和 templates 目录存在
6-
os.makedirs('static/images', exist_ok=True)
7-
os.makedirs('templates', exist_ok=True)
7+
def clean_dist():
8+
"""清理之前的构建文件"""
9+
output_name = f"SD_Prompt_Manager_v{VERSION_STR}"
10+
11+
try:
12+
for item in ['dist', 'build']:
13+
if os.path.exists(item):
14+
shutil.rmtree(item)
15+
16+
for item in ['version_info.txt', 'runtime_hook.py', f'{output_name}.spec']:
17+
if os.path.exists(item):
18+
os.remove(item)
19+
20+
except Exception as e:
21+
print(f"清理文件时出错: {e}")
22+
print("请手动关闭应用后重试")
23+
exit(1)
824

9-
# 定义打包参数
10-
PyInstaller.__main__.run([
11-
'model_manager.py',
12-
'--name=SD_Models_Manager',
13-
'--onefile',
14-
'--hidden-import=uvicorn.logging',
15-
'--hidden-import=uvicorn.lifespan.on',
16-
'--hidden-import=uvicorn.lifespan',
17-
'--add-data=templates;templates',
18-
'--add-data=static;static',
19-
])
25+
def generate_version_info():
26+
"""生成版本信息文件"""
27+
print(f"当前版本号: {VERSION_STR}")
28+
29+
try:
30+
with open('version_info.template', 'r', encoding='utf-8') as f:
31+
template = Template(f.read())
32+
33+
version_tuple = VERSION + (0,)
34+
variables = {
35+
'VERSION_TUPLE': str(version_tuple),
36+
'VERSION_STR': VERSION_STR,
37+
'APP_NAME': APP_NAME,
38+
'COMPANY': COMPANY,
39+
'DESCRIPTION': DESCRIPTION,
40+
'COPYRIGHT': COPYRIGHT
41+
}
42+
43+
with open('version_info.txt', 'w', encoding='utf-8') as f:
44+
f.write(template.substitute(variables))
45+
46+
except Exception as e:
47+
print(f"生成版本信息时出错: {str(e)}")
48+
raise
2049

21-
# 复制必要的目录到 dist 目录
22-
if os.path.exists('dist/static'):
23-
shutil.rmtree('dist/static')
24-
shutil.copytree('static', 'dist/static')
50+
def prepare_directories():
51+
"""准备必要的目录"""
52+
os.makedirs('static', exist_ok=True)
53+
os.makedirs('templates', exist_ok=True)
2554

26-
if os.path.exists('dist/templates'):
27-
shutil.rmtree('dist/templates')
28-
shutil.copytree('templates', 'dist/templates')
55+
def build_executable():
56+
"""构建可执行文件"""
57+
output_name = f"SD_Prompt_Manager_v{VERSION_STR}"
58+
59+
try:
60+
PyInstaller.__main__.run([
61+
'model_manager.py',
62+
f'--name={output_name}',
63+
'--onefile',
64+
'--hidden-import=uvicorn.logging',
65+
'--hidden-import=uvicorn.lifespan.on',
66+
'--hidden-import=uvicorn.lifespan',
67+
'--add-data=templates;templates',
68+
'--add-data=static/favicon.svg;static',
69+
])
70+
71+
# 复制必要的文件到 dist 目录
72+
if os.path.exists('dist/static'):
73+
shutil.rmtree('dist/static')
74+
os.makedirs('dist/static')
75+
shutil.copy2('static/favicon.svg', 'dist/static/favicon.svg')
76+
77+
if os.path.exists('dist/templates'):
78+
shutil.rmtree('dist/templates')
79+
shutil.copytree('templates', 'dist/templates')
80+
81+
print(f"构建完成: dist/{output_name}.exe")
82+
83+
except Exception as e:
84+
print(f"构建过程出错: {e}")
85+
raise
86+
87+
def main():
88+
"""主函数"""
89+
try:
90+
print("开始构建流程...")
91+
clean_dist()
92+
generate_version_info()
93+
prepare_directories()
94+
build_executable()
95+
print("构建流程完成!")
96+
97+
except Exception as e:
98+
print(f"构建过程失败: {e}")
99+
exit(1)
100+
101+
if __name__ == '__main__':
102+
main()

version.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# 版本号
2+
VERSION = (0, 1, 0) # 主版本号, 次版本号, 修订号
3+
VERSION_STR = f"{'.'.join(map(str, VERSION))}-alpha" # 自动生成版本号字符串
4+
5+
# 应用信息
6+
APP_NAME = "SD Models Manager"
7+
COMPANY = "GitHub: c1921"
8+
DESCRIPTION = "SD Prompt Manager - 提示词管理工具"
9+
COPYRIGHT = "MIT 开源许可 - 版权所有 (c) 2025"

version_info.template

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# UTF-8
2+
VSVersionInfo(
3+
ffi=FixedFileInfo(
4+
filevers=$VERSION_TUPLE,
5+
prodvers=$VERSION_TUPLE,
6+
mask=0x3f,
7+
flags=0x0,
8+
OS=0x40004,
9+
fileType=0x1,
10+
subtype=0x0,
11+
date=(0, 0)
12+
),
13+
kids=[
14+
StringFileInfo(
15+
[
16+
StringTable(
17+
u'080404B0',
18+
[StringStruct(u'CompanyName', u'$COMPANY'),
19+
StringStruct(u'FileDescription', u'$DESCRIPTION'),
20+
StringStruct(u'FileVersion', u'$VERSION_STR'),
21+
StringStruct(u'InternalName', u'SDPromptManager'),
22+
StringStruct(u'LegalCopyright', u'$COPYRIGHT'),
23+
StringStruct(u'OriginalFilename', u'SDPromptManager.exe'),
24+
StringStruct(u'ProductName', u'$APP_NAME'),
25+
StringStruct(u'ProductVersion', u'$VERSION_STR')])
26+
]),
27+
VarFileInfo([VarStruct(u'Translation', [2052, 1200])])
28+
]
29+
)

0 commit comments

Comments
 (0)