From 1ad9e0d7c1bc085e5eaeac6c7e2d41bbd75dbdf5 Mon Sep 17 00:00:00 2001 From: Stephen Crowe <6042774+crowecawcaw@users.noreply.github.com> Date: Fri, 17 Apr 2026 08:59:18 -0700 Subject: [PATCH] ci: add pip and hatch environment caching to reusable python build Add cache: pip to setup-python for pip download caching. Add actions/cache for the full hatch virtualenv environment, keyed on OS, python version, and dependency file hashes. Uses HATCH_DATA_DIR to normalize the env path across platforms. Release artifacts (PyPI packages, installers) are built in separate jobs with clean environments, so the cache does not affect published artifacts. Signed-off-by: Stephen Crowe <6042774+crowecawcaw@users.noreply.github.com> --- .github/workflows/reusable_python_build.yml | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/.github/workflows/reusable_python_build.yml b/.github/workflows/reusable_python_build.yml index 3657034..ea7c3c5 100644 --- a/.github/workflows/reusable_python_build.yml +++ b/.github/workflows/reusable_python_build.yml @@ -1,3 +1,9 @@ +# Caching strategy: +# - pip download cache and hatch virtualenv cache are always enabled. +# - The cache key includes OS, Python version, and hashes of all dependency files so it +# auto-busts when deps change. +# - Release artifacts (PyPI packages, installers) are built in separate jobs with clean +# environments, so the cache does not affect published artifacts. name: Python Build on: @@ -28,6 +34,7 @@ jobs: env: PYTHON: ${{ inputs.python-version }} PY_COLORS: 1 + HATCH_DATA_DIR: ${{ github.workspace }}/.hatch-data steps: - uses: actions/checkout@v4 if: ${{ !inputs.branch && !inputs.commit && !inputs.ref }} @@ -47,7 +54,7 @@ jobs: if: ${{ inputs.ref }} with: ref: ${{ inputs.ref }} - + - name: setup ${{ inputs.os }} if: inputs.os == 'ubuntu-latest' run: | @@ -56,12 +63,18 @@ jobs: libxcb-icccm4 libxcb-image0 libxcb-keysyms1 libxcb-randr0 \ libxcb-render-util0 libxcb-xinerama0 libxcb-xinput0 libxcb-xfixes0 \ x11-utils libxcb-cursor0 libopengl0 - - name: Set up Python ${{ inputs.python-version }} uses: actions/setup-python@v5 with: python-version: ${{ inputs.python-version }} + cache: pip + + - name: Restore Hatch environment cache + uses: actions/cache@v4 + with: + path: ${{ github.workspace }}/.hatch-data/env + key: hatch-env-${{ inputs.os }}-py${{ inputs.python-version }}-${{ hashFiles('pyproject.toml', 'hatch.toml', 'requirements*.txt') }} - name: Install Hatch run: | @@ -74,4 +87,4 @@ jobs: run: hatch -v build - name: Run Tests - run: hatch run test \ No newline at end of file + run: hatch run test