Cache improvements [ci]
Proposed change
A few days ago Github added the option to manage Action caches from a web interface. https://github.blog/changelog/2022-10-20-manage-caches-in-your-actions-workflows-from-web-interface/
Looking at our cache list: https://github.com/home-assistant/core/actions/caches it is rather obvious that we are well above the soft limit, 10GB, set by Github. It's regularly in the 20-40GB range, I've even seen 70GB. That isn't a direct issue as Github will automatically evict old entries. However, there is still room for improvement.
In particular:
- Github doesn't care if a cache is useful or not, it will just evict the oldest (accessed) ones first.
- Being over the limit of 10GB can have (small) performance impacts when accessing / storing cache entries.
The cache eviction process may cause cache thrashing, where caches are created and deleted at a high frequency.
https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#usage-limits-and-eviction-policy
Changes
- After a PR is merged / closed, delete all cache entries from that branch / ref. Github won't reuse them anyway. https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#restrictions-for-accessing-a-cache
- Delete all pip caches for PRs. The venv cache still kept. If it shouldn't be available, the fallback will be the last pip cache from the
devbranch which is close enough. In almost all cases only one or two new dependencies are installed per PR. In special cases, like adding support for the next Python version, a new label can be addedci-keep-cacheto bypass deletion and keep the last cache entry (per Python version). - Delete all but the latest pip cache entries for the
devbranch.
Improvements
- With less cache entries taking up space, there will be more space available for venv caches. I.e. it might not need to be rebuild quite that often if a PR doesn't target the most up-to-date version of
dev. E.g. at the moment the oldest cache entry is from 8h ago. - (Maybe) Small performance improvments when accessing / storing cache entries.
Example output
Example output if cache entries are deleted (from my fork)
Keep one entry per Python version
Check ref: refs/heads/dev
Check key regex: Linux-3.9.+-pip
{
"id": 4944,
"ref": "refs/heads/dev",
"key": "Linux-3.9.15-pip-3-2022.11-2022-10-24T08:13:1666599238",
"last_accessed_at": "2022-10-24T15:28:31.530000000Z"
}
Check key regex: Linux-3.10.+-pip
{
"id": 4942,
"ref": "refs/heads/dev",
"key": "Linux-3.10.8-pip-3-2022.11-2022-10-24T08:13:1666599237",
"last_accessed_at": "2022-10-24T15:28:33.986666700Z"
}
Deleted 2 caches.
Notes
- I've used https://github.com/snnaplab/delete-branch-cache-action to delete old caches for closed PRs. The action might need to be added to the list of allowed actions (depending on the repo settings).
snnaplab/delete-branch-cache-action@*
- A new label should be added:
ci-keep-cache.
Refs
- https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows
- https://docs.github.com/en/rest/actions/cache#list-github-actions-caches-for-a-repository
- https://github.com/marketplace/actions/delete-branch-cache-action
Type of change
- [ ] Dependency upgrade
- [ ] Bugfix (non-breaking change which fixes an issue)
- [ ] New integration (thank you!)
- [ ] New feature (which adds functionality to an existing integration)
- [ ] Deprecation (breaking change to happen in the future)
- [ ] Breaking change (fix/feature causing existing functionality to break)
- [ ] Code quality improvements to existing code or addition of tests
Additional information
- This PR fixes or closes issue: fixes #
- This PR is related to issue:
- Link to documentation pull request:
Checklist
- [ ] The code change is tested and works locally.
- [ ] Local tests pass. Your PR cannot be merged unless tests pass
- [ ] There is no commented out code in this PR.
- [ ] I have followed the development checklist
- [ ] The code has been formatted using Black (
black --fast homeassistant tests) - [ ] Tests have been added to verify that the new code works.
If user exposed functionality or configuration variables are added/changed:
- [ ] Documentation added/updated for www.home-assistant.io
If the code communicates with devices, web services, or third-party tools:
- [ ] The manifest file has all fields filled out correctly.
Updated and included derived files by running:python3 -m script.hassfest. - [ ] New or updated dependencies have been added to
requirements_all.txt.
Updated by runningpython3 -m script.gen_requirements_all. - [ ] For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.
- [ ] Untested files have been added to
.coveragerc.
To help with the load of incoming pull requests:
- [ ] I have reviewed two other open pull requests in this repository.