mirror of
https://github.com/julia-actions/cache.git
synced 2026-02-12 01:16:54 +08:00
Pass cache-name between save/restore jobs (#103)
* Pass cache-name between save/restore * Use save job name in cache-name * Re-order test jobs * Fix typo in registry warning
This commit is contained in:
103
.github/workflows/CI.yml
vendored
103
.github/workflows/CI.yml
vendored
@@ -20,19 +20,22 @@ permissions:
|
|||||||
contents: read
|
contents: read
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
generate-key:
|
generate-prefix:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
outputs:
|
outputs:
|
||||||
cache-name: ${{ steps.name.outputs.cache-name }}
|
cache-prefix: ${{ steps.name.outputs.cache-prefix }}
|
||||||
steps:
|
steps:
|
||||||
- name: Generate random cache-name
|
- name: Generate random cache-prefix
|
||||||
id: name
|
id: name
|
||||||
run: |
|
run: |
|
||||||
cache_name=$(head -n 100 </dev/urandom | shasum -a 256 | cut -d ' ' -f 1)
|
cache_prefix=$(head -n 100 </dev/urandom | shasum -a 256 | cut -d ' ' -f 1)
|
||||||
echo "cache-name=$cache_name" | tee -a "$GITHUB_OUTPUT"
|
echo "cache-prefix=$cache_prefix" >>"$GITHUB_OUTPUT"
|
||||||
|
|
||||||
test-save:
|
test-save:
|
||||||
needs: generate-key
|
needs: generate-prefix
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
outputs:
|
||||||
|
cache-name: ${{ steps.cache-name.outputs.cache-name }}
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
nested:
|
nested:
|
||||||
@@ -53,11 +56,15 @@ jobs:
|
|||||||
- version: "1.0"
|
- version: "1.0"
|
||||||
os: macOS-latest
|
os: macOS-latest
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
runs-on: ${{ matrix.os }}
|
|
||||||
env:
|
env:
|
||||||
JULIA_DEPOT_PATH: /tmp/julia-depot
|
JULIA_DEPOT_PATH: /tmp/julia-depot
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
|
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
|
||||||
|
- name: Set cache-name
|
||||||
|
id: cache-name
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
echo "cache-name=${{ needs.generate-prefix.outputs.cache-prefix }}-${{ github.job }}" >>"$GITHUB_OUTPUT"
|
||||||
- uses: julia-actions/setup-julia@v1
|
- uses: julia-actions/setup-julia@v1
|
||||||
with:
|
with:
|
||||||
version: ${{ matrix.version }}
|
version: ${{ matrix.version }}
|
||||||
@@ -65,36 +72,7 @@ jobs:
|
|||||||
id: cache
|
id: cache
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
cache-name: ${{ needs.generate-key.outputs.cache-name }}-matrix
|
cache-name: ${{ steps.cache-name.outputs.cache-name }}
|
||||||
delete-old-caches: required
|
|
||||||
- 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
|
|
||||||
if VERSION >= v"1.3"
|
|
||||||
Pkg.add(PackageSpec(name="pandoc_jll", version="3"))
|
|
||||||
else
|
|
||||||
Pkg.add(PackageSpec(name="Scratch", version="1"))
|
|
||||||
using Scratch
|
|
||||||
get_scratch!("test")
|
|
||||||
end
|
|
||||||
|
|
||||||
# Do tests with no matrix also given the matrix is auto-included in cache key
|
|
||||||
test-save-nomatrix:
|
|
||||||
needs: generate-key
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
|
|
||||||
- name: Save cache
|
|
||||||
id: cache
|
|
||||||
uses: ./
|
|
||||||
with:
|
|
||||||
cache-name: ${{ needs.generate-key.outputs.cache-name }}-nomatrix
|
|
||||||
delete-old-caches: required
|
delete-old-caches: required
|
||||||
- name: Check no artifacts dir
|
- name: Check no artifacts dir
|
||||||
shell: julia --color=yes {0}
|
shell: julia --color=yes {0}
|
||||||
@@ -114,7 +92,8 @@ jobs:
|
|||||||
end
|
end
|
||||||
|
|
||||||
test-restore:
|
test-restore:
|
||||||
needs: [generate-key, test-save]
|
needs: test-save
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
nested:
|
nested:
|
||||||
@@ -135,7 +114,6 @@ jobs:
|
|||||||
- version: "1.0"
|
- version: "1.0"
|
||||||
os: macOS-latest
|
os: macOS-latest
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
runs-on: ${{ matrix.os }}
|
|
||||||
env:
|
env:
|
||||||
JULIA_DEPOT_PATH: /tmp/julia-depot
|
JULIA_DEPOT_PATH: /tmp/julia-depot
|
||||||
steps:
|
steps:
|
||||||
@@ -147,7 +125,7 @@ jobs:
|
|||||||
id: cache
|
id: cache
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
cache-name: ${{ needs.generate-key.outputs.cache-name }}-matrix
|
cache-name: ${{ needs.test-save.outputs.cache-name }}
|
||||||
# Cannot require a successful cache delete on forked PRs as the permissions for actions is limited to read
|
# Cannot require a successful cache delete on forked PRs as the permissions for actions is limited to read
|
||||||
delete-old-caches: ${{ github.event.pull_request.head.repo.fork && 'false' || 'required' }}
|
delete-old-caches: ${{ github.event.pull_request.head.repo.fork && 'false' || 'required' }}
|
||||||
- name: Test cache-hit output
|
- name: Test cache-hit output
|
||||||
@@ -176,8 +154,43 @@ jobs:
|
|||||||
logs_dir = joinpath(first(DEPOT_PATH), "logs")
|
logs_dir = joinpath(first(DEPOT_PATH), "logs")
|
||||||
@assert !isempty(readdir(logs_dir))
|
@assert !isempty(readdir(logs_dir))
|
||||||
|
|
||||||
|
# Do tests with no matrix also given the matrix is auto-included in cache key
|
||||||
|
test-save-nomatrix:
|
||||||
|
needs: generate-prefix
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
outputs:
|
||||||
|
cache-name: ${{ steps.cache-name.outputs.cache-name }}
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
|
||||||
|
- name: Set cache-name
|
||||||
|
id: cache-name
|
||||||
|
run: |
|
||||||
|
echo "cache-name=${{ needs.generate-prefix.outputs.cache-prefix }}-${{ github.job }}" >>"$GITHUB_OUTPUT"
|
||||||
|
- name: Save cache
|
||||||
|
id: cache
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
cache-name: ${{ steps.cache-name.outputs.cache-name }}
|
||||||
|
delete-old-caches: required
|
||||||
|
- 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
|
||||||
|
if VERSION >= v"1.3"
|
||||||
|
Pkg.add(PackageSpec(name="pandoc_jll", version="3"))
|
||||||
|
else
|
||||||
|
Pkg.add(PackageSpec(name="Scratch", version="1"))
|
||||||
|
using Scratch
|
||||||
|
get_scratch!("test")
|
||||||
|
end
|
||||||
|
|
||||||
test-restore-nomatrix:
|
test-restore-nomatrix:
|
||||||
needs: [generate-key, test-save-nomatrix]
|
needs: test-save-nomatrix
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
|
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
|
||||||
@@ -185,7 +198,7 @@ jobs:
|
|||||||
id: cache
|
id: cache
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
cache-name: ${{ needs.generate-key.outputs.cache-name }}-nomatrix
|
cache-name: ${{ needs.test-save-nomatrix.outputs.cache-name }}
|
||||||
# Cannot require a successful cache delete on forked PRs as the permissions for actions is limited to read
|
# Cannot require a successful cache delete on forked PRs as the permissions for actions is limited to read
|
||||||
delete-old-caches: ${{ github.event.pull_request.head.repo.fork && 'false' || 'required' }}
|
delete-old-caches: ${{ github.event.pull_request.head.repo.fork && 'false' || 'required' }}
|
||||||
- name: Test cache-hit output
|
- name: Test cache-hit output
|
||||||
@@ -215,7 +228,7 @@ jobs:
|
|||||||
@assert !isempty(readdir(logs_dir))
|
@assert !isempty(readdir(logs_dir))
|
||||||
|
|
||||||
test-save-cloned-registry:
|
test-save-cloned-registry:
|
||||||
needs: [generate-key]
|
needs: generate-prefix
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
outputs:
|
outputs:
|
||||||
cache-name: ${{ steps.cache-name.outputs.cache-name }}
|
cache-name: ${{ steps.cache-name.outputs.cache-name }}
|
||||||
@@ -224,7 +237,7 @@ jobs:
|
|||||||
- name: Set cache-name
|
- name: Set cache-name
|
||||||
id: cache-name
|
id: cache-name
|
||||||
run: |
|
run: |
|
||||||
echo "cache-name=${{ needs.generate-key.outputs.cache-name }}-${{ github.job }}" >>"$GITHUB_OUTPUT"
|
echo "cache-name=${{ needs.generate-prefix.outputs.cache-prefix }}-${{ github.job }}" >>"$GITHUB_OUTPUT"
|
||||||
- name: Save cache
|
- name: Save cache
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
@@ -243,7 +256,7 @@ jobs:
|
|||||||
run: git -C ~/.julia/registries/General reset --hard HEAD~20
|
run: git -C ~/.julia/registries/General reset --hard HEAD~20
|
||||||
|
|
||||||
test-restore-cloned-registry:
|
test-restore-cloned-registry:
|
||||||
needs: [test-save-cloned-registry]
|
needs: test-save-cloned-registry
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
|
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ runs:
|
|||||||
if [ ! -d "${registries_path/#\~/$HOME}" ]; then
|
if [ ! -d "${registries_path/#\~/$HOME}" ]; then
|
||||||
cache_paths+=("$registries_path")
|
cache_paths+=("$registries_path")
|
||||||
else
|
else
|
||||||
echo "::warning::Julia depot registries already exist. Skipping restoring of cached registries to avoid potential merge conflicts when updating. Please ensure that \`julia-actions/cache\` preceeds any workflow steps which add registries."
|
echo "::warning::Julia depot registries already exist. Skipping restoring of cached registries to avoid potential merge conflicts when updating. Please ensure that \`julia-actions/cache\` precedes any workflow steps which add registries."
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
compiled_path="${depot}/compiled"
|
compiled_path="${depot}/compiled"
|
||||||
|
|||||||
Reference in New Issue
Block a user