From 39b0d76e640ea91d571462877ecb0a2109e529e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Lidwin?= Date: Thu, 9 Jul 2026 16:49:25 +0200 Subject: [PATCH] ci: automate pypi and releases drafting (#761) --- .github/workflows/build-base.yml | 97 ++++++++++++++++++++++++++++++++ .github/workflows/python.yml | 93 +----------------------------- .github/workflows/release.yml | 72 ++++++++++++++++++++++++ 3 files changed, 171 insertions(+), 91 deletions(-) create mode 100644 .github/workflows/build-base.yml create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/build-base.yml b/.github/workflows/build-base.yml new file mode 100644 index 0000000..be3789c --- /dev/null +++ b/.github/workflows/build-base.yml @@ -0,0 +1,97 @@ +name: Build Base + +on: + workflow_call: + +jobs: + pyinstaller: + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ + 'windows-2025', 'windows-11-arm', + 'macos-15-intel', 'macos-15' + ] + fail-fast: false + env: + UV_SYSTEM_PYTHON: 1 + + steps: + - uses: actions/checkout@v6 + + - uses: actions/setup-python@v6 + with: + python-version-file: "pyproject.toml" + + - name: Install uv + uses: astral-sh/setup-uv@v7 + with: + enable-cache: true + + - name: Dependencies and build tools + run: uv sync --extra pyinstaller_build --no-install-local + + - name: Optional dependencies (WebView) + run: uv sync --extra webview --no-install-local --inexact + if: runner.os != 'macOS' + + - name: Set strip option on non-Windows + id: strip + run: echo "option=--strip" >> $GITHUB_OUTPUT + if: runner.os != 'Windows' + + - name: Build + working-directory: legendary + run: uv run --module PyInstaller + --onefile + --name legendary + ${{ steps.strip.outputs.option }} + -i ../assets/windows_icon.ico + cli.py + env: + PYTHONOPTIMIZE: 1 + + - uses: actions/upload-artifact@v7 + with: + name: ${{ runner.os }}-${{ runner.arch }}-package + path: legendary/dist/* + + zipapp: + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ + 'ubuntu-24.04', 'ubuntu-24.04-arm' + ] + fail-fast: false + + steps: + - uses: actions/checkout@v6 + + - uses: actions/setup-python@v6 + with: + python-version-file: "pyproject.toml" + + - name: Install uv + uses: astral-sh/setup-uv@v7 + with: + enable-cache: true + + - run: mkdir -p build dist + + - name: Dependencies + run: uv export --format requirements.txt --no-editable | uv pip install --requirement - --target build + + - run: cp zipapp_main.py build/__main__.py + + - name: Build + run: python -m zipapp + --output dist/legendary + --python "/usr/bin/env python3" + --compress + build + + - uses: actions/upload-artifact@v7 + with: + name: ${{ runner.os }}-${{ runner.arch }}-package + path: dist/legendary diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 4d6330b..89a6499 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -7,94 +7,5 @@ on: branches: [ '*' ] jobs: - pyinstaller: - runs-on: ${{ matrix.os }} - strategy: - matrix: - os: [ - 'windows-2025', 'windows-11-arm', - 'macos-15-intel', 'macos-15' - ] - fail-fast: false - env: - UV_SYSTEM_PYTHON: 1 - - steps: - - uses: actions/checkout@v6 - - - uses: actions/setup-python@v6 - with: - python-version-file: "pyproject.toml" - - - name: Install uv - uses: astral-sh/setup-uv@v7 - with: - enable-cache: true - - - name: Dependencies and build tools - run: uv sync --extra pyinstaller_build --no-install-local - - - name: Optional dependencies (WebView) - run: uv sync --extra webview --no-install-local --inexact - if: runner.os != 'macOS' - - - name: Set strip option on non-Windows - id: strip - run: echo "option=--strip" >> $GITHUB_OUTPUT - if: runner.os != 'Windows' - - - name: Build - working-directory: legendary - run: uv run --module PyInstaller - --onefile - --name legendary - ${{ steps.strip.outputs.option }} - -i ../assets/windows_icon.ico - cli.py - env: - PYTHONOPTIMIZE: 1 - - - uses: actions/upload-artifact@v7 - with: - name: ${{ runner.os }}-${{ runner.arch }}-package - path: legendary/dist/* - - zipapp: - runs-on: ${{ matrix.os }} - strategy: - matrix: - os: [ - 'ubuntu-24.04', 'ubuntu-24.04-arm' - ] - fail-fast: false - - steps: - - uses: actions/checkout@v6 - - - uses: actions/setup-python@v6 - with: - python-version-file: "pyproject.toml" - - - name: Install uv - uses: astral-sh/setup-uv@v7 - with: - enable-cache: true - - - run: mkdir -p build dist - - - name: Dependencies - run: uv export --format requirements.txt --no-editable | uv pip install --requirement - --target build - - - run: cp zipapp_main.py build/__main__.py - - - name: Build - run: python -m zipapp - --output dist/legendary - --python "/usr/bin/env python3" - --compress - build - - - uses: actions/upload-artifact@v7 - with: - name: ${{ runner.os }}-${{ runner.arch }}-package - path: dist/legendary + build: + uses: ./.github/workflows/build-base.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..4d53bcc --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,72 @@ +name: Release + +on: + push: + tags: [ '*.*.*' ] + +jobs: + build: + uses: ./.github/workflows/build-base.yml + + pypi: + runs-on: ubuntu-latest + environment: pypi + env: + UV_SYSTEM_PYTHON: 1 + steps: + - uses: actions/checkout@v6 + - uses: actions/setup-python@v6 + with: + python-version-file: "pyproject.toml" + + - name: Install uv + uses: astral-sh/setup-uv@v7 + with: + enable-cache: true + + - name: Build + run: uv build + + - name: Publish + run: uv publish + + release: + permissions: + contents: write + runs-on: ubuntu-slim + needs: [build, pypi] + steps: + - name: Download builds + uses: actions/download-artifact@v8 + + - name: Setup distribution dir + run: mkdir dist + + - name: Copy binaries + run: | + oses=("Linux" "macOS" "Windows") + arches=("X64" "ARM64") + for os in ${oses[@]}; do + for arch in ${arches[@]}; do + file="./$os-$arch-package/legendary"* + if [ -f $file ]; then + filename=$(basename $file) + ext=${filename#*.} + if [[ "$ext" == "$filename" ]]; then + ext="" + else + ext=".$ext" + fi + cp $file "./dist/legendary_${os,}_${arch,,}$ext" + fi + done + done + + - name: Package macOS zip + working-directory: dist + run: 7z a legendary_macOS.zip legendary_macOS_* + + - name: Create draft release + env: + GH_TOKEN: ${{ github.token }} + run: gh release create "${{ github.ref_name }}" --repo "${{ github.server_url }}/${{ github.repository }}" --draft --generate-notes --verify-tag ./dist/legendary*