A shortcut action to cache Julia depot contents to reduce GitHub Actions running time.
An example workflow that uses this action might look like this:
name: CI
on: [push, pull_request]
# needed to allow julia-actions/cache to delete old caches that it has created
permissions:
actions: write
contents: read
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: julia-actions/setup-julia@v1
- uses: julia-actions/cache@v1
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-runtest@v1
By default the majority of the depot is cached. To also cache ~/.julia/registries/
, use
- uses: julia-actions/cache@v1
with:
cache-registries: "true"
However note that caching the registries may mean that the registry will not be updated each run.
cache-name
- The cache key prefix. Defaults tojulia-cache-${{ github.workflow }}-${{ github.job }}
. The key body automatically includes matrix vars and the OS. Include any other parameters/details in this prefix to ensure one unique cache key per concurrent job type.include-matrix
- Whether to include the matrix values when constructing the cache key. Defaults totrue
.cache-artifacts
- Whether to cache~/.julia/artifacts/
. Defaults totrue
.cache-packages
- Whether to cache~/.julia/packages/
. Defaults totrue
.cache-registries
- Whether to cache~/.julia/registries/
. Defaults tofalse
. Disabled to ensure CI gets latest versions.cache-compiled
- Whether to cache~/.julia/compiled/
. Defaults totrue
.cache-scratchspaces
- Whether to cache~/.julia/scratchspaces/
. Defaults totrue
.cache-logs
- Whether to cache~/.julia/logs/
. Defaults totrue
. Helps auto-Pkg.gc()
keep the cache small.delete-old-caches
- Whether to delete old caches for the given key. Defaults totrue
token
- A github PAT. Defaults togithub.token
. Requiresrepo
scope to enable the deletion of old caches.
cache-hit
- A boolean value to indicate an exact match was found for the primary key. Returns "" when the key is new. Forwarded from actions/cache.
This action is a wrapper around https://github.com/actions/cache. In summary, this action stores the files in the aforementioned paths in one compressed file when running for the first time. This cached file is then restored upon the second run, and afterwards resaved under a new key, and the previous cache deleted. The benefit of caching is that downloading one big file is quicker than downloading many different files from many different locations and precompiling them.
The cache key that the cache will be saved as is based on:
- The
cache-name
input - All variables in the
matrix
(unless disabled viainclude-matrix: 'false'
) - The
runner.os
(may be in the matrix too, but included for safety) - The run id
- The run attempt number
Note
If in your workflow if you do not use a matrix for concurrency you should make cache-name
such that it is unique for
concurrent jobs, otherwise caching may not be effective.
This action automatically deletes old caches that match the first 4 fields of the above key:
- The
cache-name
input - All variables in the
matrix
(unless disabled viainclude-matrix: 'false'
) - The
runner.os
(may be in the matrix too, but included for safety)
Which means your caches files will not grow needlessly. Github also deletes cache files after 90 days which can be increased in private repos to up to 400 days
Note
To allow deletion of caches you will likely need to grant the following to the default
GITHUB_TOKEN
by adding this to your yml:
permissions:
actions: write
contents: read
(Note this won't work for fork PRs but should once merged)
Or provide a token with repo
scope via the token
input option.
See https://cli.github.com/manual/gh_cache_delete
To disable deletion set input delete-old-caches: 'false'
.
Caches are restored and re-saved after every run, retaining the state of the depot throughout runs.
Their size will be regulated like a local depot automatically by the automatic Pkg.gc()
functionality that
clears out old content, which is made possible because the /log
contents are cached.
This action is built around actions/cache
and includes parts of that action. actions/cache
has been released under the following licence:
The MIT License (MIT)
Copyright (c) 2018 GitHub, Inc. and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.