actions / cache

Cache dependencies and build outputs in GitHub Actions
MIT License
4.49k stars 1.2k forks source link

Cache not found between jobs while being in the same run #1194

Open mwestphal opened 1 year ago

mwestphal commented 1 year ago

I've found a strange bug with cache action. I know about cache being only available to the PR with the branch you are working on, and only when run is finished. this is not an usage issue on my side.

In short, here is what I do with cache.

My CI:

job 1 is recovering a cache using a key, if not available, download the data from somewhere else and upload an artifact, on sucess, cache is updated with the new data if any as cache action do automatically.

job 2 is recovering a cache using the same key, if not available download the artifact and keep going from there. On sucess cache is updated but technically it is not even needed as job1 has already done it.

The problematic workflow: There is a specific situation where this breaks and it should not, when new data is available and job 2 fails.

RUN 1 (new data, broken build)

job 1 is trying to recover cache using a key, there is new data so cache is not available, so data is being downloaded from alternate source and uploaded as artifacts. cache is created from the new data as job1 is successful.

job 2 is trying to recover cache using a key, there is new data so cache is not available, so data artifact is donwloaded instead. job 2 fails to build for an unrelated reason. no cache is created from the new data as the job failed.

All behavior is expected from now

RUN 2 (no new data, build fixed)

job 1 is trying to recover cache using a key it is found, job1 succeed

job 2 is trying to recover cache using a key BUT FAILS FOR AN UNKNOWN REASON, job 2 tries to fallback on artifact, which is not available, job 2 fails.

I can see the cache listed in the cache, but job2 is not able and will never be able to access it, while job 1 can access it super fine.

Let me know If I missed anything here. I could try to create a minimal repo to reproduce this but that would be a fair amount of work so I will wait for some feedback first.

mwestphal commented 1 year ago

Link to an actual CI failing like this: https://github.com/f3d-app/f3d/actions/runs/5305416707

(Ignore MacOS jobs, something else seems to be going on with these)

comp615 commented 1 year ago

I also am experiencing this, we have a workflow that basically does this:

jobs:
  cache_check:
    secrets: inherit
    uses: ./.github/workflows/module-cache-check.yml

  lint:
    secrets: inherit
    uses: ./.github/workflows/module-lint.yml
    needs: [cache_check]

A first job to cache the code, then a second (actually many more) which pull that cache and read from it. Despite being in literally the same run, cache_check consistently finds the key while all other jobs do not. Is this because we're using workflow_call? Bad github behavior?

infogulch commented 1 year ago

I'm having an issue where the cache is just not found at all, even between separate runs. #1198

github-actions[bot] commented 9 months ago

This issue is stale because it has been open for 200 days with no activity. Leave a comment to avoid closing this issue in 5 days.

mwestphal commented 9 months ago

comment

constgen commented 7 months ago

Facing the same issue. Chained jobs can't restore the cache created on the very first job in the chain on the same run

jorroll commented 2 months ago

I was running into this issue but was able to resolve it after reading this comment in a similar issue. I found that the absolute path provided needs to be exactly the same in order for cache restore to work properly. If different jobs are using different container images this might be hard to achieve.