From e123a30911bbdaecaef4f9fb40762a7d726edcd2 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 20 Feb 2025 09:25:53 -0600 Subject: [PATCH 1/5] Switch caching to use re-actors/cache-python-deps --- .github/workflows/ci-cd.yml | 37 +++++++++++++++++++++----- .github/workflows/reusable-linters.yml | 12 +++++++-- 2 files changed, 40 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index 98ef423..f2e39fc 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -79,9 +79,16 @@ jobs: uses: actions/setup-python@v5 with: python-version: ${{ env.PYTHON_LATEST }} - cache: pip - cache-dependency-path: - requirements/*.txt + - name: >- + Calculate dependency files' combined hash value + for use in the cache key + id: calc-cache-key-files + uses: ./.github/actions/cache-keys + - name: Set up pip cache + uses: re-actors/cache-python-deps@release/v1 + with: + cache-key-for-dependency-files: >- + ${{ steps.calc-cache-key-files.outputs.cache-key-for-dep-files }} - name: Install core libraries for build run: python -Im pip install build - name: Build sdists and pure-python wheel @@ -235,8 +242,16 @@ jobs: with: python-version: ${{ matrix.pyver }} allow-prereleases: true - cache: pip - cache-dependency-path: requirements/*.txt + - name: >- + Calculate dependency files' combined hash value + for use in the cache key + id: calc-cache-key-files + uses: ./.github/actions/cache-keys + - name: Set up pip cache + uses: re-actors/cache-python-deps@release/v1 + with: + cache-key-for-dependency-files: >- + ${{ steps.calc-cache-key-files.outputs.cache-key-for-dep-files }} - name: Install dependencies uses: py-actions/py-dependency-install@v4 with: @@ -389,8 +404,16 @@ jobs: uses: actions/setup-python@v5 with: python-version: 3.13 - cache: pip - cache-dependency-path: requirements/*.txt + - name: >- + Calculate dependency files' combined hash value + for use in the cache key + id: calc-cache-key-files + uses: ./.github/actions/cache-keys + - name: Set up pip cache + uses: re-actors/cache-python-deps@release/v1 + with: + cache-key-for-dependency-files: >- + ${{ steps.calc-cache-key-files.outputs.cache-key-for-dep-files }} - name: Install dependencies uses: py-actions/py-dependency-install@v4 with: diff --git a/.github/workflows/reusable-linters.yml b/.github/workflows/reusable-linters.yml index 1b0c6e4..ac657bf 100644 --- a/.github/workflows/reusable-linters.yml +++ b/.github/workflows/reusable-linters.yml @@ -36,8 +36,16 @@ jobs: uses: actions/setup-python@v5 with: python-version: ${{ env.PYTHON_LATEST }} - cache: pip - cache-dependency-path: requirements/*.txt + - name: >- + Calculate dependency files' combined hash value + for use in the cache key + id: calc-cache-key-files + uses: ./.github/actions/cache-keys + - name: Set up pip cache + uses: re-actors/cache-python-deps@release/v1 + with: + cache-key-for-dependency-files: >- + ${{ steps.calc-cache-key-files.outputs.cache-key-for-dep-files }} - name: Cache pre-commit.com virtualenvs uses: actions/cache@v4 with: From 53a440daac8d16bf69aafdc945e213fbb43df24d Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 20 Feb 2025 09:26:55 -0600 Subject: [PATCH 2/5] copy fragment --- CHANGES/93.contrib.rst | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 CHANGES/93.contrib.rst diff --git a/CHANGES/93.contrib.rst b/CHANGES/93.contrib.rst new file mode 100644 index 0000000..d571562 --- /dev/null +++ b/CHANGES/93.contrib.rst @@ -0,0 +1,7 @@ +GitHub Actions CI/CD is now configured to manage caching pip-ecosystem +dependencies using `re-actors/cache-python-deps`_ -- an action by +:user:`webknjaz` that takes into account ABI stability and the exact +version of Python runtime. + +.. _`re-actors/cache-python-deps`: + https://github.com/marketplace/actions/cache-python-deps From 9aea612376f7b3397cefa26b879a8c06772e4fe6 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 20 Feb 2025 09:28:09 -0600 Subject: [PATCH 3/5] copy missing file --- .github/actions/cache-keys/action.yml | 46 +++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 .github/actions/cache-keys/action.yml diff --git a/.github/actions/cache-keys/action.yml b/.github/actions/cache-keys/action.yml new file mode 100644 index 0000000..a3527c0 --- /dev/null +++ b/.github/actions/cache-keys/action.yml @@ -0,0 +1,46 @@ +--- + +name: placeholder +description: placeholder + +outputs: + cache-key-for-dep-files: + description: >- + A cache key string derived from the dependency declaration files. + value: ${{ steps.calc-cache-key-files.outputs.files-hash-key }} + +runs: + using: composite + steps: + - name: >- + Calculate dependency files' combined hash value + for use in the cache key + id: calc-cache-key-files + run: | + from os import environ + from pathlib import Path + + FILE_APPEND_MODE = 'a' + + files_derived_hash = '${{ + hashFiles( + 'tox.ini', + 'pyproject.toml', + '.pre-commit-config.yaml', + 'pytest.ini', + 'requirements/**' + ) + }}' + + print(f'Computed file-derived hash is {files_derived_hash}.') + + with Path(environ['GITHUB_OUTPUT']).open( + mode=FILE_APPEND_MODE, + ) as outputs_file: + print( + f'files-hash-key={files_derived_hash}', + file=outputs_file, + ) + shell: python + +... From d8277ce69635cbf0b9a3ea5ea52474ab5bfa5b5d Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 20 Feb 2025 09:29:39 -0600 Subject: [PATCH 4/5] add setup.cfg to cache key --- .github/actions/cache-keys/action.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/actions/cache-keys/action.yml b/.github/actions/cache-keys/action.yml index a3527c0..85378aa 100644 --- a/.github/actions/cache-keys/action.yml +++ b/.github/actions/cache-keys/action.yml @@ -28,7 +28,8 @@ runs: 'pyproject.toml', '.pre-commit-config.yaml', 'pytest.ini', - 'requirements/**' + 'requirements/**', + 'setup.cfg' ) }}' From 2c8d86fd3b3ba948e5d6ae33461d5d8309f90ed5 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 20 Feb 2025 09:47:29 -0600 Subject: [PATCH 5/5] checkout for cache key --- .github/workflows/ci-cd.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index f2e39fc..d05cdd1 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -222,6 +222,8 @@ jobs: timeout-minutes: 5 continue-on-error: ${{ matrix.experimental }} steps: + - name: Checkout project + uses: actions/checkout@v4 - name: Retrieve the project source from an sdist inside the GHA artifact uses: re-actors/checkout-python-sdist@release/v2 with: