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 9c7bcb3
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 9 deletions.
37 changes: 34 additions & 3 deletions .github/actions/setup-python-env/action.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,44 @@
name: Setup Python env
name: Setup Python Environment
description: Install Python & Hatch

inputs:
python-version:
description: "Version of Python to use for testing"
required: false
default: "3.9"

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
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/ci-pre-commit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/setup-python-env
- name: Setup Python 3.9 Environment
uses: ./.github/actions/setup-python-env
with:
python-version: 3.9
# 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"
Expand Down
7 changes: 2 additions & 5 deletions .github/workflows/ci-pytest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +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 }} 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 }}"
- name: Run Python Tests
Expand Down

0 comments on commit 9c7bcb3

Please sign in to comment.