mirror of
https://github.com/julia-actions/cache.git
synced 2026-02-12 17:36:53 +08:00
* Reproduce add-julia-registry issue * Skip registries restore when already present * Expand ~ * Refactor paths step to use bash array
268 lines
8.7 KiB
YAML
268 lines
8.7 KiB
YAML
name: CI
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
paths:
|
|
- 'action.yml'
|
|
- 'handle_caches.jl'
|
|
- '.github/**'
|
|
pull_request:
|
|
paths:
|
|
- 'action.yml'
|
|
- 'handle_caches.jl'
|
|
- '.github/**'
|
|
|
|
# needed to allow julia-actions/cache to delete old caches that it has created
|
|
permissions:
|
|
actions: write
|
|
contents: read
|
|
|
|
jobs:
|
|
generate-key:
|
|
runs-on: ubuntu-latest
|
|
outputs:
|
|
cache-name: ${{ steps.name.outputs.cache-name }}
|
|
steps:
|
|
- name: Generate random cache-name
|
|
id: name
|
|
run: |
|
|
cache_name=$(head -n 100 </dev/urandom | shasum -a 256 | cut -d ' ' -f 1)
|
|
echo "cache-name=$cache_name" | tee -a "$GITHUB_OUTPUT"
|
|
|
|
test-save:
|
|
needs: generate-key
|
|
strategy:
|
|
matrix:
|
|
nested:
|
|
- name: matrix
|
|
invalid-chars: "," # Use invalid characters in job matrix to ensure we escape them
|
|
version:
|
|
- "1.0"
|
|
- "1"
|
|
- "nightly"
|
|
os:
|
|
- ubuntu-latest
|
|
- windows-latest
|
|
- macOS-latest
|
|
exclude:
|
|
# Test Julia "1.0" on Linux only
|
|
- version: "1.0"
|
|
os: windows-latest
|
|
- version: "1.0"
|
|
os: macOS-latest
|
|
fail-fast: false
|
|
runs-on: ${{ matrix.os }}
|
|
env:
|
|
JULIA_DEPOT_PATH: /tmp/julia-depot
|
|
steps:
|
|
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
|
|
- uses: julia-actions/setup-julia@v1
|
|
with:
|
|
version: ${{ matrix.version }}
|
|
- name: Save cache
|
|
id: cache
|
|
uses: ./
|
|
with:
|
|
cache-name: ${{ needs.generate-key.outputs.cache-name }}-matrix
|
|
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
|
|
- 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:
|
|
needs: [generate-key, test-save]
|
|
strategy:
|
|
matrix:
|
|
nested:
|
|
- name: matrix
|
|
invalid-chars: "," # Use invalid characters in job matrix to ensure we escape them
|
|
version:
|
|
- "1.0"
|
|
- "1"
|
|
- "nightly"
|
|
os:
|
|
- ubuntu-latest
|
|
- windows-latest
|
|
- macOS-latest
|
|
exclude:
|
|
# Test Julia "1.0" on Linux only
|
|
- version: "1.0"
|
|
os: windows-latest
|
|
- version: "1.0"
|
|
os: macOS-latest
|
|
fail-fast: false
|
|
runs-on: ${{ matrix.os }}
|
|
env:
|
|
JULIA_DEPOT_PATH: /tmp/julia-depot
|
|
steps:
|
|
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
|
|
- uses: julia-actions/setup-julia@v1
|
|
with:
|
|
version: ${{ matrix.version }}
|
|
- name: Restore cache
|
|
id: cache
|
|
uses: ./
|
|
with:
|
|
cache-name: ${{ needs.generate-key.outputs.cache-name }}-matrix
|
|
# 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' }}
|
|
- 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 existance or emptiness of affected dirs
|
|
shell: julia --color=yes {0}
|
|
run: |
|
|
# These dirs should exist as they've been cached
|
|
artifacts_dir = joinpath(first(DEPOT_PATH), "artifacts")
|
|
if VERSION >= v"1.3"
|
|
@assert !isempty(readdir(artifacts_dir))
|
|
else
|
|
@assert !isdir(artifacts_dir)
|
|
end
|
|
packages_dir = joinpath(first(DEPOT_PATH), "packages")
|
|
@assert !isempty(readdir(packages_dir))
|
|
compiled_dir = joinpath(first(DEPOT_PATH), "compiled")
|
|
@assert !isempty(readdir(compiled_dir))
|
|
scratchspaces_dir = joinpath(first(DEPOT_PATH), "scratchspaces")
|
|
@assert !isempty(readdir(scratchspaces_dir))
|
|
logs_dir = joinpath(first(DEPOT_PATH), "logs")
|
|
@assert !isempty(readdir(logs_dir))
|
|
|
|
test-restore-nomatrix:
|
|
needs: [generate-key, test-save-nomatrix]
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
|
|
- name: Restore cache
|
|
id: cache
|
|
uses: ./
|
|
with:
|
|
cache-name: ${{ needs.generate-key.outputs.cache-name }}-nomatrix
|
|
# 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' }}
|
|
- 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 existance or emptiness of affected dirs
|
|
shell: julia --color=yes {0}
|
|
run: |
|
|
# These dirs should exist as they've been cached
|
|
artifacts_dir = joinpath(first(DEPOT_PATH), "artifacts")
|
|
if VERSION >= v"1.3"
|
|
@assert !isempty(readdir(artifacts_dir))
|
|
else
|
|
@assert !isdir(artifacts_dir)
|
|
end
|
|
packages_dir = joinpath(first(DEPOT_PATH), "packages")
|
|
@assert !isempty(readdir(packages_dir))
|
|
compiled_dir = joinpath(first(DEPOT_PATH), "compiled")
|
|
@assert !isempty(readdir(compiled_dir))
|
|
scratchspaces_dir = joinpath(first(DEPOT_PATH), "scratchspaces")
|
|
@assert !isempty(readdir(scratchspaces_dir))
|
|
logs_dir = joinpath(first(DEPOT_PATH), "logs")
|
|
@assert !isempty(readdir(logs_dir))
|
|
|
|
test-save-cloned-registry:
|
|
needs: [generate-key]
|
|
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-key.outputs.cache-name }}-${{ github.job }}" >>"$GITHUB_OUTPUT"
|
|
- name: Save cache
|
|
uses: ./
|
|
with:
|
|
cache-name: ${{ steps.cache-name.outputs.cache-name }}
|
|
# 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' }}
|
|
- name: Add General registry clone
|
|
shell: julia --color=yes {0}
|
|
run: |
|
|
using Pkg
|
|
Pkg.Registry.add("General")
|
|
env:
|
|
JULIA_PKG_SERVER: ""
|
|
# Set the registry worktree to an older state to simulate the cache storing an old version of the registry.
|
|
- name: Use outdated General worktree
|
|
run: git -C ~/.julia/registries/General reset --hard HEAD~20
|
|
|
|
test-restore-cloned-registry:
|
|
needs: [test-save-cloned-registry]
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
|
|
- name: Add General registry clone
|
|
shell: julia --color=yes {0}
|
|
run: |
|
|
using Pkg
|
|
Pkg.Registry.add("General")
|
|
env:
|
|
JULIA_PKG_SERVER: ""
|
|
- name: Restore cache
|
|
uses: ./
|
|
with:
|
|
cache-name: ${{ needs.test-save-cloned-registry.outputs.cache-name }}
|
|
# 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' }}
|
|
- name: Test registry is not corrupt
|
|
shell: julia --color=yes {0}
|
|
run: |
|
|
using Pkg
|
|
Pkg.Registry.update()
|