nix-community / cache-nix-action

Cache Nix store in GitHub Actions to speed up workflows [maintainer=@deemp]
MIT License
34 stars 7 forks source link

Cache key is never marked as hit #15

Closed jgoux closed 10 months ago

jgoux commented 11 months ago

Hello 👋,

I'm trying Nix through devenv to handle my system dependencies.

Compared to my non-nix setup, my CI time tripled (from 1 min to ~3 min), so I'm trying to find ways to lower this number and this Github Action seems appropriate. 😄

I have a lot of parallel jobs that are trying to write cache to the same key (kind of logical, I have to same setup workflow for all of them).

What I don't understand is that it seems like I'm never hitting the exact cache key: https://github.com/jgoux/acme/actions/runs/6626645294/job/17999990286#step:3:1298

It means that all my jobs have a long post-setup step (1m30s) because the action is garbage collecting and creating a new cache. Also, it seems that the Failed to save: Unable to reserve cache with key is happening at the very end of the garbage collection, I'm wondering if there is a way of polling for the lock or not starting garbage collecting if there is a lock in place instead of spending this time if, in the end, the job will hit the lock.

tldr; what am I doing wrong here?

My workflow is here: https://github.com/jgoux/acme/blob/e5e508fd3aac043fc20d657314bc6bc930592f4c/.github/actions/devenv/action.yml

jgoux commented 11 months ago

I've rework my workflow a bit, but the cache is still not marked as hit even if the key appears correct. 🤔

Cache key: https://github.com/jgoux/acme/actions/runs/6689303583/job/18172629418?pr=51#step:3:72

Cache not found log (even if it's the exact same key!): https://github.com/jgoux/acme/actions/runs/6689303583/job/18172629418?pr=51#step:3:1801

deemp commented 10 months ago

Hi, @jgoux! Honestly, I have no idea about why it writes that it hasn't found a key. I see unpacking errors (link) => the action works (see Limitations on why there are such errors). It can't save a cache because there exists one with such a name. You can sometimes purge old nix caches (link). Then, the action will save a new cache, then purge old ones.

jgoux commented 10 months ago

Hey @deemp, since then I think I fixed my CI and everything is as fast as my knowledge goes. 😂 Thanks!