|
| 1 | +name: Build & Release (Windows) |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + tags: |
| 8 | + - "v*" |
| 9 | + |
| 10 | +permissions: |
| 11 | + contents: write |
| 12 | + |
| 13 | +jobs: |
| 14 | + build_windows: |
| 15 | + runs-on: windows-latest |
| 16 | + steps: |
| 17 | + - name: Checkout |
| 18 | + uses: actions/checkout@v4 |
| 19 | + |
| 20 | + - name: Derive version |
| 21 | + id: ver |
| 22 | + shell: pwsh |
| 23 | + run: | |
| 24 | + $ref = "${{ github.ref }}" |
| 25 | + $refName = "${{ github.ref_name }}" |
| 26 | + $isRelease = $ref.StartsWith("refs/tags/v") |
| 27 | + $isReleaseStr = if ($isRelease) { "true" } else { "false" } |
| 28 | +
|
| 29 | + # 注意: |
| 30 | + # - tag 构建:版本来自 vX.Y.Z(用于 exe 版本信息与安装包文件名) |
| 31 | + # - main 构建:使用占位版本(仅用于验证构建流程),并跳过发布 Release |
| 32 | + $version = if ($isRelease) { $refName.Substring(1) } else { "0.0.0" } |
| 33 | +
|
| 34 | + Add-Content -Path $env:GITHUB_OUTPUT -Value "version=$version" |
| 35 | + Add-Content -Path $env:GITHUB_OUTPUT -Value "is_release=$isReleaseStr" |
| 36 | +
|
| 37 | + - name: Setup Python |
| 38 | + uses: actions/setup-python@v5 |
| 39 | + with: |
| 40 | + python-version: "3.12" |
| 41 | + |
| 42 | + - name: Install uv |
| 43 | + shell: pwsh |
| 44 | + run: | |
| 45 | + python -m pip install --upgrade pip |
| 46 | + python -m pip install --upgrade uv |
| 47 | + uv --version |
| 48 | +
|
| 49 | + - name: Install dependencies |
| 50 | + run: uv sync --dev --frozen |
| 51 | + |
| 52 | + - name: Build (Nuitka standalone) |
| 53 | + shell: pwsh |
| 54 | + run: | |
| 55 | + $version = '${{ steps.ver.outputs.version }}' |
| 56 | + Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass -Force |
| 57 | + .\build.ps1 -Configuration Release -Mode standalone -Version $version -OutputDir build |
| 58 | +
|
| 59 | + - name: Build (Nuitka onefile) |
| 60 | + shell: pwsh |
| 61 | + run: | |
| 62 | + $version = '${{ steps.ver.outputs.version }}' |
| 63 | + Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass -Force |
| 64 | + .\build.ps1 -Configuration Release -Mode onefile -Version $version -OutputDir build/onefile |
| 65 | +
|
| 66 | + - name: Build installer (Inno Setup) |
| 67 | + uses: Minionguyjpro/Inno-Setup-Action@v1.2.2 |
| 68 | + with: |
| 69 | + path: installer/yt-dlp-gui.iss |
| 70 | + options: /DMyAppVersion=${{ steps.ver.outputs.version }} |
| 71 | + |
| 72 | + - name: SHA256 (setup) |
| 73 | + id: setup |
| 74 | + shell: pwsh |
| 75 | + run: | |
| 76 | + $version = '${{ steps.ver.outputs.version }}' |
| 77 | + $setupName = "yt-dlp-gui-$version-windows-setup.exe" |
| 78 | + $setupPath = "build/$setupName" |
| 79 | + if (-not (Test-Path $setupPath -PathType Leaf)) { throw "未找到安装包: $setupPath" } |
| 80 | + $shaPath = "$setupPath.sha256" |
| 81 | + $hash = (Get-FileHash $setupPath -Algorithm SHA256).Hash.ToLowerInvariant() |
| 82 | + "$hash $setupName" | Out-File -Encoding ascii $shaPath |
| 83 | + Add-Content -Path $env:GITHUB_OUTPUT -Value "exe=$setupPath" |
| 84 | + Add-Content -Path $env:GITHUB_OUTPUT -Value "sha=$shaPath" |
| 85 | +
|
| 86 | + - name: Package (portable zip) + SHA256 |
| 87 | + id: portable |
| 88 | + shell: pwsh |
| 89 | + run: | |
| 90 | + $version = '${{ steps.ver.outputs.version }}' |
| 91 | + $distDir = "build/yt_dlp_gui.dist" |
| 92 | + if (-not (Test-Path $distDir -PathType Container)) { throw "未找到产物目录: $distDir" } |
| 93 | +
|
| 94 | + $portableRoot = "build/yt-dlp-gui-$version-windows-portable" |
| 95 | + if (Test-Path $portableRoot) { Remove-Item -Path $portableRoot -Recurse -Force } |
| 96 | + New-Item -ItemType Directory -Path $portableRoot | Out-Null |
| 97 | + Copy-Item -Path "$distDir/*" -Destination $portableRoot -Recurse -Force |
| 98 | +
|
| 99 | + $zipName = "yt-dlp-gui-$version-windows-portable.zip" |
| 100 | + $zipPath = "build/$zipName" |
| 101 | + if (Test-Path $zipPath) { Remove-Item -Path $zipPath -Force } |
| 102 | + Compress-Archive -Path $portableRoot -DestinationPath $zipPath |
| 103 | + Remove-Item -Path $portableRoot -Recurse -Force |
| 104 | +
|
| 105 | + $shaPath = "$zipPath.sha256" |
| 106 | + $hash = (Get-FileHash $zipPath -Algorithm SHA256).Hash.ToLowerInvariant() |
| 107 | + "$hash $zipName" | Out-File -Encoding ascii $shaPath |
| 108 | + Add-Content -Path $env:GITHUB_OUTPUT -Value "zip=$zipPath" |
| 109 | + Add-Content -Path $env:GITHUB_OUTPUT -Value "sha=$shaPath" |
| 110 | +
|
| 111 | + - name: Prepare (onefile exe) + SHA256 |
| 112 | + id: onefile |
| 113 | + shell: pwsh |
| 114 | + run: | |
| 115 | + $version = '${{ steps.ver.outputs.version }}' |
| 116 | + $found = Get-ChildItem -Path "build/onefile" -Recurse -File -Filter "yt-dlp-gui.exe" -ErrorAction SilentlyContinue | Select-Object -First 1 |
| 117 | + if (-not $found) { throw "未找到 onefile 产物: build/onefile/**/yt-dlp-gui.exe" } |
| 118 | +
|
| 119 | + $exeName = "yt-dlp-gui-$version-windows-onefile.exe" |
| 120 | + $exePath = "build/$exeName" |
| 121 | + Copy-Item -Path $found.FullName -Destination $exePath -Force |
| 122 | +
|
| 123 | + $shaPath = "$exePath.sha256" |
| 124 | + $hash = (Get-FileHash $exePath -Algorithm SHA256).Hash.ToLowerInvariant() |
| 125 | + "$hash $exeName" | Out-File -Encoding ascii $shaPath |
| 126 | + Add-Content -Path $env:GITHUB_OUTPUT -Value "exe=$exePath" |
| 127 | + Add-Content -Path $env:GITHUB_OUTPUT -Value "sha=$shaPath" |
| 128 | +
|
| 129 | + - name: Upload to GitHub Release |
| 130 | + if: steps.ver.outputs.is_release == 'true' |
| 131 | + uses: softprops/action-gh-release@v2 |
| 132 | + with: |
| 133 | + fail_on_unmatched_files: true |
| 134 | + files: | |
| 135 | + ${{ steps.setup.outputs.exe }} |
| 136 | + ${{ steps.setup.outputs.sha }} |
| 137 | + ${{ steps.portable.outputs.zip }} |
| 138 | + ${{ steps.portable.outputs.sha }} |
| 139 | + ${{ steps.onefile.outputs.exe }} |
| 140 | + ${{ steps.onefile.outputs.sha }} |
0 commit comments