tweag / cooked-validators

MIT License
39 stars 11 forks source link

Peculiar behaviour of GitHub Actions caches with respect to pull requests #322

Closed Niols closed 1 year ago

Niols commented 1 year ago

We have been noticing peculiar behaviours of GitHub Actions caches in the past days. Turns out they are all normal and expected, there is just a notion of scoping involved. In particular:

The GitHub Actions documentation says in particular:

Access restrictions provide cache isolation and security by creating a logical boundary between different branches or tags. Workflow runs can restore caches created in either the current branch or the default branch (usually main). If a workflow run is triggered for a pull request, it can also restore caches created in the base branch, including base branches of forked repositories.

[...]

Workflow runs cannot restore caches created for child branches or sibling branches.

[...]

When a cache is created by a workflow run triggered on a pull request, the cache is created for the merge ref (refs/pull/.../merge). Because of this, the cache will have a limited scope and can only be restored by re-runs of the pull request. It cannot be restored by the base branch or other pull requests targeting that base branch.

Niols commented 1 year ago

In particular, it means you can have many caches all sharing the same key. A bit frustrating, but that's life. (Source for the picture.)

image