| 1 |
# This name appears as the text in the build badge: https://github.com/jab/bidict/actions/workflows/test.yml/badge.svg |
| 2 |
name: tests |
| 3 |
|
| 4 |
"on": |
| 5 |
workflow_dispatch: |
| 6 |
inputs: |
| 7 |
hypothesis_profile: |
| 8 |
type: choice |
| 9 |
description: (optional) |
| 10 |
options: |
| 11 |
- less-examples |
| 12 |
- more-examples |
| 13 |
schedule: |
| 14 |
- cron: "15 16 * * *" |
| 15 |
push: |
| 16 |
branches: |
| 17 |
- main |
| 18 |
- dev |
| 19 |
- deps |
| 20 |
pull_request: |
| 21 |
branches: |
| 22 |
- main |
| 23 |
|
| 24 |
env: |
| 25 |
FORCE_COLOR: "1" |
| 26 |
|
| 27 |
jobs: |
| 28 |
test-all: |
| 29 |
name: ${{ matrix.python }} |
| 30 |
runs-on: ubuntu-24.04 |
| 31 |
continue-on-error: ${{ matrix.allow_failure || false }} |
| 32 |
strategy: |
| 33 |
fail-fast: false |
| 34 |
matrix: |
| 35 |
include: |
| 36 |
- python: "3.15" |
| 37 |
shell: test315 |
| 38 |
# TODO: Drop allow_failure once 3.15 is stable: |
| 39 |
allow_failure: true |
| 40 |
- python: "3.14" |
| 41 |
shell: test314 |
| 42 |
enable_coverage: true |
| 43 |
- python: "3.13" |
| 44 |
shell: test313 |
| 45 |
- python: "3.12" |
| 46 |
shell: test312 |
| 47 |
- python: "3.11" |
| 48 |
shell: test311 |
| 49 |
# bidict/_typing.py's `typing`/`typing_extensions` imports branch on python<3.12 |
| 50 |
enable_coverage: true |
| 51 |
- python: "pypy-3.11" |
| 52 |
shell: testPyPy311 |
| 53 |
steps: |
| 54 |
- name: check out source |
| 55 |
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 |
| 56 |
- name: install Nix |
| 57 |
uses: DeterminateSystems/nix-installer-action@ef8a148080ab6020fd15196c2084a2eea5ff2d25 |
| 58 |
- name: cache the Nix store |
| 59 |
uses: DeterminateSystems/magic-nix-cache-action@908b263ff629f4cc17666315b7fd3ec127c6244d |
| 60 |
with: |
| 61 |
# Use only the GitHub Actions cache; we don't authenticate to FlakeHub, and leaving it |
| 62 |
# enabled makes the action log a noisy (non-fatal) "Cannot find netrc credentials for |
| 63 |
# https://api.flakehub.com/" error before falling back to the GHA cache. |
| 64 |
use-flakehub: false |
| 65 |
use-gha-cache: true |
| 66 |
- name: set hypothesis profile |
| 67 |
# Both choices are profiles bidict registers in tests/conftest.py, so no run lands on |
| 68 |
# hypothesis's built-in `default`, whose wall-clock deadline fails tests for being slow |
| 69 |
# on their first call. Using less-examples here also stops CI, which gates merges, from |
| 70 |
# generating fewer examples than a plain local `pytest` does. |
| 71 |
run: | |
| 72 |
hypothesis_profile=${{ github.event.inputs.hypothesis_profile || (github.event_name == 'schedule' && 'more-examples' || 'less-examples') }} |
| 73 |
echo PYTEST_ADDOPTS="$PYTEST_ADDOPTS --hypothesis-profile=$hypothesis_profile" >> "$GITHUB_ENV" |
| 74 |
- name: cache .hypothesis dir |
| 75 |
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 |
| 76 |
with: |
| 77 |
path: .hypothesis |
| 78 |
key: hypothesis|${{ runner.os }}|${{ matrix.python }} |
| 79 |
- name: maybe enable coverage |
| 80 |
if: matrix.enable_coverage |
| 81 |
run: | |
| 82 |
echo RUN_PYTEST_CMD="coverage run -m pytest" >> "$GITHUB_ENV" |
| 83 |
- name: run ty and pytest |
| 84 |
run: | |
| 85 |
nix develop .#${{ matrix.shell }} --command bash -c " |
| 86 |
set -euo pipefail |
| 87 |
ty check |
| 88 |
\${RUN_PYTEST_CMD:-pytest} |
| 89 |
" |
| 90 |
- name: combine and show any collected coverage |
| 91 |
if: matrix.enable_coverage |
| 92 |
run: | |
| 93 |
nix develop .#${{ matrix.shell }} --command bash -c ' |
| 94 |
coverage combine |
| 95 |
coverage debug data |
| 96 |
coverage report |
| 97 |
' |
| 98 |
- name: maybe upload to Codecov # https://github.com/codecov/codecov-action |
| 99 |
if: matrix.enable_coverage |
| 100 |
uses: codecov/codecov-action@fb8b3582c8e4def4969c97caa2f19720cb33a72f |
| 101 |
env: |
| 102 |
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} |
| 103 |
with: |
| 104 |
verbose: true |
| 105 |
fail_ci_if_error: false # https://github.com/codecov/codecov-action/issues/557 |
| 106 |
|
| 107 |
|
| 108 |
permissions: |
| 109 |
contents: read |