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 PyInstaller Binary | |
| on: | |
| release: | |
| types: [published] | |
| # The build target is whatever ref you pick in the "Use workflow from" | |
| # dropdown: the run both executes that ref's copy of this workflow and builds | |
| # its source. Pick a version tag (e.g. 0.5.0) to bake/upload that release, or a | |
| # branch to test-build it. | |
| workflow_dispatch: | |
| inputs: | |
| upload_to_release: | |
| description: "Upload to the release for the selected ref (only when it is a version tag)" | |
| type: boolean | |
| required: false | |
| default: false | |
| jobs: | |
| build-binaries: | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: | |
| - os: ubuntu-22.04 | |
| os-name: "linux" | |
| python-version: "3.11" | |
| arch: "x86_64" | |
| # Native arm64 runner -- PyInstaller cannot cross-compile, so the | |
| # architecture of the runner determines the architecture of the binary. | |
| - os: ubuntu-24.04-arm | |
| os-name: "linux" | |
| python-version: "3.11" | |
| arch: "arm64" | |
| # Intel runner for the x86_64 macOS build. | |
| - os: macos-15-intel | |
| os-name: "macos" | |
| python-version: "3.11" | |
| arch: "x86_64" | |
| # Apple Silicon runner for the arm64 macOS build. | |
| - os: macos-latest | |
| os-name: "macos" | |
| python-version: "3.11" | |
| arch: "arm64" | |
| - os: windows-latest | |
| os-name: "windows" | |
| python-version: "3.11" | |
| arch: "x86_64" | |
| steps: | |
| # Default checkout uses the launched ref: the release tag on release events, | |
| # or the ref chosen in "Use workflow from" on manual runs. | |
| - name: Check-out repository | |
| uses: actions/checkout@v4 | |
| - name: Resolve build parameters | |
| id: params | |
| shell: bash | |
| run: | | |
| version="${{ github.ref_name }}" | |
| if [[ "${{ github.event_name }}" == "release" ]]; then | |
| upload="true" | |
| else | |
| upload="${{ github.event.inputs.upload_to_release }}" | |
| fi | |
| is_version_tag=false | |
| if [[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then | |
| is_version_tag=true | |
| fi | |
| # Only upload to a release when the build target is an actual version tag. | |
| if [[ "$upload" == "true" && "$is_version_tag" != "true" ]]; then | |
| echo "::notice::'$version' is not a version tag; building without uploading." | |
| upload="false" | |
| fi | |
| echo "version=$version" >> "$GITHUB_OUTPUT" | |
| echo "upload=$upload" >> "$GITHUB_OUTPUT" | |
| # UPX is only installed where it is known to produce working binaries. | |
| # On macOS it can corrupt the (code-signed) executable, so it is skipped | |
| # there and PyInstaller is invoked with --noupx below. | |
| - name: Install UPX (Linux) | |
| if: runner.os == 'Linux' | |
| run: sudo apt-get update && sudo apt-get install -y upx-ucl | |
| - name: Install UPX (Windows) | |
| if: runner.os == 'Windows' | |
| run: choco install upx -y | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| cache: pip | |
| cache-dependency-path: requirements.txt | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -r requirements.txt | |
| pip install pyinstaller | |
| - name: Build executable with PyInstaller | |
| shell: bash | |
| run: | | |
| # The frozen binary has no git metadata, so bake the resolved version in. | |
| echo 'FFSUBSYNC_VERSION = "${{ steps.params.outputs.version }}"' > ffsubsync/_frozen_version.py | |
| if [[ "${{ runner.os }}" == "macOS" ]]; then | |
| pyinstaller --onefile --noupx --name ffsubsync ffsubsync/ffsubsync.py | |
| else | |
| pyinstaller --onefile --name ffsubsync ffsubsync/ffsubsync.py | |
| fi | |
| - name: Smoke test | |
| shell: bash | |
| run: | | |
| if [[ "${{ runner.os }}" == "Windows" ]]; then | |
| ./dist/ffsubsync.exe --version | |
| else | |
| ./dist/ffsubsync --version | |
| fi | |
| - name: Package binary | |
| shell: bash | |
| run: | | |
| cd dist | |
| if [[ "${{ runner.os }}" == "Windows" ]]; then | |
| 7z a "${{ matrix.os-name }}-${{ matrix.arch }}.zip" ffsubsync.exe | |
| else | |
| tar -czf "${{ matrix.os-name }}-${{ matrix.arch }}.tar.gz" ffsubsync | |
| fi | |
| - name: Upload binaries to GitHub Release | |
| # Upload on release events, or on manual runs that opted in for a version tag. | |
| # action-gh-release overwrites same-named assets, so re-runs replace prior uploads. | |
| if: steps.params.outputs.upload == 'true' | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: ${{ steps.params.outputs.version }} | |
| files: ./dist/${{ matrix.os-name }}-${{ matrix.arch }}.* |