ci: Add GitHub Actions workflow for build and release #136
Workflow file for this run
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 & Release Cross-Platform | |
| on: | |
| push: | |
| tags: | |
| - 'v*.*.*' | |
| permissions: | |
| contents: write | |
| jobs: | |
| runtime: | |
| name: Build license-plate runtime (${{ matrix.platform_tag }}) | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: | |
| - os: windows-latest | |
| platform_tag: win32-x64 | |
| provider: dml | |
| archive_ext: zip | |
| - os: ubuntu-latest | |
| platform_tag: linux-x64 | |
| provider: cpu | |
| archive_ext: tar.xz | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Setup Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.11' | |
| cache: 'pip' | |
| - name: Build runtime archive | |
| run: > | |
| python python_src/build_license_plate_runtime.py | |
| --platform ${{ matrix.platform_tag }} | |
| --provider ${{ matrix.provider }} | |
| --archive ${{ matrix.archive_ext }} | |
| --runtime-version ${{ github.ref_name }} | |
| - name: Collect runtime artifacts | |
| shell: bash | |
| run: | | |
| set -e | |
| mkdir -p runtime_artifacts | |
| cp python_src/build/license_plate_runtime/dist/license-plate-runtime-${{ matrix.platform_tag }}* runtime_artifacts/ | |
| - name: Upload runtime artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: runtime-${{ matrix.platform_tag }} | |
| path: runtime_artifacts/ | |
| build: | |
| name: Build ${{ matrix.version_type }} (${{ matrix.os }}) | |
| needs: runtime | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| os: [windows-latest, ubuntu-latest] | |
| version_type: [lite, intellect] | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| steps: | |
| - name: Configure caches | |
| shell: bash | |
| run: | | |
| echo "ELECTRON_CACHE=$RUNNER_TEMP/electron" >> "$GITHUB_ENV" | |
| echo "ELECTRON_BUILDER_CACHE=$RUNNER_TEMP/electron-builder" >> "$GITHUB_ENV" | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| lfs: true | |
| - name: List files for debugging | |
| run: ls -R | |
| shell: bash | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| cache: 'npm' | |
| - name: Install Node.js dependencies | |
| run: npm ci | |
| - name: Setup Python | |
| if: matrix.version_type == 'intellect' | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.11' | |
| cache: 'pip' | |
| - name: Install Linux dependencies | |
| if: ${{ matrix.os == 'ubuntu-latest' }} | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y libfuse2 | |
| - name: Setup UPX (Linux) | |
| if: ${{ matrix.os == 'ubuntu-latest' }} | |
| shell: bash | |
| run: | | |
| set -e | |
| curl -LO https://github.com/upx/upx/releases/download/v4.2.1/upx-4.2.1-amd64_linux.tar.xz | |
| tar -xf upx-4.2.1-amd64_linux.tar.xz | |
| echo "UPX_DIR=$(pwd)/upx-4.2.1-amd64_linux" >> $GITHUB_ENV | |
| - name: Setup UPX (Windows) | |
| if: ${{ matrix.os == 'windows-latest' }} | |
| shell: powershell | |
| run: | | |
| Invoke-WebRequest -Uri https://github.com/upx/upx/releases/download/v4.2.1/upx-4.2.1-win64.zip -OutFile upx-4.2.1-win64.zip | |
| if (Test-Path upx-4.2.1-win64) { Remove-Item upx-4.2.1-win64 -Recurse -Force } | |
| Expand-Archive upx-4.2.1-win64.zip -DestinationPath . | |
| $dir = Resolve-Path .\upx-4.2.1-win64 | |
| "UPX_DIR=$dir" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append | |
| - name: Clean bundled analytics directory | |
| if: matrix.version_type == 'intellect' | |
| run: rm -rf extra/analytics | |
| shell: bash | |
| - name: Disable UPX for PyInstaller (Linux) | |
| if: ${{ matrix.version_type == 'intellect' && matrix.os == 'ubuntu-latest' }} | |
| shell: bash | |
| run: mv "$UPX_DIR/upx" "$UPX_DIR/upx.disabled" | |
| - name: Disable UPX for PyInstaller (Windows) | |
| if: ${{ matrix.version_type == 'intellect' && matrix.os == 'windows-latest' }} | |
| shell: powershell | |
| run: Rename-Item "$env:UPX_DIR\upx.exe" "upx.disabled.exe" | |
| - name: Build Python analytics executables | |
| if: matrix.version_type == 'intellect' | |
| run: python ./python_src/build_analytics.py | |
| - name: Enable UPX for PyInstaller (Linux) | |
| if: ${{ matrix.version_type == 'intellect' && matrix.os == 'ubuntu-latest' }} | |
| shell: bash | |
| run: mv "$UPX_DIR/upx.disabled" "$UPX_DIR/upx" | |
| - name: Enable UPX for PyInstaller (Windows) | |
| if: ${{ matrix.version_type == 'intellect' && matrix.os == 'windows-latest' }} | |
| shell: powershell | |
| run: Rename-Item "$env:UPX_DIR\upx.disabled.exe" "upx.exe" | |
| - name: Compress analytics executables with UPX (Linux) | |
| if: ${{ matrix.version_type == 'intellect' && matrix.os == 'ubuntu-latest' }} | |
| shell: bash | |
| run: | | |
| "$UPX_DIR/upx" --lzma extra/analytics/analytics_cpu | |
| - name: Compress analytics executables with UPX (Windows) | |
| if: ${{ matrix.version_type == 'intellect' && matrix.os == 'windows-latest' }} | |
| shell: powershell | |
| run: | | |
| & "$env:UPX_DIR\upx.exe" --lzma --force extra/analytics/analytics_cpu.exe | |
| & "$env:UPX_DIR\upx.exe" --lzma --force extra/analytics/analytics_dml.exe | |
| - name: List built analytics files (Linux) | |
| if: ${{ matrix.version_type == 'intellect' && matrix.os == 'ubuntu-latest' }} | |
| run: ls -R extra/analytics | |
| shell: bash | |
| - name: List built analytics files (Windows) | |
| if: ${{ matrix.version_type == 'intellect' && matrix.os == 'windows-latest' }} | |
| shell: cmd | |
| run: dir extra\analytics /s | |
| - name: Build and package Electron app (Linux) | |
| if: ${{ matrix.os == 'ubuntu-latest' }} | |
| run: npm run dist:${{ matrix.version_type }} -- --linux --publish never | |
| env: | |
| GH_TOKEN: ${{ env.GH_TOKEN }} | |
| - name: Build and package Electron app (Windows) | |
| if: ${{ matrix.os == 'windows-latest' }} | |
| run: npm run dist:${{ matrix.version_type }} -- --win --publish never | |
| env: | |
| GH_TOKEN: ${{ env.GH_TOKEN }} | |
| shell: powershell | |
| - name: Compress installers with UPX (Linux) | |
| if: ${{ matrix.os == 'ubuntu-latest' }} | |
| shell: bash | |
| run: | | |
| if [ -d dist ]; then | |
| find dist -type f \( -name '*.AppImage' -o -perm /111 \) -print0 | while IFS= read -r -d '' file; do | |
| echo "Compressing: $file" | |
| "$UPX_DIR/upx" --best --lzma "$file" || echo "UPX failed on $file" | |
| done | |
| else | |
| echo "No dist directory found, skipping installer compression" | |
| fi | |
| - name: Compress installers with UPX (Windows) | |
| if: ${{ matrix.os == 'windows-latest' }} | |
| shell: powershell | |
| run: | | |
| if (Test-Path dist) { | |
| Get-ChildItem -Path dist -Recurse -File -Include *.exe,*.msi | ForEach-Object { | |
| Write-Host "Compressing: $($_.FullName)" | |
| try { & "$env:UPX_DIR\upx.exe" --best --lzma $_.FullName } catch { Write-Warning "UPX failed on $($_.FullName): $_" } | |
| } | |
| } else { | |
| Write-Warning 'No dist folder found; skipping installer compression' | |
| } | |
| - name: Upload build artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: ${{ matrix.os }}-${{ matrix.version_type }}-build | |
| path: dist/ | |
| create_release: | |
| name: Create GitHub Release | |
| needs: | |
| - build | |
| - runtime | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Download all artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| path: artifacts | |
| merge-multiple: true | |
| - name: List downloaded files | |
| run: ls -R artifacts/ | |
| shell: bash | |
| - name: Prepare release assets | |
| shell: bash | |
| run: | | |
| set -e | |
| mkdir -p release_assets | |
| find artifacts -type f \( \ | |
| -name '*Setup*.exe' -o \ | |
| -name '*Portable*.exe' -o \ | |
| -name '*.msi' -o \ | |
| -name '*.AppImage' -o \ | |
| -name 'latest*.yml' -o \ | |
| -name 'mediamtx*' -o \ | |
| -name 'license-plate-runtime-*' \ | |
| \) -exec cp {} release_assets/ \; | |
| - name: List final release assets | |
| run: ls -R release_assets/ | |
| shell: bash | |
| - name: Create GitHub Release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| files: release_assets/* | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |