setup-python icon indicating copy to clipboard operation
setup-python copied to clipboard

Cache key conflict

Open vnghia opened this issue 1 year ago • 3 comments

Description: When building with python-version and architecture, only python-version is included in the final cache key, e.g setup-python-Windows-python-3.11.8-poetry-... but not architecture which will cause the Unable to reserve cache with key setup-python-Windows-python-3.11.8-poetry-v2-..., another job may be creating this cache. More details: Cache already exists. Scope: refs/heads/main

Action version: v5

Platform:

  • [x] Ubuntu
  • [x] macOS
  • [x] Windows

Runner type:

  • [x] Hosted
  • [ ] Self-hosted

Tools version:

Repro steps:

jobs:
  build:
    strategy:
      fail-fast: false
      matrix:
        target:
          - os: "windows-latest"
            architecture: "x64"
          - os: "windows-latest"
            architecture: "x86"
    defaults:
      run:
        shell: bash
    runs-on: ${{ matrix.target.os }}

    steps:
      - uses: actions/checkout@v4
      - name: Install poetry
        run: pipx install poetry
      - name: Setup Python
        uses: actions/setup-python@v5
        id: setup-python
        with:
          python-version: "3.11"
          architecture: ${{ matrix.target.architecture }}
          cache: "poetry"

Expected behavior: Cache is cached for all architectures

Actual behavior: Only one architecture is cached

vnghia avatar Feb 29 '24 07:02 vnghia

Hello @vnghia Thank you for creating this issue. We will investigate it and get back to you as soon as we have some feedback.

HarithaVattikuti avatar Mar 02 '24 00:03 HarithaVattikuti

Hello @vnghia 👋, Thank you for your insightful observation. We will consider incorporating your suggestion about including the architecture in the final cache key in our future enhancements. Meantime as a workaround architecture can be included in the cache key using actions/cache as shown below to get separate caches for different architectures.


- name: Setup Python
  uses: actions/setup-python@v5
  id: setup-python
  with:
    python-version: "3.11"
    architecture: ${{ matrix.target.architecture }}
- name: Install Poetry
  run: |
    pipx install poetry
    echo "POETRY_CACHE_DIR=$(pip cache dir)" >> $GITHUB_ENV
- name: Cache poetry
  uses: actions/cache@v3
  with:
    path: ${{ env.POETRY_CACHE_DIR }}
    key: ${{ runner.os }}-poetry-${{ steps.setup-python.outputs.python-version }}-${{ matrix.target.architecture }}-${{ hashFiles('**/poetry.lock') }}
  restore-keys: |
    ${{ runner.os }}-poetry-${{ steps.setup-python.outputs.python-version }}-${{ matrix.target.architecture }}

Your patience and your valuable contribution to the improvement is immensely appreciated!!

priya-kinthali avatar Mar 27 '24 05:03 priya-kinthali

+1 for this feature! Can I also suggest that this enhancement includes within the cache key the additional configurations to the matrix via jobs.<job_id>.strategy.matrix.include?

chongshenng avatar May 22 '24 08:05 chongshenng