If you want to convert a Python script into executable binaries for Linux, Windows, and macOS, and automate this process with GitHub Actions, this guide will walk you through the full setup.

Step 1: Add PyInstaller to Your Requirements

Make sure your requirements.txt includes PyInstaller:

pyinstaller

Also, include any other dependencies your Python app requires.

⚙️ Step 2: Create a GitHub Actions Workflow

Create the file .github/workflows/main.yml in your repo:

name: Build and Release Executables

on:
  workflow_dispatch:
    inputs:
      version:
        description: "Enter the version (e.g., v1.0.0)"
        required: true

jobs:
  build:
    strategy:
      matrix:
        os: [ubuntu-latest, windows-latest, macos-latest]

    runs-on: ${{ matrix.os }}

    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Set up Python
        uses: actions/setup-python@v4
        with:
          python-version: "3.x"

      - name: Install dependencies
        run: pip install -r requirements.txt

      - name: Build executable
        run: pyinstaller --onefile app.py

      - name: Rename executable
        run: |
          if [[ "$RUNNER_OS" == "Windows" ]]; then
            mv dist/app.exe dist/app-windows.exe
          elif [[ "$RUNNER_OS" == "Linux" ]]; then
            mv dist/app dist/app-linux
          elif [[ "$RUNNER_OS" == "macOS" ]]; then
            mv dist/app dist/app-macos
          fi
        shell: bash

      - name: Upload artifact
        uses: actions/upload-artifact@v4
        with:
          name: app-${{ matrix.os }}
          path: dist/*

  release:
    needs: build
    runs-on: ubuntu-latest

    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Download all build artifacts
        uses: actions/download-artifact@v4
        with:
          merge-multiple: true

      - name: List downloaded files (Debugging)
        run: ls -R

      - name: Make files executable (Linux/Mac)
        run: chmod +x app-* || true

      - name: Create GitHub Release
        uses: softprops/action-gh-release@v2
        with:
          tag_name: ${{ github.event.inputs.version }}
          name: Release ${{ github.event.inputs.version }}
          draft: false
          prerelease: false
          files: |
            app-linux
            app-windows.exe
            app-macos

Step 3: Trigger the Workflow

Go to the Actions tab in GitHub → Select the Build and Release Executables workflow → Click Run workflow → Enter your version (e.g., v1.0.0) → Click Run.

Step 4: Output

After the workflow completes:

  • Executables for all platforms are available as GitHub Actions artifacts.
  • A GitHub Release is created with downloadable binaries for each OS.