Skip to content

Commit

Permalink
Merge pull request #66 from dbt-labs/plypaul--04--cache-python
Browse files Browse the repository at this point in the history
Use Caching in Github Actions Workflow
  • Loading branch information
plypaul authored Feb 15, 2024
2 parents a7d0006 + f79c8c0 commit 758adc2
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
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

0 comments on commit 758adc2

Please sign in to comment.