更新 .github/workflows/build-exe.yml
Some checks failed
Build Windows EXE / build (push) Failing after 13s
Some checks failed
Build Windows EXE / build (push) Failing after 13s
This commit is contained in:
72
.github/workflows/build-exe.yml
vendored
72
.github/workflows/build-exe.yml
vendored
@@ -1,66 +1,38 @@
|
||||
name: Build Windows EXE
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
branches: [ "main" ]
|
||||
workflow_dispatch: # 允许手动触发
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: windows
|
||||
runs-on: windows-latest
|
||||
|
||||
steps:
|
||||
- name: Show workspace
|
||||
shell: powershell
|
||||
run: |
|
||||
Write-Host "Workspace: $pwd"
|
||||
Get-ChildItem
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Locate project files
|
||||
shell: powershell
|
||||
run: |
|
||||
$mainFile = Get-ChildItem -Path $pwd -Recurse -Filter main.py -File | Select-Object -First 1
|
||||
if (-not $mainFile) {
|
||||
Write-Error "Could not find main.py in workspace."
|
||||
}
|
||||
|
||||
$projectDir = $mainFile.Directory.FullName
|
||||
"PROJECT_DIR=$projectDir" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
|
||||
Write-Host "Project directory: $projectDir"
|
||||
Get-ChildItem $projectDir
|
||||
|
||||
- name: Detect Python
|
||||
shell: powershell
|
||||
run: |
|
||||
if (Get-Command py -ErrorAction SilentlyContinue) {
|
||||
"PY_CMD=py" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
|
||||
py --version
|
||||
}
|
||||
elseif (Get-Command python -ErrorAction SilentlyContinue) {
|
||||
"PY_CMD=python" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
|
||||
python --version
|
||||
}
|
||||
else {
|
||||
Write-Error "Python is not installed or not available in PATH. Install Python on the runner, or add py/python to PATH."
|
||||
}
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: '3.9.1' # 建议指定版本,确保稳定性
|
||||
cache: 'pip' # 自动缓存依赖,加快下次构建速度
|
||||
|
||||
- name: Install dependencies
|
||||
shell: powershell
|
||||
run: |
|
||||
& $env:PY_CMD -m pip --version
|
||||
& $env:PY_CMD -m pip install --upgrade pip
|
||||
& $env:PY_CMD -m pip install pyinstaller keyboard pywin32
|
||||
python -m pip install --upgrade pip
|
||||
python -m pip install pyinstaller keyboard pywin32
|
||||
|
||||
- name: Build executable
|
||||
shell: powershell
|
||||
working-directory: ${{ env.PROJECT_DIR }}
|
||||
- name: Build with PyInstaller
|
||||
run: |
|
||||
& $env:PY_CMD -m PyInstaller --noconfirm --onefile --windowed --name Shortcut_Sync_PotPlayer main.py
|
||||
# --clean 确保清理旧缓存
|
||||
# --admin-access 如果你的程序需要监听全局钩子,有时需要此权限
|
||||
python -m PyInstaller --noconfirm --onefile --windowed --name "Shortcut_Sync_PotPlayer" main.py
|
||||
|
||||
- name: Collect build output
|
||||
shell: powershell
|
||||
run: |
|
||||
New-Item -ItemType Directory -Force output | Out-Null
|
||||
Copy-Item "$env:PROJECT_DIR\\dist\\Shortcut_Sync_PotPlayer.exe" output/Shortcut_Sync_PotPlayer.exe -Force
|
||||
Get-ChildItem output
|
||||
- name: Upload Artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: PotPlayer-Sync-Tool
|
||||
path: dist/Shortcut_Sync_PotPlayer.exe
|
||||
retention-days: 7 # 临时文件保存7天
|
||||
Reference in New Issue
Block a user