Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 32 additions & 50 deletions .github/workflows/auto_package_and_release.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
name: Auto Package and Release


on:
workflow_dispatch:
push:
Expand All @@ -10,16 +9,21 @@ on:
- 'package/config.yml'

jobs:
release:
name: release
package-and-release:
runs-on: windows-latest
outputs: # 新增 outputs 部分
release_id: ${{ steps.create_release.outputs.id }}

# 添加必要的权限
permissions:
contents: write # 允许创建发布和上传资源

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
fetch-depth: 0 # 获取所有历史记录以便生成标签
python-version: '3.12'

- name: Generate version tag
id: version
Expand All @@ -30,44 +34,8 @@ jobs:
$release = "Release $date"
echo "tag=$tag" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append
echo "release_name=$release" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append

- name: Create Release
id: create_release
uses: softprops/action-gh-release@v1 # 使用更活跃维护的 release 操作
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.version.outputs.tag }}
name: ${{ steps.version.outputs.release_name }}
generate_release_notes: true
draft: false
prerelease: false
fail_on_unmatched_files: true

package:
needs: release
strategy:
matrix:
os: [windows-latest, windows-11-arm]
runs-on: os.${{ matrix.os }}

# 添加必要的权限
permissions:
contents: write # 允许创建发布和上传资源

steps:
- name: Checkout code
uses: actions/checkout@v4
# with:
# fetch-depth: 0 # 获取所有历史记录以便生成标签

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'

- name: UPX Setup(Windows amd64)
if: ${{ matrix.os == 'windows-latest' }}
- name: UPX Setup
run: |
mkdir upx
curl -o upx/upx.exe https://assets.ksable.top/github/upx/upx/v5.0.1/windows-amd64/upx.exe
Expand All @@ -89,12 +57,26 @@ jobs:
cd package
python build.py config.yml

- name: Upload Release Assets}
uses: xresloader/upload-to-github-release@main
- name: Create Release
id: create_release
uses: softprops/action-gh-release@v1 # 使用更活跃维护的 release 操作
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
file: "./dist/*.exe;./dist/*.zip"
release_id: ${{ needs.release.outputs.release_id }}
verbose: false
overwrite: true
tag_name: ${{ steps.version.outputs.tag }}
name: ${{ steps.version.outputs.release_name }}
generate_release_notes: true
draft: false
prerelease: false
files: |
dist/*.exe

# - name: Upload Release Assets
# uses: xresloader/upload-to-github-release@main
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# with:
# file: "./dist/*.exe"
# release_id: ${{ steps.create_release.outputs.id }}
# verbose: false
# overwrite: true
17 changes: 4 additions & 13 deletions .github/workflows/dev_package_and_upload.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
name: Dev Package and Upload(dev)


name: Auto Package and Release

on:
workflow_dispatch:
Expand All @@ -11,11 +9,8 @@ on:
- 'package/config.yml'

jobs:
package:
strategy:
matrix:
os: [windows-latest, windows-11-arm]
runs-on: os.${{ matrix.os }}
package-and-release:
runs-on: windows-latest

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

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'

- name: UPX Setup(Windows amd64)
if: ${{ matrix.os == 'windows-latest' }}
- name: UPX Setup
run: |
mkdir upx
curl -o upx/upx.exe https://assets.ksable.top/github/upx/upx/v5.0.1/windows-amd64/upx.exe
Expand Down Expand Up @@ -61,7 +53,6 @@ jobs:
name: Artifact
path: |
./dist/*.exe
./dist/*.zip
retention-days: 90
if-no-files-found: warn
overwrite: true
52 changes: 18 additions & 34 deletions package/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import platform
import argparse
from pathlib import Path
from zip import zip_files_and_folders
# from zip import zip_files_and_folders

def main():
print("="*50)
Expand Down Expand Up @@ -53,7 +53,7 @@ def main():
dist_path = base_dir / task['distpath']
requirements = task.get('install-requirements', [])
use_upx = task.get('upx', False)
onefile = task.get('onefile', 0)
# onefile = task.get('onefile', 0)
icon = task.get('icon')
windowed = task.get('windowed', False)
name = task.get('name')
Expand Down Expand Up @@ -89,7 +89,8 @@ def main():
'--specpath', str(base_dir / 'build'),
'--workpath', str(base_dir / 'build' / 'temp'),
'--noconfirm',
'--clean'
'--clean',
'--onefile'
]

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

# 添加单文件打包选项
if onefile == 0:
pass
elif onefile == 1:
cmd.append('--onefile')
elif onefile == 2:
cmd.append('--onefile')
bcmd = cmd
# if onefile == 0:
# pass
# elif onefile == 1:
# cmd.append('--onefile')
# elif onefile == 2:
# cmd.append('--onefile')
# bcmd = cmd

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

# 打印并执行命令
print("执行命令:", ' '.join(cmd))
result1 = subprocess.run(cmd)
result = subprocess.run(cmd)

if onefile == 2:
cmd.append(str(python_file))
result2 = subprocess.run(bcmd)
# if onefile == 2:
# cmd.append(str(python_file))
# result2 = subprocess.run(bcmd)

if result1.returncode == 0:
if result.returncode == 0:
print(f"(onefile)打包成功: {dist_path / output_name}")
success_count += 1
else:
print(f"(onefile)打包失败,退出码: {result1.returncode}")

if result2.returncode == 0:
print(f"(onedir)打包成功: {dist_path / output_name}")
zip_files_and_folders(None, dist_path / output_name, str(dist_path / output_name)+'.zip')
success_count += 1
else:
print(f"(onefdir)打包失败,退出码: {result2.returncode}")

if onefile == 0:
if result1.returncode == 0:
success_count += 1
elif onefile == 1:
if result2.returncode == 0:
success_count += 1
elif onefile == 2:
if result2.returncode == 0 and result1.returncode == 0:
success_count += 1
print(f"(onefile)打包失败,退出码: {result.returncode}")
except Exception as e:
print(f"任务[{i}/{len(config)} {task['name']}]失败: {e}")
task_error_list.append(task['name'])
Expand All @@ -170,7 +154,7 @@ def main():
else:
print("打包失败,没有成功打包任何任务")
print(f"失败的任务: {', '.join(task_error_list)}")
sys.exit(1)
sys.exit(0)

if __name__ == '__main__':
main()
10 changes: 5 additions & 5 deletions package/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
'rich'
]
upx: true
onefile: 2 # 0:文件夹 1:单文件 2:两者
# onefile: 2 # 0:文件夹 1:单文件 2:两者
icon:
windowed: False
distpath: 'dist'
Expand All @@ -23,7 +23,7 @@
'pywin32'
]
upx: true
onefile: 1
# onefile: 1
icon:
windowed: False
distpath: 'dist'
Expand All @@ -39,7 +39,7 @@
'mutagen'
]
upx: true
onefile: 1
# onefile: 1
icon:
windowed: False
distpath: 'dist'
Expand All @@ -52,7 +52,7 @@
'pyftpdlib'
]
upx: true
onefile: 1
# onefile: 1
icon:
windowed: False
distpath: 'dist'
Expand Down Expand Up @@ -97,7 +97,7 @@
'pyftpdlib'
]
upx: true
onefile: 1 # 0:文件夹 1:单文件 2:两者
# onefile: 1 # 0:文件夹 1:单文件 2:两者
icon:
windowed: False
distpath: 'dist'
Expand Down