mirror of
https://github.com/julia-actions/cache.git
synced 2026-02-12 17:36:53 +08:00
Compare commits
28 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a96f53eeda | ||
|
|
bb2ad8a6dc | ||
|
|
b45946153f | ||
|
|
26bda12c02 | ||
|
|
08f6ca9894 | ||
|
|
d696810071 | ||
|
|
643194b98c | ||
|
|
c314effe59 | ||
|
|
c38652fe18 | ||
|
|
ccbc2ac68e | ||
|
|
936559d9c8 | ||
|
|
c2e869b485 | ||
|
|
1835692219 | ||
|
|
24702b2b39 | ||
|
|
8441b1201b | ||
|
|
8684ae14b7 | ||
|
|
85cc05cd46 | ||
|
|
6ee77ae122 | ||
|
|
2f4c647fce | ||
|
|
745127cf80 | ||
|
|
d5841feac0 | ||
|
|
41e67bac8f | ||
|
|
d2b01b0f17 | ||
|
|
905462d72f | ||
|
|
8e86b8dd2a | ||
|
|
20058080ea | ||
|
|
ce20795e57 | ||
|
|
1dbed0efdd |
9
.github/dependabot.yml
vendored
Normal file
9
.github/dependabot.yml
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
version: 2
|
||||
|
||||
updates:
|
||||
|
||||
# Keep dependencies for GitHub Actions up-to-date
|
||||
- package-ecosystem: 'github-actions'
|
||||
directory: '/'
|
||||
schedule:
|
||||
interval: 'daily'
|
||||
79
.github/workflows/CI.yml
vendored
Normal file
79
.github/workflows/CI.yml
vendored
Normal file
@@ -0,0 +1,79 @@
|
||||
name: CI
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
paths:
|
||||
- 'action.yml'
|
||||
- '.github/**'
|
||||
pull_request:
|
||||
paths:
|
||||
- 'action.yml'
|
||||
- '.github/**'
|
||||
|
||||
jobs:
|
||||
generate-key:
|
||||
runs-on: ubuntu-latest
|
||||
outputs:
|
||||
cache-name: ${{ steps.name.outputs.cache-name }}
|
||||
steps:
|
||||
- name: Generate random file
|
||||
shell: 'julia --color=yes {0}'
|
||||
run: 'write("random.txt", string(rand(10)))'
|
||||
- name: Set cache-name as output
|
||||
id: name
|
||||
run: echo "cache-name=${{ hashFiles('random.txt') }}" >> $GITHUB_OUTPUT
|
||||
|
||||
test-save:
|
||||
needs: generate-key
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest, windows-latest, macOS-latest]
|
||||
fail-fast: false
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
- uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b
|
||||
- name: Save cache
|
||||
id: cache
|
||||
uses: ./
|
||||
with:
|
||||
cache-name: ${{ needs.generate-key.outputs.cache-name }}
|
||||
- name: Check no artifacts dir
|
||||
shell: 'julia --color=yes {0}'
|
||||
run: |
|
||||
dir = joinpath(first(DEPOT_PATH), "artifacts")
|
||||
@assert !isdir(dir)
|
||||
- name: Install a small binary
|
||||
shell: 'julia --color=yes {0}'
|
||||
run: 'using Pkg; Pkg.add("pandoc_jll")'
|
||||
|
||||
test-restore:
|
||||
needs: [generate-key, test-save]
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest, windows-latest, macOS-latest]
|
||||
fail-fast: false
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
- uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b
|
||||
- name: Restore cache
|
||||
id: cache
|
||||
uses: ./
|
||||
with:
|
||||
cache-name: ${{ needs.generate-key.outputs.cache-name }}
|
||||
- name: Test cache-hit output
|
||||
shell: 'julia --color=yes {0}'
|
||||
run: |
|
||||
@show ENV["cache-hit"]
|
||||
@assert ENV["cache-hit"] == "true"
|
||||
env:
|
||||
cache-hit: ${{ steps.cache.outputs.cache-hit }}
|
||||
- name: Check non-empty artifacts and packages dir
|
||||
shell: 'julia --color=yes {0}'
|
||||
run: |
|
||||
artifacts_dir = joinpath(first(DEPOT_PATH), "artifacts")
|
||||
@assert !isempty(readdir(artifacts_dir))
|
||||
packages_dir = joinpath(first(DEPOT_PATH), "packages")
|
||||
@assert !isempty(readdir(packages_dir))
|
||||
|
||||
82
README.md
82
README.md
@@ -1,63 +1,75 @@
|
||||
# cache-artifacts
|
||||
A shortcut action to cache Julia artifacts.
|
||||
# julia-actions/cache Action
|
||||
|
||||
Using this action is equivalent to including the following step in your workflows:
|
||||
|
||||
```yaml
|
||||
- uses: actions/cache@v1
|
||||
env:
|
||||
cache-name: cache-artifacts
|
||||
with:
|
||||
path: ~/.julia/artifacts
|
||||
key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/Project.toml') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-test-${{ env.cache-name }}-
|
||||
${{ runner.os }}-test-
|
||||
${{ runner.os }}-
|
||||
```
|
||||
A shortcut action to cache Julia artifacts, packages and (optionally) registries to reduce GitHub Actions running time.
|
||||
|
||||
## Usage
|
||||
|
||||
### Inputs
|
||||
An example workflow that uses this action might look like this:
|
||||
|
||||
```yaml
|
||||
- uses: julia-actions/cache-artifacts@v1
|
||||
with:
|
||||
# The cache name is used as part of the cache key.
|
||||
# It is equivalent to the cache-name environment variable in the snippet above.
|
||||
#
|
||||
# Default: cache-artifacts
|
||||
cache-name: ''
|
||||
name: CI
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- 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, this caches the files in `~/.julia/artifacts/` and `~/.julia/packages/`.
|
||||
To also cache `~/.julia/registries/`, use
|
||||
|
||||
```yaml
|
||||
- uses: julia-actions/cache@v1
|
||||
with:
|
||||
cache-registries: "true"
|
||||
```
|
||||
|
||||
Note that caching the registries may actually slow down the workflow running time on Windows runners.
|
||||
That is why caching the registries is disabled by default.
|
||||
|
||||
### Inputs
|
||||
|
||||
- `cache-name` - Name used as part of the cache keys
|
||||
- `cache-artifacts` - Whether to cache `~/.julia/artifacts/`. Enabled by default.
|
||||
- `cache-packages` - Whether to cache `~/.julia/packages/`. Enabled by default.
|
||||
- `cache-registries` - Whether to cache `~/.julia/registries/`. Disabled by default.
|
||||
|
||||
### Outputs
|
||||
|
||||
```yaml
|
||||
outputs:
|
||||
# A boolean value to indicate an exact match was found for the primary key.
|
||||
# Forwarded from actions/cache, check its documentation for more info.
|
||||
cache-hit: ''
|
||||
```
|
||||
- `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.
|
||||
|
||||
## 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.
|
||||
The benefit of this is that downloading one big file is quicker than downloading many different files from many different locations.
|
||||
|
||||
## Third Party Notice
|
||||
|
||||
This action is built around [`actions/cache`](https://github.com/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
|
||||
|
||||
39
action.yml
39
action.yml
@@ -1,6 +1,6 @@
|
||||
name: 'Cache Julia Artifacts'
|
||||
description: 'Cache Julia artifacts using actions/cache'
|
||||
author: 'Sascha Mann'
|
||||
name: 'Cache Julia artifacts, packages and registry'
|
||||
description: 'Cache Julia using actions/cache'
|
||||
author: 'Sascha Mann, Rik Huijzer, and contributors'
|
||||
|
||||
branding:
|
||||
icon: 'archive'
|
||||
@@ -9,26 +9,45 @@ branding:
|
||||
inputs:
|
||||
cache-name:
|
||||
description: 'Name used as part of the cache keys'
|
||||
default: 'cache-artifacts'
|
||||
default: 'julia-cache'
|
||||
cache-artifacts:
|
||||
description: 'Whether to cache ~/.julia/artifacts/'
|
||||
default: 'true'
|
||||
cache-packages:
|
||||
description: 'Whether to cache ~/.julia/packages/'
|
||||
default: 'true'
|
||||
cache-registries:
|
||||
description: 'Whether to cache ~/.julia/registries/'
|
||||
default: 'false'
|
||||
|
||||
outputs:
|
||||
cache-hit:
|
||||
description: 'A boolean value to indicate an exact match was found for the primary key. Forwarded from actions/cache'
|
||||
description: 'A boolean value to indicate an exact match was found for the primary key. Returns \"\" when the key is new. Forwarded from actions/cache'
|
||||
value: ${{ steps.hit.outputs.cache-hit }}
|
||||
|
||||
runs:
|
||||
using: 'composite'
|
||||
steps:
|
||||
- uses: actions/cache@937d24475381cd9c75ae6db12cb4e79714b926ed
|
||||
- id: paths
|
||||
run: |
|
||||
[ "${{ inputs.cache-artifacts }}" = "true" ] && A_PATH="~/.julia/artifacts"
|
||||
echo "ARTIFACTS_PATH=$A_PATH" >> $GITHUB_ENV
|
||||
[ "${{ inputs.cache-packages }}" = "true" ] && P_PATH="~/.julia/packages"
|
||||
echo "PACKAGES_PATH=$P_PATH" >> $GITHUB_ENV
|
||||
[ "${{ inputs.cache-registries }}" = "true" ] && R_PATH="~/.julia/registries"
|
||||
echo "REGISTRIES_PATH=$R_PATH" >> $GITHUB_ENV
|
||||
shell: bash
|
||||
|
||||
- uses: actions/cache@4723a57e26efda3a62cbde1812113b730952852d
|
||||
id: cache
|
||||
with:
|
||||
path: ~/.julia/artifacts
|
||||
path: "${{ format('{0}\n{1}\n{2}', env.ARTIFACTS_PATH, env.PACKAGES_PATH, env.REGISTRIES_PATH) }}"
|
||||
key: ${{ runner.os }}-test-${{ inputs.cache-name }}-${{ hashFiles('**/Project.toml') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-test-${{ inputs.cache-name }}-
|
||||
${{ runner.os }}-test-
|
||||
${{ runner.os }}-
|
||||
|
||||
- run: echo "::set-output name=cache-hit::$CACHE_HIT"
|
||||
- id: hit
|
||||
run: echo "cache-hit=$CACHE_HIT" >> $GITHUB_OUTPUT
|
||||
env:
|
||||
CACHE_HIT: ${{ steps.cache.outputs.cache-hit }}
|
||||
shell: bash
|
||||
|
||||
Reference in New Issue
Block a user