Skip to content

Merge pull request #4 from sa23up/revert-3-revert-2-build-by-nuitka #3

Merge pull request #4 from sa23up/revert-3-revert-2-build-by-nuitka

Merge pull request #4 from sa23up/revert-3-revert-2-build-by-nuitka #3

Workflow file for this run

name: Build & Release (Windows)
on:
push:
branches:
- main
tags:
- "v*"
permissions:
contents: write
jobs:
build_windows:
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Derive version
id: ver
shell: pwsh
run: |
$ref = "${{ github.ref }}"
$refName = "${{ github.ref_name }}"
$isRelease = $ref.StartsWith("refs/tags/v")
$isReleaseStr = if ($isRelease) { "true" } else { "false" }
# 注意:
# - tag 构建:版本来自 vX.Y.Z(用于 exe 版本信息与安装包文件名)
# - main 构建:使用占位版本(仅用于验证构建流程),并跳过发布 Release
$version = if ($isRelease) { $refName.Substring(1) } else { "0.0.0" }
Add-Content -Path $env:GITHUB_OUTPUT -Value "version=$version"
Add-Content -Path $env:GITHUB_OUTPUT -Value "is_release=$isReleaseStr"
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install uv
shell: pwsh
run: |
python -m pip install --upgrade pip
python -m pip install --upgrade uv
uv --version
- name: Install dependencies
run: uv sync --dev --frozen
- name: Build (Nuitka standalone)
shell: pwsh
run: |
$version = '${{ steps.ver.outputs.version }}'
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass -Force
.\build.ps1 -Configuration Release -Mode standalone -Version $version -OutputDir build
- name: Build (Nuitka onefile)
shell: pwsh
run: |
$version = '${{ steps.ver.outputs.version }}'
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass -Force
.\build.ps1 -Configuration Release -Mode onefile -Version $version -OutputDir build/onefile
- name: Build installer (Inno Setup)
uses: Minionguyjpro/[email protected]
with:
path: installer/yt-dlp-gui.iss
options: /DMyAppVersion=${{ steps.ver.outputs.version }}
- name: SHA256 (setup)
id: setup
shell: pwsh
run: |
$version = '${{ steps.ver.outputs.version }}'
$setupName = "yt-dlp-gui-$version-windows-setup.exe"
$setupPath = "build/$setupName"
if (-not (Test-Path $setupPath -PathType Leaf)) { throw "未找到安装包: $setupPath" }
$shaPath = "$setupPath.sha256"
$hash = (Get-FileHash $setupPath -Algorithm SHA256).Hash.ToLowerInvariant()
"$hash $setupName" | Out-File -Encoding ascii $shaPath
Add-Content -Path $env:GITHUB_OUTPUT -Value "exe=$setupPath"
Add-Content -Path $env:GITHUB_OUTPUT -Value "sha=$shaPath"
- name: Package (portable zip) + SHA256
id: portable
shell: pwsh
run: |
$version = '${{ steps.ver.outputs.version }}'
$distDir = "build/yt_dlp_gui.dist"
if (-not (Test-Path $distDir -PathType Container)) { throw "未找到产物目录: $distDir" }
$portableRoot = "build/yt-dlp-gui-$version-windows-portable"
if (Test-Path $portableRoot) { Remove-Item -Path $portableRoot -Recurse -Force }
New-Item -ItemType Directory -Path $portableRoot | Out-Null
Copy-Item -Path "$distDir/*" -Destination $portableRoot -Recurse -Force
$zipName = "yt-dlp-gui-$version-windows-portable.zip"
$zipPath = "build/$zipName"
if (Test-Path $zipPath) { Remove-Item -Path $zipPath -Force }
Compress-Archive -Path $portableRoot -DestinationPath $zipPath
Remove-Item -Path $portableRoot -Recurse -Force
$shaPath = "$zipPath.sha256"
$hash = (Get-FileHash $zipPath -Algorithm SHA256).Hash.ToLowerInvariant()
"$hash $zipName" | Out-File -Encoding ascii $shaPath
Add-Content -Path $env:GITHUB_OUTPUT -Value "zip=$zipPath"
Add-Content -Path $env:GITHUB_OUTPUT -Value "sha=$shaPath"
- name: Prepare (onefile exe) + SHA256
id: onefile
shell: pwsh
run: |
$version = '${{ steps.ver.outputs.version }}'
$found = Get-ChildItem -Path "build/onefile" -Recurse -File -Filter "yt-dlp-gui.exe" -ErrorAction SilentlyContinue | Select-Object -First 1
if (-not $found) { throw "未找到 onefile 产物: build/onefile/**/yt-dlp-gui.exe" }
$exeName = "yt-dlp-gui-$version-windows-onefile.exe"
$exePath = "build/$exeName"
Copy-Item -Path $found.FullName -Destination $exePath -Force
$shaPath = "$exePath.sha256"
$hash = (Get-FileHash $exePath -Algorithm SHA256).Hash.ToLowerInvariant()
"$hash $exeName" | Out-File -Encoding ascii $shaPath
Add-Content -Path $env:GITHUB_OUTPUT -Value "exe=$exePath"
Add-Content -Path $env:GITHUB_OUTPUT -Value "sha=$shaPath"
- name: Upload to GitHub Release
if: steps.ver.outputs.is_release == 'true'
uses: softprops/action-gh-release@v2
with:
fail_on_unmatched_files: true
files: |
${{ steps.setup.outputs.exe }}
${{ steps.setup.outputs.sha }}
${{ steps.portable.outputs.zip }}
${{ steps.portable.outputs.sha }}
${{ steps.onefile.outputs.exe }}
${{ steps.onefile.outputs.sha }}