Skip to content

Fit background scatter on the frame it corrects #213

Fit background scatter on the frame it corrects

Fit background scatter on the frame it corrects #213

name: PyReduce CI/CD
on:
push:
branches: [ master ]
tags: [ 'v*' ]
workflow_dispatch:
pull_request:
branches: [ master ]
jobs:
# Run tests on PRs, manual triggers, and tag pushes
test:
name: Test on Python ${{ matrix.python-version }}
runs-on: ubuntu-latest
if: github.event_name == 'pull_request' || github.event_name == 'workflow_dispatch' || startsWith(github.ref, 'refs/tags/v')
strategy:
fail-fast: false
matrix:
python-version: ['3.12', '3.13', '3.14']
steps:
- uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v4
with:
enable-cache: true
- name: Set up Python ${{ matrix.python-version }}
run: uv python install ${{ matrix.python-version }}
- name: Install dependencies
run: uv sync --all-extras
- name: Run pre-commit hooks
run: uv run pre-commit run --all-files
- name: Test with pytest (unit tests)
run: uv run pytest -m unit --cov=pyreduce --cov-report=xml --cov-report=term
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
if: matrix.python-version == '3.13'
with:
file: ./coverage.xml
fail_ci_if_error: false
# Guards the documented promise that PyReduce runs with no compiled extension
test_pure_python:
name: Test without the C extension (numpy backend)
runs-on: ubuntu-latest
if: github.event_name == 'pull_request' || github.event_name == 'workflow_dispatch' || startsWith(github.ref, 'refs/tags/v')
steps:
- uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v4
with:
enable-cache: true
- name: Set up Python
run: uv python install 3.13
- name: Install dependencies
run: uv sync
- name: Remove the compiled extension
run: uv run reduce-clean
- name: Verify it is really gone
run: |
uv run --no-sync python - <<'EOF'
import importlib.util, sys
if importlib.util.find_spec("pyreduce.clib._slitdec") is not None:
sys.exit("the compiled extension is still importable; this job proves nothing")
import pyreduce.extract # must import without it
EOF
- name: Run unit tests on the numpy backend
env:
PYREDUCE_EXTRACTION: numpy
run: uv run --no-sync pytest -m unit
# Build platform-specific wheels using cibuildwheel
build_wheels:
name: Build wheels on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
needs: [test, test_pure_python]
if: github.event_name == 'workflow_dispatch' || startsWith(github.ref, 'refs/tags/v')
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]
steps:
- uses: actions/checkout@v4
- name: Build wheels
uses: pypa/cibuildwheel@v3.2.0
env:
CIBW_BUILD_VERBOSITY: 1
- uses: actions/upload-artifact@v4
with:
name: wheels-${{ matrix.os }}
path: ./wheelhouse/*.whl
# Build source distribution
build_sdist:
name: Build source distribution
runs-on: ubuntu-latest
needs: [test, test_pure_python]
if: github.event_name == 'workflow_dispatch' || startsWith(github.ref, 'refs/tags/v')
steps:
- uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v4
- name: Set up Python
run: uv python install 3.13
- name: Build sdist
run: uv build --sdist
- uses: actions/upload-artifact@v4
with:
name: sdist
path: dist/*.tar.gz
# Upload to PyPI when a tag is pushed
upload_pypi:
name: Upload to PyPI
needs: [build_wheels, build_sdist]
runs-on: ubuntu-latest
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
environment:
name: pypi
url: https://pypi.org/p/pyreduce-astro
permissions:
id-token: write # Required for trusted publishing
steps:
- name: Download all wheels
uses: actions/download-artifact@v4
with:
pattern: wheels-*
merge-multiple: true
path: dist/
- name: Download sdist
uses: actions/download-artifact@v4
with:
name: sdist
path: dist/
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
# Create GitHub Release with CHANGELOG
create_release:
name: Create GitHub Release
needs: [upload_pypi]
runs-on: ubuntu-latest
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
permissions:
contents: write # Required to create releases
steps:
- uses: actions/checkout@v4
- name: Create GitHub Release
env:
GH_TOKEN: ${{ github.token }}
run: |
# Extract tag name
TAG_NAME=${GITHUB_REF#refs/tags/}
# Create release with CHANGELOG as notes
gh release create "$TAG_NAME" \
--title "Release $TAG_NAME" \
--notes-file CHANGELOG.md