Skip to content

Setup CI: Tox-uv and hynek-cov #9

Setup CI: Tox-uv and hynek-cov

Setup CI: Tox-uv and hynek-cov #9

# This workflows 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: tests
on:
push:
branches:
- main
- npe2
tags:
- "v*" # Push events to matching v*, i.e. v1.0, v20.15.10
pull_request:
branches:
- main
- npe2
workflow_dispatch:
env:
FORCE_COLOR: "1"
jobs:
build-package:
name: Build & verify package
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: hynek/build-and-inspect-python-package@v2
id: baipp
ouputs:

Check failure on line 33 in .github/workflows/test_and_deploy.yml

View workflow run for this annotation

GitHub Actions / tests

Invalid workflow file

The workflow is not valid. .github/workflows/test_and_deploy.yml (Line: 33, Col: 5): Unexpected value 'ouputs'
# Used to define the matrix for tests below. The value is based on
# packaging metadata (trove classifiers).
python-versions: ${{ steps.baipp.outputs.supported_python_classifiers_json_array }}
test:
name: ${{ matrix.platform }} py${{ matrix.python-version }}
runs-on: ${{ matrix.platform }}
timeout-minutes: 30
strategy:
matrix:
platform: [ubuntu-latest, windows-latest, macos-latest]
python-version: ${{ fromJson(needs.build-package.outputs.python-versions) }}
env:
PYTHON: ${{ matrix.python-version }}
steps:
- name: Download pre-built packages
uses: actions/download-artifact@v4
with:
name: Packages
path: dist
- run: |
tar xf dist/*.tar.gz --strip-components=1
rm -rf src
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
allow-prereleases: true
- uses: hynek/setup-cached-uv@v2
# these libraries enable testing on Qt on linux
- uses: tlambert03/setup-qt-libs@v1
# strategy borrowed from vispy for installing opengl libs on windows
- name: Install Windows OpenGL
if: runner.os == 'Windows'
run: |
git clone --depth 1 https://github.com/pyvista/gl-ci-helpers.git
powershell gl-ci-helpers/appveyor/install_opengl.ps1
# note: if you need dependencies from conda, considering using
# setup-miniconda: https://github.com/conda-incubator/setup-miniconda
# and
# tox-conda: https://github.com/tox-dev/tox-conda
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install setuptools tox tox-gh-actions
# this runs the platform-specific tests declared in tox.ini
- name: Test with tox
uses: aganders3/headless-gui@v2
with:
run: >
uvx --with tox-uv tox run
--installpkg dist/*.whl
-f py${PYTHON//./}-tests
# - name: Coverage
# uses: codecov/codecov-action@v3
- name: Upload coverage data
uses: actions/upload-artifact@v4
with:
name: coverage-data-${{ matrix.python-version }}
path: .coverage.*
include-hidden-files: true
if-no-files-found: ignore
coverage:
name: Ensure 90% test coverage
runs-on: ubuntu-latest
needs: test
if: always()
steps:
- uses: actions/checkout@v4
with:
persist-credentials: true
- uses: actions/setup-python@v5
with:
python-version-file: .python-version
- uses: hynek/setup-cached-uv@v2
- name: Download coverage data
uses: actions/download-artifact@v4
with:
pattern: coverage-data-*
merge-multiple: true
- name: Combine coverage and fail if it's below 90%
run: |
uv tool install 'coverage[toml]'
coverage combine
coverage html --skip-covered --skip-empty
# Report and write to summary
coverage report --format=markdown >> $GITHUB_STEP_SUMMARY
# Report again and fail if under 90%
coverage report --fail-under=90
- name: Upload HTML report
uses: actions/upload-artifact@v4
with:
name: html-report
path: htmlcov
deploy:
# this will run when you have tagged a commit, starting with "v*"
# and requires that you have put your twine API key in your
# github secrets (see readme for details)
needs: [test]
runs-on: ubuntu-latest
if: contains(github.ref, 'tags')
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.x"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -U setuptools setuptools_scm wheel twine build
- name: Build and publish
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.TWINE_API_KEY }}
run: |
git tag
python -m build .
twine upload dist/*