diff --git a/.github/actions/cache-pip-deps/action.yml b/.github/actions/cache-pip-deps/action.yml deleted file mode 100644 index 446f8eb..0000000 --- a/.github/actions/cache-pip-deps/action.yml +++ /dev/null @@ -1,114 +0,0 @@ ---- - -name: placeholder -description: placeholder - -inputs: - cache-key-for-dep-files: - description: >- - A cache key string derived from the dependency declaration files. - required: true - -outputs: - cache-key-for-pip-deps: - description: >- - A cache key string derived from the current interpreter version - and the dependency file hashes. - value: >- - ${{ steps.python-runtime.outputs.cache-entry-key }} - cache-key-for-python-interpreter: - description: >- - A cache key string derived from the current interpreter version. - value: >- - ${{ steps.python-runtime.outputs.restore-key-prefix }} - cache-key-for-os: - description: >- - A cache key string derived from the current OS and interpreter stability. - value: >- - ${{ steps.python-runtime.outputs.restore-key-fallback-prefix }} - is-stable-abi: - description: >- - Whether the currently used Python version has a reliable - Application Binary Interface. If it doesn't, it's best to avoid - caching any dependencies. - value: ${{ steps.python-runtime.outputs.is-stable-abi }} - pip-cache-dir: - description: >- - The discovered pip cache directory path. - value: ${{ steps.pip-cache-dir.outputs.dir }} - -runs: - using: composite - steps: - - name: >- - Calculate Python interpreter properties - version hash value - for use in the cache key - id: python-runtime - run: | - from hashlib import sha512 - from os import environ - from sys import version, version_info - - FILE_APPEND_MODE = 'a' - - is_stable_abi = version_info.releaselevel == 'final' - version_hash = sha512(version.encode()).hexdigest() - - stable_or_unstable = f'{"" if is_stable_abi else "un"}stable' - restore_key_fallback_prefix = ( - f'${{ runner.os }}-pip-{stable_or_unstable}' - ) - restore_key_prefix = f'{restore_key_fallback_prefix}-{version_hash}' - cache_entry_key = ( - f'{restore_key_prefix}-{version_hash}-' - '${{ inputs.cache-key-for-dep-files }}' - ) - - print(f'Python ABI is found to be {stable_or_unstable}.') - print(f'Python version-derived hash is {version_hash}.') - print(f'The computed cache entry key is {cache_entry_key}.') - - with open( - environ['GITHUB_OUTPUT'], mode=FILE_APPEND_MODE, - ) as outputs_file: - print( - 'is-stable-abi={is_stable_abi}'. - format(is_stable_abi=str(is_stable_abi).lower()), - file=outputs_file, - ) - print( - f'restore-key-fallback-prefix={restore_key_fallback_prefix}', - file=outputs_file, - ) - print( - f'restore-key-prefix={restore_key_prefix}', - file=outputs_file, - ) - print(f'cache-entry-key={cache_entry_key}', file=outputs_file) - shell: python - - name: Get pip cache dir - id: pip-cache-dir - run: >- - echo "dir=$(python -m pip cache dir)" >> "${GITHUB_OUTPUT}" - shell: bash - - name: Skip setting up pip cache - if: >- - !fromJSON(steps.python-runtime.outputs.is-stable-abi) - run: >- - >&2 echo Skipping cache configuration because the current - Python ABI is unstable... - shell: bash - - name: Set up pip cache - if: fromJSON(steps.python-runtime.outputs.is-stable-abi) - uses: actions/cache@v4 - with: - path: ${{ steps.pip-cache-dir.outputs.dir }} - key: >- - ${{ steps.python-runtime.outputs.cache-entry-key }} - restore-keys: | - ${{ steps.python-runtime.outputs.cache-entry-key }} - ${{ steps.python-runtime.outputs.restore-key-prefix }} - ${{ steps.python-runtime.outputs.restore-key-fallback-prefix }} - -... diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index 17598e7..cf74dfb 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -85,9 +85,9 @@ jobs: id: calc-cache-key-files uses: ./.github/actions/cache-keys - name: Set up pip cache - uses: ./.github/actions/cache-pip-deps + uses: re-actors/cache-python-deps@release/v1 with: - cache-key-for-dep-files: >- + 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 @@ -233,9 +233,9 @@ jobs: id: calc-cache-key-files uses: ./.github/actions/cache-keys - name: Set up pip cache - uses: ./.github/actions/cache-pip-deps + uses: re-actors/cache-python-deps@release/v1 with: - cache-key-for-dep-files: >- + 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 diff --git a/.github/workflows/reusable-linters.yml b/.github/workflows/reusable-linters.yml index d4207e5..d8d0b60 100644 --- a/.github/workflows/reusable-linters.yml +++ b/.github/workflows/reusable-linters.yml @@ -42,9 +42,9 @@ jobs: id: calc-cache-key-files uses: ./.github/actions/cache-keys - name: Set up pip cache - uses: ./.github/actions/cache-pip-deps + uses: re-actors/cache-python-deps@release/v1 with: - cache-key-for-dep-files: >- + 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 diff --git a/CHANGES/622.contrib.rst b/CHANGES/622.contrib.rst deleted file mode 100644 index 7c59659..0000000 --- a/CHANGES/622.contrib.rst +++ /dev/null @@ -1,2 +0,0 @@ -GitHub Actions CI/CD is now configured to manage caching pip-managed -dependencies using in-tree composite actions -- by :user:`webknjaz`. diff --git a/CHANGES/633.contrib.rst b/CHANGES/633.contrib.rst new file mode 100644 index 0000000..d571562 --- /dev/null +++ b/CHANGES/633.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