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 Caching in Github Actions Workflow #66

Merged
merged 1 commit into from
Feb 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
29 changes: 28 additions & 1 deletion .github/actions/setup-python-env/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,42 @@ inputs:
python-version:
description: Python version number to install
required: true
additional-cache-key:
description: |
An additional cache key that can be specified to differentiate workflows that install a different set of packages.
required: false
default: "default"

runs:
using: "composite"
steps:
- 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: ${{ inputs.python-version }}

- 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 }}"
AND additional_cache_key: "${{ inputs.additional-cache-key }}"
- name: Install Hatch
shell: bash
run: pip3 install hatch
1 change: 1 addition & 0 deletions .github/workflows/ci-pre-commit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ jobs:
uses: ./.github/actions/setup-python-env
with:
python-version: ${{ matrix.python-version }}
additional-cache-key: "pydantic~=1.10"
# 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
1 change: 1 addition & 0 deletions .github/workflows/ci-pytest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ jobs:
uses: ./.github/actions/setup-python-env
with:
python-version: ${{ matrix.python-version }}
additional-cache-key: "pydantic~=${{ matrix.pydantic-version }}"
- name: Set pydantic Version ~= ${{ matrix.pydantic-version }}
run: hatch run dev-env:pip install "pydantic~=${{ matrix.pydantic-version }}"
- name: Run Python Tests
Expand Down
Loading