diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index b20426f..d2ffe31 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -214,3 +214,54 @@ jobs: 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() diff --git a/action.yml b/action.yml index f64c579..c4b081f 100644 --- a/action.yml +++ b/action.yml @@ -69,19 +69,32 @@ runs: else depot="~/.julia" fi - echo "depot=$depot" >> $GITHUB_OUTPUT - [ "${{ inputs.cache-artifacts }}" = "true" ] && A_PATH="${depot}/artifacts" - echo "artifacts-path=$A_PATH" >> $GITHUB_OUTPUT - [ "${{ inputs.cache-packages }}" = "true" ] && P_PATH="${depot}/packages" - echo "packages-path=$P_PATH" >> $GITHUB_OUTPUT - [ "${{ inputs.cache-registries }}" = "true" ] && R_PATH="${depot}/registries" - echo "registries-path=$R_PATH" >> $GITHUB_OUTPUT - [ "${{ inputs.cache-compiled }}" = "true" ] && PCC_PATH="${depot}/compiled" - echo "compiled-path=$PCC_PATH" >> $GITHUB_OUTPUT - [ "${{ inputs.cache-scratchspaces }}" = "true" ] && S_PATH="${depot}/scratchspaces" - echo "scratchspaces-path=$S_PATH" >> $GITHUB_OUTPUT - [ "${{ inputs.cache-logs }}" = "true" ] && L_PATH="${depot}/logs" - echo "logs-path=$L_PATH" >> $GITHUB_OUTPUT + echo "depot=$depot" | tee -a "$GITHUB_OUTPUT" + + cache_paths=() + artifacts_path="${depot}/artifacts" + [ "${{ inputs.cache-artifacts }}" = "true" ] && cache_paths+=("$artifacts_path") + packages_path="${depot}/packages" + [ "${{ inputs.cache-packages }}" = "true" ] && cache_paths+=("$packages_path") + registries_path="${depot}/registries" + if [ "${{ inputs.cache-registries }}" = "true" ]; then + if [ ! -d "${registries_path/#\~/$HOME}" ]; then + cache_paths+=("$registries_path") + 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." + fi + fi + compiled_path="${depot}/compiled" + [ "${{ inputs.cache-compiled }}" = "true" ] && cache_paths+=("$compiled_path") + scratchspaces_path="${depot}/scratchspaces" + [ "${{ inputs.cache-scratchspaces }}" = "true" ] && cache_paths+=("$scratchspaces_path") + logs_path="${depot}/logs" + [ "${{ inputs.cache-logs }}" = "true" ] && cache_paths+=("$logs_path") + { + echo "cache-paths<