Skip to content

Commit

Permalink
Use caching in Github Actions Workflow.
Browse files Browse the repository at this point in the history
  • Loading branch information
plypaul committed Jan 10, 2024
1 parent bee9aaf commit cfc9929
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 15 deletions.
44 changes: 40 additions & 4 deletions .github/actions/setup-python-env/action.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,50 @@
name: Setup Python env
description: Install Python & Hatch
name: Setup Python / Hatch / Pydantic Environment
description: Install Python / Hatch / Pydantic

inputs:
python-version:
description: "Version of Python to use for testing"
required: true
pydantic-version:
description: "Version of Pydantic to use for testing"
required: true

runs:
using: "composite"

steps:
- name: Set up Python 3.9
- name: Set Linux Release Environment Variable
shell: bash
run: echo "LINUX_RELEASE=$(lsb_release -rs)" >> $GITHUB_ENV
- name: Set up Python ${{ inputs.python_version }}
uses: actions/setup-python@v4
with:
python-version: "3.9"
python-version: "${{ inputs.python-version }}"

# Cache the dependencies installed by Hatch so that we don't need to reinstall them on every run.
- uses: actions/cache@v3
with:
# Save pip cache.
# Save Hatch environments.
# Save the package cache for Hatch.
# Save pre-commit environments.
path: |
${{ env.pythonLocation }}
~/.cache/pip
~/.local/share/hatch
~/.cache/hatch
~/.cache/pre-commit
# >- means combine all lines to a single line
# The cache key can be any string. The format used here is just for readability.
key: >-
python_location: "${{ env.pythonLocation }}" AND
pyproject_hash: "${{ hashFiles('pyproject.toml') }}" AND
precommit_config_hash: "${{ hashFiles('.pre-commit-config.yaml') }}" AND
linux_release: "${{ env.LINUX_RELEASE }}"
- name: Install Hatch
shell: bash
run: pip3 install hatch
# This step is necessary so long as we're allowing Pydantic 1 and Pydantic 2 via shimming
- name: Install pydantic Version ~= ${{ inputs.pydantic-version }}
run: hatch run dev-env:pip install "pydantic~=${{ inputs.pydantic-version }}"
9 changes: 5 additions & 4 deletions .github/workflows/ci-pre-commit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/setup-python-env
# This step is necessary so long as we're allowing Pydantic 1 and Pydantic 2 via shimming
- name: Force Pydantic 1
run: hatch run dev-env:pip install "pydantic~=1.10"
- name: Setup Python 3.9 Environment
uses: ./.github/actions/setup-python-env
with:
python-version: 3.9
pydantic-version: 1.10
- name: Run Pre-commit Hooks
run: hatch run dev-env:pre-commit run --show-diff-on-failure --color=always --all-files
10 changes: 3 additions & 7 deletions .github/workflows/ci-pytest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
- name: Setup Python ${{ matrix.python-version }} / Pydantic ${{ matrix.pydantic-version }} Environment
uses: ./.github/actions/setup-python-env
with:
python-version: ${{ matrix.python-version }}
- name: Install Hatch
shell: bash
run: pip3 install hatch
- name: Set pydantic Version ~= ${{ matrix.pydantic-version }}
run: hatch run dev-env:pip install "pydantic~=${{ matrix.pydantic-version }}"
pydantic-version: ${{ matrix.pydantic-version }}
- name: Run Python Tests
run: hatch run dev-env:pytest tests

0 comments on commit cfc9929

Please sign in to comment.