Skip to content

Commit

Permalink
build: experimental python env and pip caching
Browse files Browse the repository at this point in the history
  • Loading branch information
akaihola committed Feb 3, 2025
1 parent 7aa5f77 commit bee382f
Showing 1 changed file with 105 additions and 3 deletions.
108 changes: 105 additions & 3 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,41 @@ jobs:
- uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v3
- uses: actions/setup-python@v5
- id: setup-python
uses: actions/setup-python@v5

# PYTHON CACHING:
- id: python-cache
uses: actions/cache@v4
with:
path: |
${{ env.pythonLocation }}/lib
${{ env.pythonLocation }}/bin
key: >
os${{ runner.os }}-
py${{ steps.setup-python.outputs.python-version }}-
req${{ hashFiles('setup.cfg') }}
- id: get-uv-cache
if: steps.python-cache.outputs.cache-hit != 'true'
run: echo "uv-cache-dir=$(uv cache dir)" >> ${GITHUB_OUTPUT}
- name: "Cache uv"
if: steps.python-cache.outputs.cache-hit != 'true'
uses: actions/cache@v4
with:
path: ${{steps.get-uv-cache.outputs.uv-cache-dir}}
key: >
os${{ runner.os }}-
py${{ steps.setup-python.outputs.python-version }}-
req${{ hashFiles('setup.cfg') }}
restore-keys: "\
os${{ runner.os }}-\
py${{ steps.setup-python.outputs.python-version }}-
os${{ runner.os }}-
"
# END PYTHON CACHING

- name: Build wheel distribution
run: uv build --wheel
- name: Upload wheel for other jobs
Expand Down Expand Up @@ -118,10 +152,44 @@ jobs:
with:
fetch-depth: 0
# need full history since Pytest runs Darker itself below
- name: Set up Python ${{ matrix.python-version }}
- id: setup-python
name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

# PYTHON CACHING:
- id: python-cache
uses: actions/cache@v4
with:
path: |
${{ env.pythonLocation }}/lib
${{ env.pythonLocation }}/bin
key: >
os${{ runner.os }}-
py${{ steps.setup-python.outputs.python-version }}-
req${{ hashFiles('setup.cfg') }}
- id: get-uv-cache
if: steps.python-cache.outputs.cache-hit != 'true'
run: echo "uv-cache-dir=$(uv cache dir)" >> ${GITHUB_OUTPUT}
- name: "Cache uv"
if: steps.python-cache.outputs.cache-hit != 'true'
uses: actions/cache@v4
with:
path: ${{steps.get-uv-cache.outputs.uv-cache-dir}}
key: >
os${{ runner.os }}-
py${{ steps.setup-python.outputs.python-version }}-
req${{ hashFiles('setup.cfg') }}
restore-keys: "\
os${{ runner.os }}-\
py${{ steps.setup-python.outputs.python-version }}-
os${{ runner.os }}-
"
# END PYTHON CACHING

- name: Download wheel uploaded by the build-wheel job
uses: actions/download-artifact@v4
- name: Install Darker and its dependencies from the wheel built earlier
Expand All @@ -147,7 +215,41 @@ jobs:
- uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v3
- uses: actions/setup-python@v5
- id: setup-python
uses: actions/setup-python@v5

# PYTHON CACHING:
- id: python-cache
uses: actions/cache@v4
with:
path: |
${{ env.pythonLocation }}/lib
${{ env.pythonLocation }}/bin
key: >
os${{ runner.os }}-
py${{ steps.setup-python.outputs.python-version }}-
req${{ hashFiles('setup.cfg') }}
- id: get-uv-cache
if: steps.python-cache.outputs.cache-hit != 'true'
run: echo "uv-cache-dir=$(uv cache dir)" >> ${GITHUB_OUTPUT}
- name: "Cache uv"
if: steps.python-cache.outputs.cache-hit != 'true'
uses: actions/cache@v4
with:
path: ${{steps.get-uv-cache.outputs.uv-cache-dir}}
key: >
os${{ runner.os }}-
py${{ steps.setup-python.outputs.python-version }}-
req${{ hashFiles('setup.cfg') }}
restore-keys: "\
os${{ runner.os }}-\
py${{ steps.setup-python.outputs.python-version }}-
os${{ runner.os }}-
"
# END PYTHON CACHING

- name: Download wheel uploaded by the build-wheel job
uses: actions/download-artifact@v4
- name: Build source distribution
Expand Down

0 comments on commit bee382f

Please sign in to comment.