Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 68 additions & 40 deletions .github/workflows/pythonpublish.yml
Original file line number Diff line number Diff line change
@@ -1,50 +1,68 @@
# 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
# Builds and publishes to PyPI when a GitHub release is created.
# Every build job runs without secrets. A single publish job, whose only permission is
# id-token: write, uploads all distributions via PyPI Trusted Publishing (OIDC), so no PyPI
# password or token is stored in GitHub: https://docs.pypi.org/trusted-publishers/
# All actions are pinned to full commit SHAs; the comment shows the matching release tag.

name: Upload Python Package

on:
release:
types: [ created ]

jobs:
deploy-generic:
permissions: {}

jobs:
build-generic:
runs-on: ubuntu-latest
timeout-minutes: 20
permissions:
contents: read

steps:
- uses: actions/checkout@v7
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false

- name: Set up Python
uses: actions/setup-python@v7
uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
with:
python-version: '3.15'

- name: Install uv
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3

# Isolated build: Cython is not part of the build requirements, so this is the pure Python sdist and wheel
- name: Build and Publish
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}

- name: Build and check
run: |
uv build
uvx twine==6.2.0 upload dist/*
uvx twine==6.2.0 check dist/*

deploy-cython:
- name: Upload distribution artifact
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: dist-generic
path: dist/*
if-no-files-found: error

build-cython:
strategy:
fail-fast: false
matrix:
os: [macos-latest, windows-latest]
python-version: ["3.11", "3.12", "3.13", "3.14", "3.15"]
runs-on: ${{ matrix.os }}
timeout-minutes: 30
permissions:
contents: read

steps:
- uses: actions/checkout@v7
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Set up Python ${{ matrix.python-version }}
id: setup-python
uses: actions/setup-python@v7
uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
with:
python-version: ${{ matrix.python-version }}
- name: Install uv
Expand All @@ -53,21 +71,28 @@ jobs:
run: |
uv venv --python "${{ steps.setup-python.outputs.python-path }}"
uv pip install "setuptools>=77" wheel "Cython>=3.3.0"
- name: Build and publish
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
# No build isolation so the Cython installed above is used to build the compiled wheel
# No build isolation so the Cython installed above is used to build the compiled wheel
- name: Build and check
run: |
uv build --wheel --no-build-isolation
uvx twine==6.2.0 upload dist/*
uvx twine==6.2.0 check dist/*
- name: Upload wheel artifact
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: dist-cython-${{ matrix.os }}-${{ matrix.python-version }}
path: dist/*.whl
if-no-files-found: error

# Building runs the test suite (third party test dependencies), so it happens in a job without
# access to the PyPI credentials. A separate job only downloads the built wheels and uploads them.
build-cython-manylinux:
runs-on: ubuntu-latest
timeout-minutes: 60
permissions:
contents: read

steps:
- uses: actions/checkout@v7
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Install uv
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3

Expand All @@ -76,27 +101,30 @@ jobs:
run: uvx cibuildwheel==4.3.5 --output-dir dist

- name: Upload wheel artifact
uses: actions/upload-artifact@v7
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: python_box_manylinux
name: dist-cython-manylinux
path: dist/*-manylinux*.whl
if-no-files-found: error

deploy-cython-manylinux:
needs: build-cython-manylinux
# Publishes only after every build succeeds, so a release is never left half uploaded
publish:
needs: [ build-generic, build-cython, build-cython-manylinux ]
runs-on: ubuntu-latest
timeout-minutes: 15
environment:
name: pypi
url: https://pypi.org/p/python-box
permissions:
id-token: write # Required for Trusted Publishing; the only permission this job has

steps:
- name: Download wheels
uses: actions/download-artifact@v7
- name: Download all distributions
uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
with:
name: python_box_manylinux
pattern: dist-*
path: dist
merge-multiple: true

- name: Install uv
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3

- name: Publish
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
uvx twine==6.2.0 upload dist/*-manylinux*.whl
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@7245906fb61fa33a13554f9d5fb856fe61758086 # v1.14.3
16 changes: 8 additions & 8 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Install uv
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
with:
Expand All @@ -30,10 +30,10 @@ jobs:
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v7
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Set up Python ${{ matrix.python-version }}
id: setup-python
uses: actions/setup-python@v7
uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
with:
python-version: ${{ matrix.python-version }}
- name: Install uv
Expand Down Expand Up @@ -64,15 +64,15 @@ jobs:
Remove-item box -recurse -force
uv run --no-sync pytest -vv
- name: Upload wheel artifact
uses: actions/upload-artifact@v7
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: python_box_${{matrix.os}}_${{ matrix.python-version }}
path: dist/*.whl

package-manylinux-checks:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Install uv
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
with:
Expand All @@ -82,7 +82,7 @@ jobs:
run: uvx cibuildwheel==4.3.5 --output-dir dist

- name: Upload wheel artifact
uses: actions/upload-artifact@v7
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: python_box_manylinux
path: dist/*-manylinux*.whl
Expand All @@ -94,10 +94,10 @@ jobs:
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v7
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Set up Python ${{ matrix.python-version }}
id: setup-python
uses: actions/setup-python@v7
uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
with:
python-version: ${{ matrix.python-version }}
- name: Install uv
Expand Down
Loading