I don't quite understand the extent to which Github actions/cache works, what I mean:
Caching works fine if I make a pull request and then in the same pull request I add 1 more commit, but if I create a new pull request in the same branch - the caching is reset and starts again, but why?
Is there any way to extend file caching to all yml
files and so that each pull request uses existing caching?
Because to speed up the work it turns out - that developers always need to pour their work into one branch, and it somehow sounds like some nonsense.
My caching key is formed as follows
- uses: actions/cache@v2
id: composer-cache
with:
path: .github/docker/development/php-cli/composer/cache
key: ${{ runner.os }}-develop-composer-${{ hashFiles('src/composer.lock') }}
restore-keys: |
${{ runner.os }}-develop-composer-
Yeah, GitHub's cache action has unintuitive behavior across branches. Pull request workflows don't share, and tag workflows never get a cache hit.
Per the docs (useful bit made bold):
A workflow can access and restore a cache created in the current branch, the base branch (including base branches of forked repositories), or the default branch (usually
main
). For example, a cache created on the default branch would be accessible from any pull request. Also, if the branchfeature-b
has the base branchfeature-a
, a workflow triggered onfeature-b
would have access to caches created in the default branch (main
),feature-a
, andfeature-b
.
So the solution then is to make a separate workflow triggered by pushes to main
— plus any base branches you like — just to keep a fresh cache available to pull requests and tags.