julia-actions / cache

A shortcut action to cache Julia artifacts, packages, and registries.
MIT License
38 stars 8 forks source link
actions cache github-actions julia

julia-actions/cache Action

A shortcut action to cache Julia depot contents to reduce GitHub Actions running time.

Usage

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@v4
    - uses: julia-actions/setup-julia@v2
    - uses: julia-actions/cache@v2
    - uses: julia-actions/julia-buildpkg@v1
    - uses: julia-actions/julia-runtest@v1

By default all depot directories called out below are cached.

Requirements

Optional Inputs

Outputs

How It Works

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.

By default, this action removes caches that were previously made by jobs on the same branch with the same restore key. GitHub automatically removes old caches after a certain period or when the repository cache allocation is full. It is, however, more efficient to explicitly remove old caches to improve caching for less frequently run jobs.

Cache keys

The cache key that the cache will be saved as is based on:

[!NOTE] If there is job concurrency that is not fully defined by a matrix you should ensure that cache-name is unique for each concurrent job, otherwise caching may not be effective.

Cache Retention

This action automatically deletes old caches that match the first 4 fields of the above key:

Which means your caches files will not grow needlessly. GitHub also deletes cache files after 7 days of not being accessed, and there is a limit of 10 GB for the total size of cache files associated to each repository.

[!NOTE] To allow deletion of caches you will likely need to grant the following permissions to the GITHUB_TOKEN by adding this to your GitHub actions workflow:

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'.

Cache Garbage Collection

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.

Third Party Notice

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.