update build-windows.yml

This commit is contained in:
Mohamed
2025-08-27 02:52:50 +03:00
committed by GitHub
parent 700ec8e27e
commit defdedc9b1
+251 -213
View File
@@ -1,214 +1,252 @@
name: Build Windows Release name: Build Windows Release
on: on:
push: push:
tags: tags:
- 'v*' - 'v*'
env: env:
PYTHON_VERSION: '3.12.10' PYTHON_VERSION: '3.12.10'
jobs: jobs:
build-windows: build-windows:
runs-on: windows-latest runs-on: windows-latest
steps: steps:
- name: Checkout code - name: Checkout code
uses: actions/checkout@v4 uses: actions/checkout@v4
with: with:
fetch-depth: 0 fetch-depth: 0
- name: Extract version from tag - name: Extract version from tag
id: get_version id: get_version
shell: powershell shell: powershell
run: | run: |
$tag = "${{ github.ref_name }}" $tag = "${{ github.ref_name }}"
$version = $tag -replace '^v', '' $version = $tag -replace '^v', ''
Write-Host "Extracted version: $version" Write-Host "Extracted version: $version"
echo "VERSION=$version" >> $env:GITHUB_OUTPUT echo "VERSION=$version" >> $env:GITHUB_OUTPUT
- name: Setup Python - name: Setup Python
uses: actions/setup-python@v4 uses: actions/setup-python@v4
with: with:
python-version: ${{ env.PYTHON_VERSION }} python-version: ${{ env.PYTHON_VERSION }}
- name: Cache Python dependencies - name: Cache Python dependencies
uses: actions/cache@v3 uses: actions/cache@v3
with: with:
path: | path: |
venv venv
~\AppData\Local\pip\Cache ~\AppData\Local\pip\Cache
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: | restore-keys: |
${{ runner.os }}-pip- ${{ runner.os }}-pip-
- name: Create virtual environment and install dependencies - name: Create virtual environment and install dependencies
shell: powershell shell: powershell
run: | run: |
python -m venv venv python -m venv venv
.\venv\Scripts\Activate.ps1 .\venv\Scripts\Activate.ps1
python -m pip install --upgrade pip python -m pip install --upgrade pip
pip install --no-cache-dir -r requirements.txt pip install --no-cache-dir -r requirements.txt
pip install --no-cache-dir cx_Freeze pip install --no-cache-dir cx_Freeze
pip install --no-cache-dir yt-dlp pip install --no-cache-dir yt-dlp
- name: Update version in setup files - name: Update version in setup files
shell: powershell shell: powershell
run: | run: |
$version = "${{ steps.get_version.outputs.VERSION }}" $version = "${{ steps.get_version.outputs.VERSION }}"
Write-Host "Updating version to: $version" Write-Host "Updating version to: $version"
# Update setup.py # Update setup.py
$setupContent = Get-Content "build/windows/setup.py" -Raw $setupContent = Get-Content "build/windows/setup.py" -Raw
$setupContent = $setupContent -replace 'version="[^"]*"', "version=`"$version`"" $setupContent = $setupContent -replace 'version="[^"]*"', "version=`"$version`""
Set-Content "build/windows/setup.py" -Value $setupContent Set-Content "build/windows/setup.py" -Value $setupContent
# Update setup-ffmpeg.py # Update setup-ffmpeg.py
$setupFFmpegContent = Get-Content "build/windows/setup-ffmpeg.py" -Raw $setupFFmpegContent = Get-Content "build/windows/setup-ffmpeg.py" -Raw
$setupFFmpegContent = $setupFFmpegContent -replace 'version="[^"]*"', "version=`"$version`"" $setupFFmpegContent = $setupFFmpegContent -replace 'version="[^"]*"', "version=`"$version`""
Set-Content "build/windows/setup-ffmpeg.py" -Value $setupFFmpegContent Set-Content "build/windows/setup-ffmpeg.py" -Value $setupFFmpegContent
Write-Host "Version updated in setup files (build script auto-detects version)" Write-Host "Version updated in setup files (build script auto-detects version)"
- name: Build Standard Version (MSI + ZIP) - name: Build Standard Version (MSI + ZIP)
shell: powershell shell: powershell
run: | run: |
.\venv\Scripts\Activate.ps1 .\venv\Scripts\Activate.ps1
Write-Host "Building Standard Version..." Write-Host "Building Standard Version..."
# Clean previous build artifacts # Clean previous build artifacts
if (Test-Path "build\exe.*") { Remove-Item "build\exe.*" -Recurse -Force } if (Test-Path "build\exe.*") { Remove-Item "build\exe.*" -Recurse -Force }
if (Test-Path "dist") { Remove-Item "dist" -Recurse -Force } if (Test-Path "dist") { Remove-Item "dist" -Recurse -Force }
# Build executable # Build executable
python build\windows\setup.py build python build\windows\setup.py build
# Build MSI installer # Build MSI installer
python build\windows\setup.py bdist_msi python build\windows\setup.py bdist_msi
# Create ZIP distribution # Create ZIP distribution
$exeDir = Get-ChildItem -Path "build" -Directory -Filter "exe.*" | Select-Object -First 1 $exeDir = Get-ChildItem -Path "build" -Directory -Filter "exe.*" | Select-Object -First 1
if ($exeDir) { if ($exeDir) {
$version = "${{ steps.get_version.outputs.VERSION }}" $version = "${{ steps.get_version.outputs.VERSION }}"
Compress-Archive -Path "$($exeDir.FullName)\*" -DestinationPath "dist\YTSage-v$version.zip" -Force Compress-Archive -Path "$($exeDir.FullName)\*" -DestinationPath "dist\YTSage-v$version.zip" -Force
Write-Host "Created ZIP: YTSage-v$version.zip" Write-Host "Created ZIP: YTSage-v$version.zip"
} }
- name: Build FFmpeg Version (MSI + ZIP) - name: Setup FFmpeg for bundle
shell: powershell shell: powershell
run: | run: |
.\venv\Scripts\Activate.ps1 Write-Host "Setting up FFmpeg for bundled version..."
Write-Host "Building FFmpeg Version..."
# Create ffmpeg directory
# Clean previous build artifacts New-Item -ItemType Directory -Path "ffmpeg-temp" -Force
if (Test-Path "build\exe.*") { Remove-Item "build\exe.*" -Recurse -Force }
if (Test-Path "dist\*.msi") { Remove-Item "dist\*.msi" -Force } # Download FFmpeg
$ffmpegUrl = "https://github.com/BtbN/FFmpeg-Builds/releases/download/latest/ffmpeg-master-latest-win64-gpl.zip"
# Build executable with FFmpeg Write-Host "Downloading FFmpeg from: $ffmpegUrl"
python build\windows\setup-ffmpeg.py build Invoke-WebRequest -Uri $ffmpegUrl -OutFile "ffmpeg-temp\ffmpeg.zip"
# Build MSI installer with FFmpeg # Extract FFmpeg
python build\windows\setup-ffmpeg.py bdist_msi Expand-Archive -Path "ffmpeg-temp\ffmpeg.zip" -DestinationPath "ffmpeg-temp" -Force
# Create ZIP distribution with FFmpeg # Find the extracted directory (it has a timestamp in the name)
$exeDir = Get-ChildItem -Path "build" -Directory -Filter "exe.*" | Select-Object -First 1 $ffmpegDir = Get-ChildItem -Path "ffmpeg-temp" -Directory | Where-Object { $_.Name -like "ffmpeg-*" } | Select-Object -First 1
if ($exeDir) {
$version = "${{ steps.get_version.outputs.VERSION }}" if ($ffmpegDir) {
Compress-Archive -Path "$($exeDir.FullName)\*" -DestinationPath "dist\YTSage-v$version-ffmpeg.zip" -Force # Set environment variable for the build
Write-Host "Created ZIP: YTSage-v$version-ffmpeg.zip" $ffmpegBinPath = Join-Path $ffmpegDir.FullName "bin"
} Write-Host "FFmpeg binaries found at: $ffmpegBinPath"
echo "FFMPEG_PATH=$ffmpegBinPath" >> $env:GITHUB_ENV
- name: Prepare release artifacts
shell: powershell # Verify files exist
run: | $ffmpegExe = Join-Path $ffmpegBinPath "ffmpeg.exe"
$version = "${{ steps.get_version.outputs.VERSION }}" $ffprobeExe = Join-Path $ffmpegBinPath "ffprobe.exe"
$ffplayExe = Join-Path $ffmpegBinPath "ffplay.exe"
Write-Host "Preparing artifacts for version: $version"
New-Item -ItemType Directory -Path "artifacts" -Force if (Test-Path $ffmpegExe) { Write-Host "✓ ffmpeg.exe found" } else { Write-Host "✗ ffmpeg.exe missing" }
if (Test-Path $ffprobeExe) { Write-Host "✓ ffprobe.exe found" } else { Write-Host "✗ ffprobe.exe missing" }
# Find and copy standard build artifacts from dist directory if (Test-Path $ffplayExe) { Write-Host "✓ ffplay.exe found" } else { Write-Host "✗ ffplay.exe missing" }
$standardMsi = Get-ChildItem -Path "dist" -Filter "*.msi" | Where-Object { $_.Name -notlike "*ffmpeg*" } | Select-Object -First 1 } else {
if ($standardMsi) { Write-Host "Error: Could not find FFmpeg directory after extraction"
Copy-Item $standardMsi.FullName "artifacts\YTSage-v$version.msi" exit 1
Write-Host "Copied: $($standardMsi.Name) -> YTSage-v$version.msi" }
}
- name: Build FFmpeg Version (MSI + ZIP)
$standardZip = Get-ChildItem -Path "dist" -Filter "YTSage-v$version.zip" | Select-Object -First 1 shell: powershell
if ($standardZip) { run: |
Copy-Item $standardZip.FullName "artifacts\YTSage-v$version.zip" .\venv\Scripts\Activate.ps1
Write-Host "Copied: $($standardZip.Name) -> YTSage-v$version.zip" Write-Host "Building FFmpeg Version..."
}
# Clean previous build artifacts
# Find and copy FFmpeg build artifacts from dist directory if (Test-Path "build\exe.*") { Remove-Item "build\exe.*" -Recurse -Force }
$ffmpegMsi = Get-ChildItem -Path "dist" -Filter "*.msi" | Where-Object { $_.Name -like "*ffmpeg*" } | Select-Object -First 1 if (Test-Path "dist\*.msi") { Remove-Item "dist\*.msi" -Force }
if ($ffmpegMsi) {
Copy-Item $ffmpegMsi.FullName "artifacts\YTSage-v$version-ffmpeg.msi" # Build executable with FFmpeg
Write-Host "Copied: $($ffmpegMsi.Name) -> YTSage-v$version-ffmpeg.msi" python build\windows\setup-ffmpeg.py build
}
# Build MSI installer with FFmpeg
$ffmpegZip = Get-ChildItem -Path "dist" -Filter "YTSage-v$version-ffmpeg.zip" | Select-Object -First 1 python build\windows\setup-ffmpeg.py bdist_msi
if ($ffmpegZip) {
Copy-Item $ffmpegZip.FullName "artifacts\YTSage-v$version-ffmpeg.zip" # Create ZIP distribution with FFmpeg
Write-Host "Copied: $($ffmpegZip.Name) -> YTSage-v$version-ffmpeg.zip" $exeDir = Get-ChildItem -Path "build" -Directory -Filter "exe.*" | Select-Object -First 1
} if ($exeDir) {
$version = "${{ steps.get_version.outputs.VERSION }}"
# List all artifacts Compress-Archive -Path "$($exeDir.FullName)\*" -DestinationPath "dist\YTSage-v$version-ffmpeg.zip" -Force
Write-Host "Final artifacts:" Write-Host "Created ZIP: YTSage-v$version-ffmpeg.zip"
Get-ChildItem artifacts | ForEach-Object { Write-Host " $($_.Name)" } }
- name: Create draft release - name: Prepare release artifacts
uses: softprops/action-gh-release@v1 shell: powershell
with: run: |
tag_name: ${{ github.ref_name }} $version = "${{ steps.get_version.outputs.VERSION }}"
name: YTSage ${{ github.ref_name }}
draft: true Write-Host "Preparing artifacts for version: $version"
prerelease: false New-Item -ItemType Directory -Path "artifacts" -Force
body: |
# YTSage ${{ github.ref_name }} # Find and copy standard build artifacts from dist directory
$standardMsi = Get-ChildItem -Path "dist" -Filter "*.msi" | Where-Object { $_.Name -notlike "*ffmpeg*" } | Select-Object -First 1
**Release Date**: ${{ github.event.head_commit.timestamp }} if ($standardMsi) {
Copy-Item $standardMsi.FullName "artifacts\YTSage-v$version.msi"
## Downloads Write-Host "Copied: $($standardMsi.Name) -> YTSage-v$version.msi"
}
### Standard Version
- **YTSage-v${{ steps.get_version.outputs.VERSION }}.msi** - Windows Installer (Recommended) $standardZip = Get-ChildItem -Path "dist" -Filter "YTSage-v$version.zip" | Select-Object -First 1
- **YTSage-v${{ steps.get_version.outputs.VERSION }}.zip** - Portable ZIP (No installation required) if ($standardZip) {
Copy-Item $standardZip.FullName "artifacts\YTSage-v$version.zip"
### FFmpeg Bundle Version Write-Host "Copied: $($standardZip.Name) -> YTSage-v$version.zip"
- **YTSage-v${{ steps.get_version.outputs.VERSION }}-ffmpeg.msi** - Windows Installer with FFmpeg included }
- **YTSage-v${{ steps.get_version.outputs.VERSION }}-ffmpeg.zip** - Portable ZIP with FFmpeg included
# Find and copy FFmpeg build artifacts from dist directory
## Installation Instructions $ffmpegMsi = Get-ChildItem -Path "dist" -Filter "*.msi" | Where-Object { $_.Name -like "*ffmpeg*" } | Select-Object -First 1
if ($ffmpegMsi) {
### MSI Installer Copy-Item $ffmpegMsi.FullName "artifacts\YTSage-v$version-ffmpeg.msi"
1. Download the `.msi` file Write-Host "Copied: $($ffmpegMsi.Name) -> YTSage-v$version-ffmpeg.msi"
2. Double-click to run the installer }
3. Follow the installation wizard
4. YTSage will be available in your Start Menu $ffmpegZip = Get-ChildItem -Path "dist" -Filter "YTSage-v$version-ffmpeg.zip" | Select-Object -First 1
if ($ffmpegZip) {
### Portable ZIP Copy-Item $ffmpegZip.FullName "artifacts\YTSage-v$version-ffmpeg.zip"
1. Download the `.zip` file Write-Host "Copied: $($ffmpegZip.Name) -> YTSage-v$version-ffmpeg.zip"
2. Extract to your preferred location }
3. Run `YTSage.exe`
# List all artifacts
## System Requirements Write-Host "Final artifacts:"
Get-ChildItem artifacts | ForEach-Object { Write-Host " $($_.Name)" }
- Windows 10/11 (64-bit)
- .NET Framework (usually pre-installed) - name: Create draft release
- Internet connection for yt-dlp updates uses: softprops/action-gh-release@v1
with:
## Notes tag_name: ${{ github.ref_name }}
name: YTSage ${{ github.ref_name }}
- Standard version: Downloads FFmpeg automatically when needed draft: true
- FFmpeg bundle: Includes FFmpeg binaries for offline use prerelease: false
body: |
--- # YTSage ${{ github.ref_name }}
**Full Changelog**: https://github.com/${{ github.repository }}/compare/${{ github.ref_name }} **Release Date**: ${{ github.event.head_commit.timestamp }}
files: |
artifacts/YTSage-v${{ steps.get_version.outputs.VERSION }}.msi ## Downloads
artifacts/YTSage-v${{ steps.get_version.outputs.VERSION }}.zip
artifacts/YTSage-v${{ steps.get_version.outputs.VERSION }}-ffmpeg.msi ### Standard Version
artifacts/YTSage-v${{ steps.get_version.outputs.VERSION }}-ffmpeg.zip - **YTSage-v${{ steps.get_version.outputs.VERSION }}.msi** - Windows Installer (Recommended)
env: - **YTSage-v${{ steps.get_version.outputs.VERSION }}.zip** - Portable ZIP (No installation required)
### FFmpeg Bundle Version
- **YTSage-v${{ steps.get_version.outputs.VERSION }}-ffmpeg.msi** - Windows Installer with FFmpeg included
- **YTSage-v${{ steps.get_version.outputs.VERSION }}-ffmpeg.zip** - Portable ZIP with FFmpeg included
## Installation Instructions
### MSI Installer
1. Download the `.msi` file
2. Double-click to run the installer
3. Follow the installation wizard
4. YTSage will be available in your Start Menu
### Portable ZIP
1. Download the `.zip` file
2. Extract to your preferred location
3. Run `YTSage.exe`
## System Requirements
- Windows 10/11 (64-bit)
- .NET Framework (usually pre-installed)
- Internet connection for yt-dlp updates
## Notes
- Standard version: Downloads FFmpeg automatically when needed
- FFmpeg bundle: Includes FFmpeg binaries for offline use
---
**Full Changelog**: https://github.com/${{ github.repository }}/compare/${{ github.ref_name }}
files: |
artifacts/YTSage-v${{ steps.get_version.outputs.VERSION }}.msi
artifacts/YTSage-v${{ steps.get_version.outputs.VERSION }}.zip
artifacts/YTSage-v${{ steps.get_version.outputs.VERSION }}-ffmpeg.msi
artifacts/YTSage-v${{ steps.get_version.outputs.VERSION }}-ffmpeg.zip
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}