Skip to content

Commit 408632e

Browse files
committed
refactor: 优化 release workflow 与跨平台兼容性
- 优化 release 构建/发布流程 - 改善跨平台 UI/系统处理 - 规范类型注解,消除 Pylance 非致命警告
1 parent a966121 commit 408632e

File tree

5 files changed

+233
-179
lines changed

5 files changed

+233
-179
lines changed

.github/workflows/build-release.yml

Lines changed: 124 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -1,168 +1,175 @@
11
name: Build & Release
22

3-
permissions:
4-
contents: write
5-
63
on:
74
release:
85
types: [published]
96
workflow_dispatch:
107
inputs:
118
tag:
9+
description: 'Release tag (e.g., v1.2.3)'
1210
required: true
1311
type: string
1412

15-
jobs:
16-
build-windows:
17-
name: Build Windows x64 App
18-
runs-on: windows-latest
19-
steps:
20-
- name: Checkout code
21-
uses: actions/checkout@v5
22-
- name: Set up Python
23-
uses: actions/setup-python@v6
24-
with:
25-
python-version: '3.14'
26-
- name: Install dependencies
27-
run: |
28-
python -m venv .venv
29-
.venv\Scripts\activate
30-
python -m pip install --upgrade pip
31-
pip install pyinstaller
32-
pip install -r requirements.txt
33-
- name: Build app with PyInstaller
34-
run: |
35-
.venv\Scripts\pyinstaller ./tchMaterial-parser.spec
36-
cd dist
37-
mv tchMaterial-parser.exe tchMaterial-parser-windows-x64.exe
38-
- name: Upload Release Asset
39-
uses: softprops/action-gh-release@v2
40-
with:
41-
files: dist/tchMaterial-parser-windows-x64.exe
42-
tag_name: ${{ inputs.tag || github.ref_name }}
43-
env:
44-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
13+
permissions:
14+
contents: read
4515

16+
concurrency:
17+
group: release-${{ inputs.tag || github.ref_name }}
18+
cancel-in-progress: false
19+
20+
env:
21+
PYTHON_VERSION: '3.14'
22+
SPEC_PATH: 'tchMaterial-parser.spec'
23+
DIST_DIR: 'dist'
24+
25+
jobs:
4626
build-linux:
47-
name: Build Linux x64 App
48-
runs-on: ubuntu-latest
27+
name: Build (Linux)
28+
runs-on: ${{ matrix.runs_on }}
29+
strategy:
30+
fail-fast: false
31+
matrix:
32+
include:
33+
- runs_on: ubuntu-latest
34+
artifact_name: tchMaterial-parser-linux-x64
35+
- runs_on: ubuntu-24.04-arm
36+
artifact_name: tchMaterial-parser-linux-arm64
37+
defaults:
38+
run:
39+
shell: bash
4940
steps:
5041
- name: Checkout code
5142
uses: actions/checkout@v5
43+
5244
- name: Set up Python
5345
uses: actions/setup-python@v6
5446
with:
55-
python-version: '3.14'
47+
python-version: ${{ env.PYTHON_VERSION }}
48+
cache: pip
49+
cache-dependency-path: requirements.txt
50+
51+
- name: Create virtual environment
52+
run: python -m venv .venv
53+
5654
- name: Install dependencies
5755
run: |
58-
python -m venv .venv
59-
source .venv/bin/activate
60-
python -m pip install --upgrade pip
61-
pip install pyinstaller
62-
pip install -r requirements.txt
63-
- name: Build app with PyInstaller
56+
./.venv/bin/python -m pip install --upgrade pip
57+
./.venv/bin/python -m pip install pyinstaller -r requirements.txt
58+
59+
- name: Build app
6460
run: |
65-
.venv/bin/pyinstaller ./tchMaterial-parser.spec
66-
cd dist
67-
mv tchMaterial-parser tchMaterial-parser-linux-x64
68-
- name: Upload Release Asset
69-
uses: softprops/action-gh-release@v2
61+
./.venv/bin/python -m PyInstaller ${{ env.SPEC_PATH }}
62+
mv "${{ env.DIST_DIR }}/tchMaterial-parser" "${{ env.DIST_DIR }}/${{ matrix.artifact_name }}"
63+
64+
- name: Upload artifact
65+
uses: actions/upload-artifact@v4
7066
with:
71-
files: dist/tchMaterial-parser-linux-x64
72-
tag_name: ${{ inputs.tag || github.ref_name }}
73-
env:
74-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
67+
name: ${{ matrix.artifact_name }}
68+
path: ${{ env.DIST_DIR }}/${{ matrix.artifact_name }}
69+
if-no-files-found: error
7570

76-
build-linux-arm64:
77-
name: Build Linux ARM64 App
78-
runs-on: ubuntu-24.04-arm
71+
build-windows:
72+
name: Build (Windows)
73+
runs-on: windows-latest
74+
defaults:
75+
run:
76+
shell: pwsh
7977
steps:
8078
- name: Checkout code
8179
uses: actions/checkout@v5
80+
8281
- name: Set up Python
8382
uses: actions/setup-python@v6
8483
with:
85-
python-version: '3.14'
84+
python-version: ${{ env.PYTHON_VERSION }}
85+
cache: pip
86+
cache-dependency-path: requirements.txt
87+
88+
- name: Create virtual environment
89+
run: python -m venv .venv
90+
8691
- name: Install dependencies
8792
run: |
88-
python -m venv .venv
89-
source .venv/bin/activate
90-
python -m pip install --upgrade pip
91-
pip install pyinstaller
92-
pip install -r requirements.txt
93-
- name: Build app with PyInstaller
93+
.\.venv\Scripts\python -m pip install --upgrade pip
94+
.\.venv\Scripts\python -m pip install pyinstaller -r requirements.txt
95+
96+
- name: Build app
9497
run: |
95-
.venv/bin/pyinstaller ./tchMaterial-parser.spec
96-
cd dist
97-
mv tchMaterial-parser tchMaterial-parser-linux-arm64
98-
- name: Upload Release Asset
99-
uses: softprops/action-gh-release@v2
98+
.\.venv\Scripts\python -m PyInstaller $env:SPEC_PATH
99+
Move-Item "$env:DIST_DIR\\tchMaterial-parser.exe" "$env:DIST_DIR\\tchMaterial-parser-windows-x64.exe"
100+
101+
- name: Upload artifact
102+
uses: actions/upload-artifact@v4
100103
with:
101-
files: dist/tchMaterial-parser-linux-arm64
102-
tag_name: ${{ inputs.tag || github.ref_name }}
103-
env:
104-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
104+
name: tchMaterial-parser-windows-x64.exe
105+
path: ${{ env.DIST_DIR }}/tchMaterial-parser-windows-x64.exe
106+
if-no-files-found: error
105107

106108
build-macos:
107-
name: Build macOS ARM64 App
109+
name: Build (macOS ARM64)
108110
runs-on: macos-latest
111+
defaults:
112+
run:
113+
shell: bash
109114
steps:
110115
- name: Checkout code
111116
uses: actions/checkout@v5
112-
117+
113118
- name: Set up Python
114119
uses: actions/setup-python@v6
115120
with:
116-
python-version: '3.12' # 推荐使用 3.12 稳定版
117-
121+
python-version: ${{ env.PYTHON_VERSION }}
122+
cache: pip
123+
cache-dependency-path: requirements.txt
124+
125+
- name: Create virtual environment
126+
run: python -m venv .venv
127+
118128
- name: Install dependencies
119129
run: |
120-
python -m venv .venv
121-
source .venv/bin/activate
122-
python -m pip install --upgrade pip
123-
pip install pyinstaller
124-
pip install -r requirements.txt
125-
126-
- name: Build app with PyInstaller
127-
run: |
128-
# 激活虚拟环境
129-
source .venv/bin/activate
130-
131-
# 执行打包命令
132-
# --clean: 清理缓存
133-
# --onefile: 强制生成单文件
134-
# --name: 指定输出文件名
135-
# --add-data: 打包资源文件 (格式为 源路径:目标路径)
136-
# src/tchMaterial-parser.pyw: 你的入口脚本
137-
138-
pyinstaller --clean --onefile --name tchMaterial-parser \
139-
--add-data "res:res" \
140-
--add-data "version.txt:." \
141-
src/tchMaterial-parser.pyw
142-
143-
- name: Sign the binary
144-
run: |
145-
# 对生成的单文件进行 Ad-hoc 签名
146-
# 这一步是解决“文件已损坏”的核心
147-
codesign --force --deep --sign - dist/tchMaterial-parser
130+
./.venv/bin/python -m pip install --upgrade pip
131+
./.venv/bin/python -m pip install pyinstaller -r requirements.txt
132+
133+
- name: Build app
134+
run: ./.venv/bin/python -m PyInstaller ${{ env.SPEC_PATH }}
135+
136+
- name: Ad-hoc sign app bundle
137+
run: codesign --force --deep --sign - "${{ env.DIST_DIR }}/tchMaterial-parser.app"
148138

149139
- name: Create zip archive
150140
run: |
151-
cd dist
152-
# 改名为带架构后缀的文件名
153-
mv tchMaterial-parser tchMaterial-parser-mac-arm64
154-
155-
# 赋予可执行权限(双重保险)
156-
chmod +x tchMaterial-parser-mac-arm64
157-
158-
# 压缩为 zip
159-
zip -r tchMaterial-parser-mac-arm64.zip tchMaterial-parser-mac-arm64
160-
161-
- name: Upload Release Asset
141+
cd "${{ env.DIST_DIR }}"
142+
zip -r "tchMaterial-parser-mac-arm64.zip" "tchMaterial-parser.app"
143+
144+
- name: Upload artifact
145+
uses: actions/upload-artifact@v4
146+
with:
147+
name: tchMaterial-parser-mac-arm64.zip
148+
path: ${{ env.DIST_DIR }}/tchMaterial-parser-mac-arm64.zip
149+
if-no-files-found: error
150+
151+
release:
152+
name: Publish release
153+
runs-on: ubuntu-latest
154+
needs:
155+
- build-linux
156+
- build-windows
157+
- build-macos
158+
permissions:
159+
contents: write
160+
steps:
161+
- name: Download artifacts
162+
uses: actions/download-artifact@v4
163+
with:
164+
path: dist
165+
merge-multiple: true
166+
167+
- name: Upload release assets
162168
uses: softprops/action-gh-release@v2
163169
with:
164-
files: dist/tchMaterial-parser-mac-arm64.zip
170+
files: |
171+
dist/tchMaterial-parser-windows-x64.exe
172+
dist/tchMaterial-parser-linux-x64
173+
dist/tchMaterial-parser-linux-arm64
174+
dist/tchMaterial-parser-mac-arm64.zip
165175
tag_name: ${{ inputs.tag || github.ref_name }}
166-
env:
167-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
168-

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2025 肥宅水水呀
3+
Copyright (c) 2026 肥宅水水呀
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ psutil
22
pywin32; sys_platform == "win32"
33
requests
44
pyperclip
5-
pypdf
5+
pypdf

0 commit comments

Comments
 (0)