Setup for optional django dependency and unit testing with/without django #417
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: unit tests | |
| permissions: | |
| contents: read | |
| id-token: write | |
| on: | |
| push: | |
| branches: | |
| - "**" | |
| paths: | |
| - 'undate/**' | |
| - 'tests/**' | |
| pull_request: | |
| branches: | |
| - "**" | |
| env: | |
| # python version used to calculate and submit code coverage | |
| COV_PYTHON_VERSION: "3.12" | |
| jobs: | |
| python-unit: | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| python: ["3.10", "3.11", "3.12", "3.13"] | |
| django: [0, "5.2"] # add more versions as we add support | |
| # exclude incompatible python+django combinations if needed | |
| # OR limit django+python to specific combinations to avoid too many builds | |
| defaults: | |
| run: | |
| working-directory: . | |
| steps: | |
| - uses: actions/checkout@v5 | |
| # use github python action instead of uv to take advantage of caching | |
| - name: Set up Python ${{ matrix.python }} | |
| uses: actions/setup-python@v6 | |
| with: | |
| python-version: ${{ matrix.python }} | |
| cache: 'pip' | |
| cache-dependency-path: '**/pyproject.toml' | |
| # test with and without django based on build matrix | |
| - name: Install package with dependencies (and optionally django) | |
| run: | | |
| if [ "${{ matrix.django }}" -gt "0"]; then pip install -q Django==${{ matrix.django }} pytest-django; fi | |
| pip install -e '.[test]' | |
| # for all versions but the one we use for code coverage, run normally | |
| - name: Run unit tests without code coverage | |
| run: pytest | |
| if: ${{ matrix.python != env.COV_PYTHON_VERSION }} | |
| # run code coverage in one version only | |
| - name: Run unit tests with code coverage reporting | |
| run: pytest --cov=. | |
| if: ${{ matrix.python == env.COV_PYTHON_VERSION }} | |
| - name: Upload coverage to Codecov | |
| uses: codecov/codecov-action@v5 | |
| env: | |
| CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} | |
| if: ${{ matrix.python == env.COV_PYTHON_VERSION }} | |