Extend cache action (#4)

* Extend cache action

* Also test on Windows and macOS

* Fix a problem with setting output on Windows

* Use echo after set-output

* Generate key only once

* Fix non-matching name (should fail but doesn't weirdly)

* Update action.yml

Co-authored-by: Sascha Mann <git@mail.saschamann.eu>

* Update action.yml

Co-authored-by: Sascha Mann <git@mail.saschamann.eu>

Co-authored-by: Sascha Mann <git@mail.saschamann.eu>
This commit is contained in:
Rik Huijzer
2021-12-27 21:52:42 +01:00
committed by GitHub
parent 8e86b8dd2a
commit 905462d72f
2 changed files with 54 additions and 18 deletions

View File

@@ -11,27 +11,34 @@ on:
- 'action.yml' - 'action.yml'
jobs: jobs:
test-save: generate-key:
runs-on: ubuntu-latest runs-on: ubuntu-latest
outputs: outputs:
cache-name: ${{ steps.name.outputs.cache-name }} cache-name: ${{ steps.name.outputs.cache-name }}
steps: steps:
- uses: actions/checkout@ec3a7ce113134d7a93b817d10a8272cb61118579
- name: Generate random file - name: Generate random file
shell: 'julia --color=yes {0}' shell: 'julia --color=yes {0}'
run: 'write("random.txt", string(rand(10)))' run: 'write("random.txt", string(rand(10)))'
- name: Set cache-name as output
id: name
run: echo "::set-output name=cache-name::$(echo $CACHE_NAME)"
env:
CACHE_NAME: ${{ hashFiles('random.txt') }}
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@ec3a7ce113134d7a93b817d10a8272cb61118579
- name: Save cache - name: Save cache
id: cache id: cache
uses: ./ uses: ./
with: with:
cache-name: ${{ hashFiles('random.txt') }} cache-name: ${{ needs.generate-key.outputs.cache-name }}
- name: Set cache-name as output
id: name
run: |
echo "Setting outputs.cache-name to \"$CACHE_NAME\""
echo "::set-output name=cache-name::$CACHE_NAME"
env:
CACHE_NAME: ${{ hashFiles('random.txt') }}
- name: Check no artifacts dir - name: Check no artifacts dir
shell: 'julia --color=yes {0}' shell: 'julia --color=yes {0}'
run: | run: |
@@ -42,15 +49,19 @@ jobs:
run: 'using Pkg; Pkg.add("pandoc_jll")' run: 'using Pkg; Pkg.add("pandoc_jll")'
test-restore: test-restore:
needs: test-save needs: [generate-key, test-save]
runs-on: ubuntu-latest strategy:
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
fail-fast: false
runs-on: ${{ matrix.os }}
steps: steps:
- uses: actions/checkout@ec3a7ce113134d7a93b817d10a8272cb61118579 - uses: actions/checkout@ec3a7ce113134d7a93b817d10a8272cb61118579
- name: Restore cache - name: Restore cache
id: cache id: cache
uses: ./ uses: ./
with: with:
cache-name: ${{ needs.test-save.outputs.cache-name }} cache-name: ${{ needs.generate-key.outputs.cache-name }}
- name: Test cache-hit output - name: Test cache-hit output
shell: 'julia --color=yes {0}' shell: 'julia --color=yes {0}'
run: | run: |

View File

@@ -1,5 +1,5 @@
name: 'Cache Julia Artifacts' name: 'Cache Julia artifacts, packages and registry'
description: 'Cache Julia artifacts using actions/cache' description: 'Cache Julia using actions/cache'
author: 'Sascha Mann, Rik Huijzer, and contributors' author: 'Sascha Mann, Rik Huijzer, and contributors'
branding: branding:
@@ -9,7 +9,16 @@ branding:
inputs: inputs:
cache-name: cache-name:
description: 'Name used as part of the cache keys' description: 'Name used as part of the cache keys'
default: 'cache-artifacts' default: 'julia-cache'
cache-artifacts:
description: 'Whether to cache artifacts'
default: 'true'
cache-packages:
description: 'Whether to cache packages'
default: 'true'
cache-registry:
description: 'Whether to cache the registry'
default: 'false'
outputs: outputs:
cache-hit: cache-hit:
@@ -19,11 +28,27 @@ outputs:
runs: runs:
using: 'composite' using: 'composite'
steps: steps:
- id: paths
run: |
PATHS=""
[ "$CACHE_ARTIFACTS" = "true" ] && PATHS="${PATHS}~/.julia/artifacts"$'\n'
[ "$CACHE_PACKAGES" = "true" ] && PATHS="${PATHS}~/.julia/packages"$'\n'
[ "$CACHE_REGISTRY" = "true" ] && PATHS="${PATHS}~/.julia/registry"$'\n'
if [ "$PATHS" = "" ]; then
echo "::error title=Invalid inputs::At least one of cache-artifacts, cache-packages or cache-registry has to be true"
exit 1
fi
echo "::set-output name=cache-paths::$PATHS"
env:
CACHE_ARTIFACTS: ${{ inputs.cache-artifacts }}
CACHE_PACKAGES: ${{ inputs.cache-packages }}
CACHE_REGISTRY: ${{ inputs.cache-registry }}
shell: bash
- uses: actions/cache@937d24475381cd9c75ae6db12cb4e79714b926ed - uses: actions/cache@937d24475381cd9c75ae6db12cb4e79714b926ed
id: cache id: cache
with: with:
path: | path: ${{ steps.paths.outputs.cache-paths }}
~/.julia/artifacts
key: ${{ runner.os }}-test-${{ inputs.cache-name }}-${{ hashFiles('**/Project.toml') }} key: ${{ runner.os }}-test-${{ inputs.cache-name }}-${{ hashFiles('**/Project.toml') }}
restore-keys: | restore-keys: |
${{ runner.os }}-test-${{ inputs.cache-name }}- ${{ runner.os }}-test-${{ inputs.cache-name }}-