From 4aedb208f0852a999b166205208bdd6134beb980 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=9B=9B=E6=9C=88?= Date: Sun, 15 Mar 2026 02:22:14 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20.github/workflows/build-ex?= =?UTF-8?q?e.yml?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/build-exe.yml | 72 ++++++++++----------------------- 1 file changed, 22 insertions(+), 50 deletions(-) diff --git a/.github/workflows/build-exe.yml b/.github/workflows/build-exe.yml index 3f42c48..ec4aeea 100644 --- a/.github/workflows/build-exe.yml +++ b/.github/workflows/build-exe.yml @@ -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天 \ No newline at end of file