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 = 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))