Skip to content
Latchkey

Upload Python Package workflow (cdgriffith/Box)

The Upload Python Package workflow from cdgriffith/Box, explained and optimized by Latchkey.

C

CI health: C - fair

Point runs-on at Latchkey and get caching, job timeouts, self-healing for flaky steps, and up to 58% lower cost, applied automatically.

Grade your own workflow free or run it on Latchkey →
Source: cdgriffith/Box.github/workflows/pythonpublish.ymlLicense MITView source

What it does

This is the Upload Python Package workflow from the cdgriffith/Box repository, a real project running GitHub Actions. It is shown here with attribution under its MIT license.

Below, Latchkey shows a faster, safer version produced by its optimization engine.

The workflow

workflow (.yml)
# This workflow will upload a Python Package using Twine when a release is created
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries

name: Upload Python Package

on:
  release:
    types: [ created ]

jobs:
  deploy-generic:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v4

    - name: Set up Python
      uses: actions/setup-python@v5
      with:
        python-version: '3.14'

    - name: Install Dependencies
      run: |
        python -m pip install --upgrade pip
        pip install setuptools wheel twine --upgrade


    - name: Build and Publish
      env:
        TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
        TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}

      run: |
        python setup.py sdist bdist_wheel
        twine upload dist/*

  deploy-cython:
    strategy:
      matrix:
        os: [macos-latest, windows-latest]
        python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"]
    runs-on: ${{ matrix.os }}

    steps:
    - uses: actions/checkout@v4
    - name: Set up Python ${{ matrix.python-version }}
      uses: actions/setup-python@v5
      with:
        python-version: ${{ matrix.python-version }}
    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip
        pip install setuptools wheel twine Cython>=3.0.11 --upgrade
    - name: Build and publish
      env:
        TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
        TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
      run: |
        python setup.py bdist_wheel
        twine upload dist/*

  deploy-cython-manylinux:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4
    - name: Set up Python 3.13
      uses: actions/setup-python@v5
      with:
        python-version: "3.13"

    - name: Build wheels
      run: |
        python -m pip install --upgrade pip
        pip install cibuildwheel setuptools wheel
        python -m cibuildwheel --output-dir dist
      env:
        CIBW_BUILD: cp310-manylinux_x86_64 cp311-manylinux_x86_64 cp312-manylinux_x86_64 cp313-manylinux_x86_64
        CIBW_BEFORE_BUILD: pip install Cython>=3.0.11 setuptools wheel
        CIBW_BUILD_FRONTEND: "build; args: --no-isolation"
        CIBW_BEFORE_TEST: pip install -r requirements.txt -r requirements-test.txt setuptools wheel twine Cython>=3.0.11
        CIBW_BUILD_VERBOSITY: 1
        CIBW_TEST_COMMAND: pytest {package}/test -vv

    - name: Publish
      env:
        TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
        TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
      run: |
        pip install twine
        twine upload dist/*-manylinux*.whl

The same workflow, on Latchkey

Estimated ~20% faster on cache hits, plus fewer wasted runs and a safer supply chain. Added and changed lines are highlighted.

# This workflow will upload a Python Package using Twine when a release is created
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries
 
name: Upload Python Package
 
on:
  release:
    types: [ created ]
 
jobs:
  deploy-generic:
    timeout-minutes: 30
 
    runs-on: latchkey-small
 
    steps:
    - uses: actions/checkout@v4
 
    - name: Set up Python
      uses: actions/setup-python@v5
      with:
        cache: 'pip'
        python-version: '3.14'
 
    - name: Install Dependencies
      run: |
        python -m pip install --upgrade pip
        pip install setuptools wheel twine --upgrade
 
 
    - name: Build and Publish
      env:
        TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
        TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
 
      run: |
        python setup.py sdist bdist_wheel
        twine upload dist/*
 
  deploy-cython:
    timeout-minutes: 30
    strategy:
      matrix:
        os: [macos-latest, windows-latest]
        python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"]
    runs-on: ${{ matrix.os }}
 
    steps:
    - uses: actions/checkout@v4
    - name: Set up Python ${{ matrix.python-version }}
      uses: actions/setup-python@v5
      with:
        cache: 'pip'
        python-version: ${{ matrix.python-version }}
    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip
        pip install setuptools wheel twine Cython>=3.0.11 --upgrade
    - name: Build and publish
      env:
        TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
        TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
      run: |
        python setup.py bdist_wheel
        twine upload dist/*
 
  deploy-cython-manylinux:
    timeout-minutes: 30
    runs-on: latchkey-small
    steps:
    - uses: actions/checkout@v4
    - name: Set up Python 3.13
      uses: actions/setup-python@v5
      with:
        cache: 'pip'
        python-version: "3.13"
 
    - name: Build wheels
      run: |
        python -m pip install --upgrade pip
        pip install cibuildwheel setuptools wheel
        python -m cibuildwheel --output-dir dist
      env:
        CIBW_BUILD: cp310-manylinux_x86_64 cp311-manylinux_x86_64 cp312-manylinux_x86_64 cp313-manylinux_x86_64
        CIBW_BEFORE_BUILD: pip install Cython>=3.0.11 setuptools wheel
        CIBW_BUILD_FRONTEND: "build; args: --no-isolation"
        CIBW_BEFORE_TEST: pip install -r requirements.txt -r requirements-test.txt setuptools wheel twine Cython>=3.0.11
        CIBW_BUILD_VERBOSITY: 1
        CIBW_TEST_COMMAND: pytest {package}/test -vv
 
    - name: Publish
      env:
        TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
        TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
      run: |
        pip install twine
        twine upload dist/*-manylinux*.whl
 

What changed

What Latchkey heals here

This workflow has steps that commonly fail on transient issues (network, registries, flaky browsers). On Latchkey managed runners they are detected, retried, and self-healed instead of failing your build:

This workflow runs 3 jobs (12 with the matrix expanded) per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.

Actions used in this workflow