Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use cached conda environment for CI #351

Merged
merged 4 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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"
jfrost-mo marked this conversation as resolved.
Show resolved Hide resolved
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:
Expand All @@ -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.
Expand All @@ -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
Expand All @@ -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

Expand All @@ -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/
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down