Skip to content

cache environment with python version #2

cache environment with python version

cache environment with python version #2

Workflow file for this run

name: Linting, (type-)checking, testing
on:
pull_request:
push:
branches:
- main
paths:
- ".github/workflows/test.yml"
- "TODO_package_name/**"
- "tests/**"
jobs:
get-python-versions:
runs-on: ubuntu-latest
outputs:
python-matrix: ${{ steps.get-python-versions-action.outputs.latest-python-versions }}
steps:
- uses: snok/latest-python-versions@v1
id: get-python-versions-action
with:
min-version: "3.11"
include-prereleases: false
setup-env:
needs: get-python-versions
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ${{ fromJson(needs.get-python-versions.outputs.python-matrix) }}
fail-fast: false
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install Conda environment with Micromamba
uses: mamba-org/setup-micromamba@v1
with:
environment-file: "environment-cpu.yml"
init-shell: >-
bash
zsh
cache-environment: true
cache-environment-key: ${{ runner.os }}-micromamba-${{ matrix.python-version }}-${{ hashFiles('environment-cpu.yml') }}
cache-downloads: false
post-cleanup: "all"
pre-commit:
needs: setup-env
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Restore Micromamba environment from cache
uses: mamba-org/setup-micromamba@v1
with:
environment-file: environment-cpu.yml
cache-environment-key: ${{ runner.os }}-micromamba-${{ matrix.python-version }}-${{ hashFiles('environment-cpu.yml') }}
- name: Check with pre-commit
uses: pre-commit/action@v3.0.0
pytest:
needs: setup-env
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Restore Micromamba environment from cache
uses: mamba-org/setup-micromamba@v1
with:
environment-file: environment-cpu.yml
cache-environment-key: ${{ runner.os }}-micromamba-${{ matrix.python-version }}-${{ hashFiles('environment-cpu.yml') }}
- name: Test with PyTest
shell: bash -l {0}
run: |
micromamba activate TODO_package_name
python -m pip install pytest pytest-cov
pytest --cov=TODO_package_name/ tests/ || [ $? -eq 5 ]