Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore does not find cache key even though it seems to exist #7

Open
jbergstroem opened this issue Jun 29, 2023 · 3 comments
Open

Comments

@jbergstroem
Copy link

Given the following yaml:

      - name: Check if cache key exists
        uses: martijnhols/actions-cache/check@v3.0.11
        id: cache_exists
        with:
          path: .venv
          key: ${{ runner.os }}-python-deps-${{ hashFiles('poetry.lock') }}

      - name: Set up Python
        uses: actions/setup-python@v4
        if: steps.cache_exists.outputs.cache-hit != 'true'
        with:
          python-version: ${{ env.PYTHON_VERSION }}

      - name: Restore dependency cache
        uses: actions/cache@v3
        if: steps.cache_exists.outputs.cache-hit != 'true'
        id: deps-cache
        with:
          path: .venv
          key: ${{ runner.os }}-python-deps-${{ hashFiles('poetry.lock') }}

I get this output:
Screenshot 2023-06-29 at 7 47 57 PM

Comparing the keys, they look identical (copy pasted manually from output):

  • Linux-python-deps-905d6047b1ef7816097d7c2ed5d59e9334470b45f129b2df87b40a4f33058e2a
  • Linux-python-deps-905d6047b1ef7816097d7c2ed5d59e9334470b45f129b2df87b40a4f33058e2a
@jbergstroem
Copy link
Author

Resorted to just calling the cache endpoint via curl instead:

- name: Check if cache key exists
  id: cache_exists
  env:
    url: "${{ github.api_url }}/repos/${{ github.repository }}/actions/caches"
    key: ${{ runner.os }}-python-deps-${{ hashFiles('poetry.lock') }}
  run: |
    curl -s \
    -H "Accept: application/vnd.github+json" \
    -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
    -H "X-GitHub-Api-Version: 2022-11-28" \
    "${{ env.url }}?key=${{ env.key }}" | jq -r '"cache-hit=" + (.total_count > 0 | tostring)' >> "$GITHUB_OUTPUT"

- name: Set up Python
  uses: actions/setup-python@v4
  if: steps.cache_exists.outputs.cache-hit != 'true'
  with:
    python-version: ${{ env.PYTHON_VERSION }}

@MartijnHols
Copy link
Owner

You’re setting up Python in between the check and restore. This probably changes the result of the hash function. Either move that step below the cache restore, or reuse the cache key from the check via the output as documented in the readme.

@jbergstroem
Copy link
Author

You’re setting up Python in between the check and restore. This probably changes the result of the hash function.

Setting up Python doesn't touch poetry.lock and the signatures are identical. Either way, directly calling the API works fine for me!

Let me know if you think this is a me error and I'm happy to close the issue. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants