From 7fea26ba367b8126d067173872dc29f5870113ad Mon Sep 17 00:00:00 2001 From: Antti Kaihola <13725+akaihola@users.noreply.github.com> Date: Fri, 2 Aug 2024 16:57:22 +0300 Subject: [PATCH 1/3] build: experimental python env and pip caching --- .github/workflows/python-package.yml | 105 ++++++++++++++++++++++++++- 1 file changed, 103 insertions(+), 2 deletions(-) diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index 81a30cc33..54d9d59d4 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -30,6 +30,39 @@ jobs: cache-dependency-glob: | **/setup.cfg **/pyproject.toml + + # 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 @@ -119,7 +152,8 @@ 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 }} @@ -128,6 +162,39 @@ jobs: with: python-version: ${{ matrix.python-version }} activate-environment: true + + # 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 @@ -153,9 +220,43 @@ jobs: - uses: actions/checkout@v4 - name: Install uv uses: astral-sh/setup-uv@v6 - - uses: actions/setup-python@v5 + - id: setup-python + uses: actions/setup-python@v5 with: python-version: 3.x + + # 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 From 23d4d220389ac802e2e1cd5e3e8115b6a1a76fda Mon Sep 17 00:00:00 2001 From: Antti Kaihola <13725+akaihola@users.noreply.github.com> Date: Mon, 1 Sep 2025 10:14:46 +0300 Subject: [PATCH 2/3] fix(ci): unify cache keys --- .github/workflows/python-package.yml | 69 ++++++++++++---------------- 1 file changed, 30 insertions(+), 39 deletions(-) diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index 54d9d59d4..17178f15d 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -38,10 +38,10 @@ jobs: path: | ${{ env.pythonLocation }}/lib ${{ env.pythonLocation }}/bin - key: > - os${{ runner.os }}- - py${{ steps.setup-python.outputs.python-version }}- - req${{ hashFiles('setup.cfg') }} + 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} @@ -50,17 +50,14 @@ jobs: 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') }} + 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 }}- - - " + py${{ steps.setup-python.outputs.python-version }}-\ + os${{ runner.os }}" # END PYTHON CACHING - name: Build wheel distribution @@ -170,10 +167,10 @@ jobs: path: | ${{ env.pythonLocation }}/lib ${{ env.pythonLocation }}/bin - key: > - os${{ runner.os }}- - py${{ steps.setup-python.outputs.python-version }}- - req${{ hashFiles('setup.cfg') }} + 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} @@ -182,17 +179,14 @@ jobs: 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') }} + 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 }}- - - " + py${{ steps.setup-python.outputs.python-version }}-\ + os${{ runner.os }}" # END PYTHON CACHING - name: Download wheel uploaded by the build-wheel job @@ -232,10 +226,10 @@ jobs: path: | ${{ env.pythonLocation }}/lib ${{ env.pythonLocation }}/bin - key: > - os${{ runner.os }}- - py${{ steps.setup-python.outputs.python-version }}- - req${{ hashFiles('setup.cfg') }} + 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} @@ -244,17 +238,14 @@ jobs: 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') }} + 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 }}- - - " + py${{ steps.setup-python.outputs.python-version }}-\ + os${{ runner.os }}" # END PYTHON CACHING - name: Download wheel uploaded by the build-wheel job From a7d013da9b34d1a885b2e6c1c63979f57000f99d Mon Sep 17 00:00:00 2001 From: Antti Kaihola <13725+akaihola@users.noreply.github.com> Date: Mon, 1 Sep 2025 11:11:01 +0300 Subject: [PATCH 3/3] fix(ci): add explicit bash shell for Windows compatibility in workflow The uv cache dir commands use bash-specific syntax ( and command substitution) that fails on Windows runners without explicit shell specification. Added shell: bash to all three get-uv-cache steps. --- .github/workflows/python-package.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index 17178f15d..ad4ada345 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -44,6 +44,7 @@ jobs: req${{ hashFiles('setup.cfg') }}" - id: get-uv-cache if: steps.python-cache.outputs.cache-hit != 'true' + shell: bash run: echo "uv-cache-dir=$(uv cache dir)" >> ${GITHUB_OUTPUT} - name: "Cache uv" if: steps.python-cache.outputs.cache-hit != 'true' @@ -173,6 +174,7 @@ jobs: req${{ hashFiles('setup.cfg') }}" - id: get-uv-cache if: steps.python-cache.outputs.cache-hit != 'true' + shell: bash run: echo "uv-cache-dir=$(uv cache dir)" >> ${GITHUB_OUTPUT} - name: "Cache uv" if: steps.python-cache.outputs.cache-hit != 'true' @@ -232,6 +234,7 @@ jobs: req${{ hashFiles('setup.cfg') }}" - id: get-uv-cache if: steps.python-cache.outputs.cache-hit != 'true' + shell: bash run: echo "uv-cache-dir=$(uv cache dir)" >> ${GITHUB_OUTPUT} - name: "Cache uv" if: steps.python-cache.outputs.cache-hit != 'true'