Skip to content

Commit 6a44c20

Browse files
authored
Merge pull request #9 from God-2077:dev
更新自动打包和发布工作流,合并开发和发布流程,优化权限设置,调整 Python 版本,修复配置文件中的单文件打包选项
2 parents 4857ff6 + c0a8511 commit 6a44c20

4 files changed

Lines changed: 59 additions & 102 deletions

File tree

Lines changed: 32 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
name: Auto Package and Release
22

3-
43
on:
54
workflow_dispatch:
65
push:
@@ -10,16 +9,21 @@ on:
109
- 'package/config.yml'
1110

1211
jobs:
13-
release:
14-
name: release
12+
package-and-release:
1513
runs-on: windows-latest
16-
outputs: # 新增 outputs 部分
17-
release_id: ${{ steps.create_release.outputs.id }}
14+
15+
# 添加必要的权限
16+
permissions:
17+
contents: write # 允许创建发布和上传资源
18+
1819
steps:
1920
- name: Checkout code
2021
uses: actions/checkout@v4
22+
23+
- name: Set up Python
24+
uses: actions/setup-python@v5
2125
with:
22-
fetch-depth: 0 # 获取所有历史记录以便生成标签
26+
python-version: '3.12'
2327

2428
- name: Generate version tag
2529
id: version
@@ -30,44 +34,8 @@ jobs:
3034
$release = "Release $date"
3135
echo "tag=$tag" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append
3236
echo "release_name=$release" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append
33-
34-
- name: Create Release
35-
id: create_release
36-
uses: softprops/action-gh-release@v1 # 使用更活跃维护的 release 操作
37-
env:
38-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
39-
with:
40-
tag_name: ${{ steps.version.outputs.tag }}
41-
name: ${{ steps.version.outputs.release_name }}
42-
generate_release_notes: true
43-
draft: false
44-
prerelease: false
45-
fail_on_unmatched_files: true
46-
47-
package:
48-
needs: release
49-
strategy:
50-
matrix:
51-
os: [windows-latest, windows-11-arm]
52-
runs-on: os.${{ matrix.os }}
5337
54-
# 添加必要的权限
55-
permissions:
56-
contents: write # 允许创建发布和上传资源
57-
58-
steps:
59-
- name: Checkout code
60-
uses: actions/checkout@v4
61-
# with:
62-
# fetch-depth: 0 # 获取所有历史记录以便生成标签
63-
64-
- name: Set up Python
65-
uses: actions/setup-python@v5
66-
with:
67-
python-version: '3.12'
68-
69-
- name: UPX Setup(Windows amd64)
70-
if: ${{ matrix.os == 'windows-latest' }}
38+
- name: UPX Setup
7139
run: |
7240
mkdir upx
7341
curl -o upx/upx.exe https://assets.ksable.top/github/upx/upx/v5.0.1/windows-amd64/upx.exe
@@ -89,12 +57,26 @@ jobs:
8957
cd package
9058
python build.py config.yml
9159
92-
- name: Upload Release Assets}
93-
uses: xresloader/upload-to-github-release@main
60+
- name: Create Release
61+
id: create_release
62+
uses: softprops/action-gh-release@v1 # 使用更活跃维护的 release 操作
9463
env:
95-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
64+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
9665
with:
97-
file: "./dist/*.exe;./dist/*.zip"
98-
release_id: ${{ needs.release.outputs.release_id }}
99-
verbose: false
100-
overwrite: true
66+
tag_name: ${{ steps.version.outputs.tag }}
67+
name: ${{ steps.version.outputs.release_name }}
68+
generate_release_notes: true
69+
draft: false
70+
prerelease: false
71+
files: |
72+
dist/*.exe
73+
74+
# - name: Upload Release Assets
75+
# uses: xresloader/upload-to-github-release@main
76+
# env:
77+
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
78+
# with:
79+
# file: "./dist/*.exe"
80+
# release_id: ${{ steps.create_release.outputs.id }}
81+
# verbose: false
82+
# overwrite: true

.github/workflows/dev_package_and_upload.yml

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
name: Dev Package and Upload(dev)
2-
3-
1+
name: Auto Package and Release
42

53
on:
64
workflow_dispatch:
@@ -11,11 +9,8 @@ on:
119
- 'package/config.yml'
1210

1311
jobs:
14-
package:
15-
strategy:
16-
matrix:
17-
os: [windows-latest, windows-11-arm]
18-
runs-on: os.${{ matrix.os }}
12+
package-and-release:
13+
runs-on: windows-latest
1914

2015
# 添加必要的权限
2116
permissions:
@@ -24,16 +19,13 @@ jobs:
2419
steps:
2520
- name: Checkout code
2621
uses: actions/checkout@v4
27-
with:
28-
fetch-depth: 0 # 获取所有历史记录以便生成标签
2922

3023
- name: Set up Python
3124
uses: actions/setup-python@v5
3225
with:
3326
python-version: '3.12'
3427

35-
- name: UPX Setup(Windows amd64)
36-
if: ${{ matrix.os == 'windows-latest' }}
28+
- name: UPX Setup
3729
run: |
3830
mkdir upx
3931
curl -o upx/upx.exe https://assets.ksable.top/github/upx/upx/v5.0.1/windows-amd64/upx.exe
@@ -61,7 +53,6 @@ jobs:
6153
name: Artifact
6254
path: |
6355
./dist/*.exe
64-
./dist/*.zip
6556
retention-days: 90
6657
if-no-files-found: warn
6758
overwrite: true

package/build.py

Lines changed: 18 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import platform
66
import argparse
77
from pathlib import Path
8-
from zip import zip_files_and_folders
8+
# from zip import zip_files_and_folders
99

1010
def main():
1111
print("="*50)
@@ -53,7 +53,7 @@ def main():
5353
dist_path = base_dir / task['distpath']
5454
requirements = task.get('install-requirements', [])
5555
use_upx = task.get('upx', False)
56-
onefile = task.get('onefile', 0)
56+
# onefile = task.get('onefile', 0)
5757
icon = task.get('icon')
5858
windowed = task.get('windowed', False)
5959
name = task.get('name')
@@ -89,7 +89,8 @@ def main():
8989
'--specpath', str(base_dir / 'build'),
9090
'--workpath', str(base_dir / 'build' / 'temp'),
9191
'--noconfirm',
92-
'--clean'
92+
'--clean',
93+
'--onefile'
9394
]
9495

9596
# 添加窗口模式选项
@@ -118,47 +119,30 @@ def main():
118119
print("不使用UPX压缩")
119120

120121
# 添加单文件打包选项
121-
if onefile == 0:
122-
pass
123-
elif onefile == 1:
124-
cmd.append('--onefile')
125-
elif onefile == 2:
126-
cmd.append('--onefile')
127-
bcmd = cmd
122+
# if onefile == 0:
123+
# pass
124+
# elif onefile == 1:
125+
# cmd.append('--onefile')
126+
# elif onefile == 2:
127+
# cmd.append('--onefile')
128+
# bcmd = cmd
128129

129130
# 添加主Python文件
130131
cmd.append(str(python_file))
131132

132133
# 打印并执行命令
133134
print("执行命令:", ' '.join(cmd))
134-
result1 = subprocess.run(cmd)
135+
result = subprocess.run(cmd)
135136

136-
if onefile == 2:
137-
cmd.append(str(python_file))
138-
result2 = subprocess.run(bcmd)
137+
# if onefile == 2:
138+
# cmd.append(str(python_file))
139+
# result2 = subprocess.run(bcmd)
139140

140-
if result1.returncode == 0:
141+
if result.returncode == 0:
141142
print(f"(onefile)打包成功: {dist_path / output_name}")
142143
success_count += 1
143144
else:
144-
print(f"(onefile)打包失败,退出码: {result1.returncode}")
145-
146-
if result2.returncode == 0:
147-
print(f"(onedir)打包成功: {dist_path / output_name}")
148-
zip_files_and_folders(None, dist_path / output_name, str(dist_path / output_name)+'.zip')
149-
success_count += 1
150-
else:
151-
print(f"(onefdir)打包失败,退出码: {result2.returncode}")
152-
153-
if onefile == 0:
154-
if result1.returncode == 0:
155-
success_count += 1
156-
elif onefile == 1:
157-
if result2.returncode == 0:
158-
success_count += 1
159-
elif onefile == 2:
160-
if result2.returncode == 0 and result1.returncode == 0:
161-
success_count += 1
145+
print(f"(onefile)打包失败,退出码: {result.returncode}")
162146
except Exception as e:
163147
print(f"任务[{i}/{len(config)} {task['name']}]失败: {e}")
164148
task_error_list.append(task['name'])
@@ -170,7 +154,7 @@ def main():
170154
else:
171155
print("打包失败,没有成功打包任何任务")
172156
print(f"失败的任务: {', '.join(task_error_list)}")
173-
sys.exit(1)
157+
sys.exit(0)
174158

175159
if __name__ == '__main__':
176160
main()

package/config.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
'rich'
99
]
1010
upx: true
11-
onefile: 2 # 0:文件夹 1:单文件 2:两者
11+
# onefile: 2 # 0:文件夹 1:单文件 2:两者
1212
icon:
1313
windowed: False
1414
distpath: 'dist'
@@ -23,7 +23,7 @@
2323
'pywin32'
2424
]
2525
upx: true
26-
onefile: 1
26+
# onefile: 1
2727
icon:
2828
windowed: False
2929
distpath: 'dist'
@@ -39,7 +39,7 @@
3939
'mutagen'
4040
]
4141
upx: true
42-
onefile: 1
42+
# onefile: 1
4343
icon:
4444
windowed: False
4545
distpath: 'dist'
@@ -52,7 +52,7 @@
5252
'pyftpdlib'
5353
]
5454
upx: true
55-
onefile: 1
55+
# onefile: 1
5656
icon:
5757
windowed: False
5858
distpath: 'dist'
@@ -97,7 +97,7 @@
9797
'pyftpdlib'
9898
]
9999
upx: true
100-
onefile: 1 # 0:文件夹 1:单文件 2:两者
100+
# onefile: 1 # 0:文件夹 1:单文件 2:两者
101101
icon:
102102
windowed: False
103103
distpath: 'dist'

0 commit comments

Comments
 (0)