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 EXE | |
| on: | |
| push: | |
| branches: [ main, master ] | |
| paths: | |
| - '**.py' | |
| - 'requirements.txt' | |
| - '.github/workflows/build.yml' | |
| pull_request: | |
| branches: [ main, master ] | |
| workflow_dispatch: | |
| release: | |
| types: [published] | |
| permissions: | |
| contents: write | |
| jobs: | |
| build-windows-exe: | |
| runs-on: windows-latest | |
| defaults: | |
| run: | |
| shell: pwsh | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.10' | |
| - name: Upgrade pip | |
| run: python -m pip install --upgrade pip | |
| - name: Install dependencies | |
| run: | | |
| if (Test-Path requirements.txt) { | |
| pip install -r requirements.txt | |
| } | |
| pip install pyinstaller pytest | |
| - name: Show Python environment | |
| run: | | |
| python --version | |
| pip --version | |
| pip freeze | |
| - name: Run unit tests | |
| run: | | |
| pytest -q | |
| - name: Build executable with PyInstaller | |
| run: | | |
| $ErrorActionPreference = 'Stop' | |
| # Ensure output directories are clean | |
| if (Test-Path dist) { Remove-Item -Recurse -Force dist } | |
| if (Test-Path build) { Remove-Item -Recurse -Force build } | |
| # Include settings.json (if exists) into the same dir as the executable | |
| $addDataArgs = @() | |
| if (Test-Path settings.json) { $addDataArgs += @('--add-data','settings.json;.') } | |
| pyinstaller --noconfirm --onefile --windowed --name syncer @addDataArgs main.py | |
| - name: Archive build outputs | |
| if: always() | |
| run: | | |
| Get-ChildItem -Recurse dist | ForEach-Object { Write-Host $_.FullName } | |
| - name: Upload EXE artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: syncer-windows-exe | |
| path: dist/syncer.exe | |
| if-no-files-found: error | |
| - name: Publish/Update 'latest' pre-release with asset (on main/master) | |
| if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master' | |
| uses: svenstaro/upload-release-action@v2 | |
| with: | |
| repo_token: ${{ secrets.GITHUB_TOKEN }} | |
| file: dist/syncer.exe | |
| asset_name: syncer.exe | |
| tag: latest | |
| overwrite: true | |
| prerelease: true | |
| body: "Automated build from ${{ github.sha }} on ${{ github.ref }}" | |
| - name: Upload full dist folder (debug) | |
| if: failure() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: dist-folder-debug | |
| path: dist/** |