Update build.yml #55
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build (Windows/macOS/Linux) | |
on: | |
push: | |
branches: [ main, master ] | |
tags: [ 'v*' ] | |
paths: | |
- '**/*.py' | |
- 'lang/**' | |
- 'HELP.md' | |
- 'yt_audio_workbench.spec' | |
- '.github/workflows/build.yml' | |
pull_request: | |
branches: [ main, master ] | |
workflow_dispatch: | |
jobs: | |
test: | |
name: Tests (${{ matrix.os }} | py${{ matrix.python }}) | |
runs-on: ${{ matrix.os }} | |
strategy: | |
fail-fast: false | |
matrix: | |
os: [ubuntu-latest, windows-latest, macos-13, macos-14] | |
python: ['3.11'] | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-python@v5 | |
with: | |
python-version: ${{ matrix.python }} | |
- name: Install OS dependencies (Linux only) | |
if: startsWith(matrix.os, 'ubuntu') | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y python3-tk | |
- name: Install Python deps for tests | |
run: | | |
python -m pip install --upgrade pip | |
python -m pip install pytest | |
- name: Install project requirements (if requirements.txt exists) | |
if: hashFiles('requirements.txt') != '' | |
run: python -m pip install -r requirements.txt | |
- name: Run tests | |
env: | |
PYTHONPATH: ${{ github.workspace }} | |
run: python -m pytest -q | |
build: | |
name: Build (${{ matrix.os }}) | |
needs: test | |
runs-on: ${{ matrix.os }} | |
strategy: | |
fail-fast: false | |
matrix: | |
os: [ubuntu-latest, windows-latest, macos-14] | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-python@v5 | |
with: | |
python-version: '3.11' | |
- name: Install OS dependencies (Linux only) | |
if: startsWith(matrix.os, 'ubuntu') | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y python3-tk zip | |
- name: Install Python deps for build | |
run: | | |
python -m pip install --upgrade pip | |
python -m pip install pyinstaller | |
- name: Install project requirements (if requirements.txt exists) | |
if: hashFiles('requirements.txt') != '' | |
run: python -m pip install -r requirements.txt | |
- name: Build with PyInstaller | |
run: pyinstaller -y yt_audio_workbench.spec | |
- name: Show dist tree (debug) | |
shell: bash | |
run: | | |
echo "== dist/ contents ==" | |
ls -la dist || true | |
echo "== one level deeper ==" | |
find dist -maxdepth 2 -mindepth 1 -print || true | |
# ---------- Windows pack ---------- | |
- name: Pack artifact (Windows) | |
if: runner.os == 'Windows' | |
shell: pwsh | |
run: | | |
$ErrorActionPreference = 'Stop' | |
$dist = Join-Path $PWD 'dist' | |
if (-not (Test-Path $dist)) { throw "dist/ not found. Did the build step run?" } | |
# Prefer onedir folder; fallback to onefile(s) | |
$productDir = Get-ChildItem -Path $dist -Directory | Select-Object -First 1 | |
if ($productDir) { | |
$zip = "$($productDir.Name)-Windows.zip" | |
Push-Location $productDir.FullName | |
Compress-Archive -Path * -DestinationPath (Join-Path $dist $zip) -Force | |
Pop-Location | |
$zipPath = Join-Path $dist $zip | |
} else { | |
$files = Get-ChildItem -Path $dist -File | |
if (-not $files) { | |
$found = (Get-ChildItem -Path $dist | Select-Object -ExpandProperty Name) -join ', ' | |
throw "Nothing to pack in dist/. Found entries: $found" | |
} | |
$zip = 'YT-Audio-Workbench-Windows.zip' | |
Compress-Archive -Path ($files | ForEach-Object { $_.FullName }) -DestinationPath (Join-Path $dist $zip) -Force | |
$zipPath = Join-Path $dist $zip | |
} | |
"ZIP_PATH=$zipPath" | Out-File -FilePath $env:GITHUB_ENV -Append | |
# ---------- macOS / Linux pack ---------- | |
- name: Pack artifact (macOS/Linux) | |
if: runner.os != 'Windows' | |
shell: bash | |
run: | | |
set -euo pipefail | |
dist="dist" | |
[[ -d "$dist" ]] || { echo "dist/ not found"; exit 1; } | |
# Prefer an app folder (onedir). If none, zip all files (onefile case). | |
first_dir="$(find "$dist" -mindepth 1 -maxdepth 1 -type d | head -n1 || true)" | |
if [[ -n "${first_dir:-}" ]]; then | |
base="$(basename "$first_dir")" | |
zip_path="$dist/${base}-${{ runner.os }}.zip" | |
(cd "$first_dir" && zip -r "../$(basename "$zip_path")" .) | |
else | |
if ! find "$dist" -mindepth 1 -maxdepth 1 -type f | grep -q .; then | |
echo "Nothing to pack in dist/"; exit 1 | |
fi | |
zip_path="$dist/YT-Audio-Workbench-${{ runner.os }}.zip" | |
(cd "$dist" && zip -r "$(basename "$zip_path")" .) | |
fi | |
echo "ZIP_PATH=$zip_path" >> "$GITHUB_ENV" | |
- name: Upload artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
# unique name prevents 409 conflicts between matrix jobs | |
name: YT-Audio-Workbench-${{ runner.os }} | |
path: ${{ env.ZIP_PATH }} | |
if-no-files-found: error | |
retention-days: 7 | |
release: | |
name: Release on tag | |
if: startsWith(github.ref, 'refs/tags/v') | |
needs: build | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/download-artifact@v4 | |
with: | |
path: artifacts | |
- name: List artifacts | |
run: ls -R artifacts | |
- name: Create GitHub Release | |
uses: softprops/action-gh-release@v2 | |
with: | |
draft: false | |
prerelease: false | |
files: | | |
artifacts/**/YT-Audio-Workbench-*.zip | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |