diff --git a/.github/workflows/pr_ci.yml b/.github/workflows/pull_request_checks.yml similarity index 51% rename from .github/workflows/pr_ci.yml rename to .github/workflows/pull_request_checks.yml index 78c493964..e0dfcf9a0 100644 --- a/.github/workflows/pr_ci.yml +++ b/.github/workflows/pull_request_checks.yml @@ -10,31 +10,36 @@ on: jobs: tests: runs-on: ubuntu-latest + strategy: + matrix: + py-ver: ["py39", "py310", "py311", "py312"] steps: - uses: actions/checkout@v4 - - uses: actions/setup-python@v5 - with: - python-version: "3.x" - - name: Get week number - id: week - run: echo "week=$(date '+W%V')" >> $GITHUB_OUTPUT - - uses: actions/cache@v3 + - name: Cache conda environment + id: conda-env-cache + uses: actions/cache@v3 with: - key: tests|${{ runner.os }}-${{ runner.arch}}|${{ steps.week.outputs.week }}|${{ hashFiles('requirements/locks/*') }} - path: | - .tox - ~/.cache/pip - - name: Install dependencies - run: python3 -m pip install tox tox-conda + key: conda|${{runner.os}}-${{runner.arch}}|${{ hashFiles(format('requirements/locks/{0}-lock-linux-64.txt', matrix.py-ver)) }} + path: ~/conda-env + - name: Create conda environment + if: steps.conda-env-cache.outputs.cache-hit != 'true' + run: | + # Check cache hasn't pulled a partial key match. + test ! -e "${HOME}/conda-env" + conda create --prefix="${HOME}/conda-env" --file=requirements/locks/${{ matrix.py-ver }}-lock-linux-64.txt + - name: Add conda environment to PATH + run: echo "${HOME}/conda-env/bin" >> $GITHUB_PATH - name: Run tests env: PY_COLORS: "1" - TOX_PARALLEL_NO_SPINNER: "1" - run: tox -e py39-linux-tests,py310-linux-tests,py311-linux-tests,py312-linux-tests + run: | + python3 -m pip install -e . + pytest --verbose --cov --cov-append + mv .coverage ".coverage.${{ matrix.py-ver }}" - uses: actions/upload-artifact@v4 with: - name: coverage-data - path: .coverage + name: coverage-data-${{ matrix.py-ver }} + path: .coverage.* retention-days: 1 coverage-report: @@ -45,24 +50,34 @@ jobs: contents: read pull-requests: write steps: - - uses: actions/checkout@v4 - uses: actions/setup-python@v5 with: python-version: "3.x" - - name: Install dependencies + - name: Get week number for cache + id: week + run: echo "week=$(date '+W%V')" >> $GITHUB_OUTPUT + - uses: actions/cache@v3 + with: + key: coverage-report|${{ env.pythonLocation }}|${{ steps.week.outputs.week }} + path: ~/.cache/pip + - name: Install coverage run: python3 -m pip install coverage + - uses: actions/checkout@v4 - uses: actions/download-artifact@v4 with: - name: coverage-data + pattern: coverage-data-* + merge-multiple: true - name: Generate coverage report - run: coverage html + run: | + coverage combine + coverage html - name: Add report to PR env: GH_TOKEN: ${{ github.token }} run: | # This links to a hosted version of the HTML report. tar -czf coverage-report.tar.gz htmlcov/ - report_url="$(curl --data-binary @coverage-report.tar.gz https://tmpweb.net)" + report_url="$(curl -sSf --data-binary @coverage-report.tar.gz https://tmpweb.net)" badge_options="$(coverage json --fail-under=0 -qo - | jq -r .totals.percent_covered_display)%25-blue?style=for-the-badge" echo "[![Coverage](https://img.shields.io/badge/coverage-${badge_options})](${report_url})" >> ${{ runner.temp }}/cov-report.md # Edit last comment if it exists, else create new one. @@ -73,12 +88,11 @@ jobs: pre-commit: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - name: Set up Python uses: actions/setup-python@v5 with: python-version: "3.x" - - name: Get week number + - name: Get week number for cache id: week run: echo "week=$(date '+W%V')" >> $GITHUB_OUTPUT - uses: actions/cache@v3 @@ -89,6 +103,7 @@ jobs: ~/.cache/pre-commit - name: Set up pre-commit run: python3 -m pip install pre-commit + - uses: actions/checkout@v4 - name: Run pre-commit run: pre-commit run --show-diff-on-failure --color=always --all-files @@ -97,23 +112,28 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: actions/setup-python@v5 + - name: Cache conda environment + id: conda-env-cache + uses: actions/cache@v3 with: - python-version: "3.x" - - name: Get week number - id: week - run: echo "week=$(date '+W%V')" >> $GITHUB_OUTPUT - - uses: actions/cache@v3 - with: - key: docs|${{ runner.os }}-${{ runner.arch}}|${{ steps.week.outputs.week }}|${{ hashFiles('requirements/locks/*') }} - path: | - .tox - ~/.cache/pip - - name: Install dependencies - run: python3 -m pip install tox tox-conda - - name: Build documentation - run: tox -e py312-linux-docs - - uses: actions/upload-artifact@v4 + key: conda|${{runner.os}}-${{runner.arch}}|${{hashFiles('requirements/locks/py312-lock-linux-64.txt')}} + path: ~/conda-env + - name: Create conda environment + if: steps.conda-env-cache.outputs.cache-hit != 'true' + run: | + # Check cache hasn't pulled a partial key match. + test ! -e "${HOME}/conda-env" + conda create --prefix="${HOME}/conda-env" --file=requirements/locks/py312-lock-linux-64.txt + - name: Add conda environment to PATH + run: echo "${HOME}/conda-env/bin" >> $GITHUB_PATH + - name: Build documentation with Sphinx + run: | + # Install module so it can be imported during docs generation. + python3 -m pip install . + # Generate the documentation + sphinx-build -d "docs/build/doctree" "docs/source" "docs/build/html" --color -W -bhtml + - name: Upload documentation artifact + uses: actions/upload-artifact@v4 with: name: html-docs path: docs/build/html/ diff --git a/pyproject.toml b/pyproject.toml index 196f64485..010b6510c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -32,7 +32,7 @@ requires = ["setuptools>=61.0"] build-backend = "setuptools.build_meta" [tool.pytest.ini_options] -addopts = ["--import-mode=importlib", "--verbose", "--cov", "--cov-append"] +addopts = ["--import-mode=importlib"] filterwarnings = ['ignore::DeprecationWarning:pytest'] minversion = "7" pythonpath = ["src"]