Skip to content

v0.15.0

v0.15.0 #74

Workflow file for this run

name: Publish to PyPi
on:
release:
types: [published]
workflow_dispatch:
# For testing/debugging purposes, you make changes to this workflow on a branch and then trigger the workflow manually from the Github Actions tab
# Doing will only run the publish-test-pyi job and *not* the publish-prod-pypi job, unless you comment out the publish-prod-pypi job's `if` condition
jobs:
publish-test-pypi:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install the latest version of uv
uses: astral-sh/setup-uv@v6
with:
activate-environment: true
enable-cache: true
cache-dependency-glob: |
pyproject.toml
uv.lock
- name: Get the version
id: get_version
run: |
echo "VERSION=$(uv version --short)" >> $GITHUB_OUTPUT
- name: Display version being published
run: |
echo "Publishing version: ${{ steps.get_version.outputs.VERSION }} from ${{ github.ref }} for event ${{ github.event_name }}"
- name: Install dependencies
run: uv sync --group build
- name: Build package
run: uv build .
- name: Publish to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
# TODO: There is no CZI org on test.pypi.org, and so it is not set up as a Trusted Publisher yet; we need to use a test token
password: ${{ secrets.TEST_PYPI_CZI_API_TOKEN }}
repository-url: https://test.pypi.org/legacy/
# Useful if prod pypi publish failed (below), and this workflow is re-run
skip-existing: true
- name: Confirm publish to Test PyPI
uses: nick-fields/retry@v3
with:
max_attempts: 15
timeout_seconds: 30
polling_interval_seconds: 5
command: uv run pip index versions --index-url https://test.pypi.org/simple/ cz-benchmarks | tee | grep "Available.*${{ steps.get_version.outputs.VERSION }}"
# it takes a little time for a package to show up so the first try might fail
- name: Install and Test Package from Test PyPI
# Add PyPi index to the pip install command so that any dependencies not on TestPyPI are installed from PyPI
# For example, anndata >= 0.9.0 is not on TestPyPI, so it is installed from PyPI
run: |
uv venv venv
source venv/bin/activate
# Note: We install the "latest" version (i.e. no explicit version) to ensure that the newly published version is in fact the latest version (verified below).
uv pip install --no-cache-dir -i https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple cz-benchmarks
uv run --active python -c "import czbenchmarks" # --active uses the venv
uv pip show cz-benchmarks | grep "Version: ${{ steps.get_version.outputs.VERSION }}"
publish-prod-pypi:
# This job will only run if the test-pypi job is successful
needs: publish-test-pypi
# Only run if done for an official release, not via a triggered workflow, which is used for testing
if: github.event_name == 'release' && startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/cz-benchmarks
permissions:
id-token: write # to authenticate as Trusted Publisher to pypi.org
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Get the version
id: get_version
run: |
echo "VERSION=$(uv version --short)" >> $GITHUB_OUTPUT
- name: Display version being published
run: |
echo "Publishing version: ${{ steps.get_version.outputs.VERSION }} from ${{ github.ref }} for event ${{ github.event_name }}"
- name: Install the latest version of uv
uses: astral-sh/setup-uv@v6
with:
activate-environment: true
enable-cache: true
cache-dependency-glob: |
pyproject.toml
uv.lock
- name: Install dependencies
run: uv sync --group build
- name: Build package
run: uv build .
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
# with:
# # Useful if prod pypi publish succeeded, but you need to debug later steps in this job
# skip-existing: true
- name: Confirm publish to PyPI
uses: nick-fields/retry@v3
with:
max_attempts: 15
timeout_seconds: 30
polling_interval_seconds: 5
command: uv run pip index versions --index-url https://pypi.org/simple/ cz-benchmarks | grep "Available.*${{ steps.get_version.outputs.VERSION }}"
# it takes a little time for a package to show up so the first try might fail
- name: Install and Test Package from PyPI
run: |
uv venv venv
source venv/bin/activate
# Note: We install the "latest" version (i.e. no explicit version) to ensure that the newly published version is in fact the latest version (verified below).
uv pip install --no-cache-dir cz-benchmarks
uv run --active python -c "import czbenchmarks" # --active uses the venv
uv pip show cz-benchmarks | grep "Version: ${{ steps.get_version.outputs.VERSION }}"