更新 .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
|
name: Build Windows EXE
|
||||||
|
|
||||||
on:
|
on:
|
||||||
workflow_dispatch:
|
|
||||||
push:
|
push:
|
||||||
branches:
|
branches: [ "main" ]
|
||||||
- main
|
workflow_dispatch: # 允许手动触发
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
runs-on: windows
|
runs-on: windows-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Show workspace
|
- name: Checkout code
|
||||||
shell: powershell
|
uses: actions/checkout@v4
|
||||||
run: |
|
|
||||||
Write-Host "Workspace: $pwd"
|
|
||||||
Get-ChildItem
|
|
||||||
|
|
||||||
- name: Locate project files
|
- name: Set up Python
|
||||||
shell: powershell
|
uses: actions/setup-python@v5
|
||||||
run: |
|
with:
|
||||||
$mainFile = Get-ChildItem -Path $pwd -Recurse -Filter main.py -File | Select-Object -First 1
|
python-version: '3.9.1' # 建议指定版本,确保稳定性
|
||||||
if (-not $mainFile) {
|
cache: 'pip' # 自动缓存依赖,加快下次构建速度
|
||||||
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: Install dependencies
|
- name: Install dependencies
|
||||||
shell: powershell
|
|
||||||
run: |
|
run: |
|
||||||
& $env:PY_CMD -m pip --version
|
python -m pip install --upgrade pip
|
||||||
& $env:PY_CMD -m pip install --upgrade pip
|
python -m pip install pyinstaller keyboard pywin32
|
||||||
& $env:PY_CMD -m pip install pyinstaller keyboard pywin32
|
|
||||||
|
|
||||||
- name: Build executable
|
- name: Build with PyInstaller
|
||||||
shell: powershell
|
|
||||||
working-directory: ${{ env.PROJECT_DIR }}
|
|
||||||
run: |
|
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
|
- name: Upload Artifact
|
||||||
shell: powershell
|
uses: actions/upload-artifact@v4
|
||||||
run: |
|
with:
|
||||||
New-Item -ItemType Directory -Force output | Out-Null
|
name: PotPlayer-Sync-Tool
|
||||||
Copy-Item "$env:PROJECT_DIR\\dist\\Shortcut_Sync_PotPlayer.exe" output/Shortcut_Sync_PotPlayer.exe -Force
|
path: dist/Shortcut_Sync_PotPlayer.exe
|
||||||
Get-ChildItem output
|
retention-days: 7 # 临时文件保存7天
|
||||||
Reference in New Issue
Block a user