mirror of
https://github.com/julia-actions/cache.git
synced 2026-02-12 09:26:53 +08:00
Avoid corrupting existing cloned Julia registries (#102)
* Reproduce add-julia-registry issue * Skip registries restore when already present * Expand ~ * Refactor paths step to use bash array
This commit is contained in:
51
.github/workflows/CI.yml
vendored
51
.github/workflows/CI.yml
vendored
@@ -214,3 +214,54 @@ 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))
|
||||||
|
|
||||||
|
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()
|
||||||
|
|||||||
47
action.yml
47
action.yml
@@ -69,19 +69,32 @@ runs:
|
|||||||
else
|
else
|
||||||
depot="~/.julia"
|
depot="~/.julia"
|
||||||
fi
|
fi
|
||||||
echo "depot=$depot" >> $GITHUB_OUTPUT
|
echo "depot=$depot" | tee -a "$GITHUB_OUTPUT"
|
||||||
[ "${{ inputs.cache-artifacts }}" = "true" ] && A_PATH="${depot}/artifacts"
|
|
||||||
echo "artifacts-path=$A_PATH" >> $GITHUB_OUTPUT
|
cache_paths=()
|
||||||
[ "${{ inputs.cache-packages }}" = "true" ] && P_PATH="${depot}/packages"
|
artifacts_path="${depot}/artifacts"
|
||||||
echo "packages-path=$P_PATH" >> $GITHUB_OUTPUT
|
[ "${{ inputs.cache-artifacts }}" = "true" ] && cache_paths+=("$artifacts_path")
|
||||||
[ "${{ inputs.cache-registries }}" = "true" ] && R_PATH="${depot}/registries"
|
packages_path="${depot}/packages"
|
||||||
echo "registries-path=$R_PATH" >> $GITHUB_OUTPUT
|
[ "${{ inputs.cache-packages }}" = "true" ] && cache_paths+=("$packages_path")
|
||||||
[ "${{ inputs.cache-compiled }}" = "true" ] && PCC_PATH="${depot}/compiled"
|
registries_path="${depot}/registries"
|
||||||
echo "compiled-path=$PCC_PATH" >> $GITHUB_OUTPUT
|
if [ "${{ inputs.cache-registries }}" = "true" ]; then
|
||||||
[ "${{ inputs.cache-scratchspaces }}" = "true" ] && S_PATH="${depot}/scratchspaces"
|
if [ ! -d "${registries_path/#\~/$HOME}" ]; then
|
||||||
echo "scratchspaces-path=$S_PATH" >> $GITHUB_OUTPUT
|
cache_paths+=("$registries_path")
|
||||||
[ "${{ inputs.cache-logs }}" = "true" ] && L_PATH="${depot}/logs"
|
else
|
||||||
echo "logs-path=$L_PATH" >> $GITHUB_OUTPUT
|
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<<EOF"
|
||||||
|
printf "%s\n" "${cache_paths[@]}"
|
||||||
|
echo "EOF"
|
||||||
|
} | tee -a "$GITHUB_OUTPUT"
|
||||||
shell: bash
|
shell: bash
|
||||||
env:
|
env:
|
||||||
PATH_DELIMITER: ${{ runner.OS == 'Windows' && ';' || ':' }}
|
PATH_DELIMITER: ${{ runner.OS == 'Windows' && ';' || ':' }}
|
||||||
@@ -109,13 +122,7 @@ runs:
|
|||||||
id: cache
|
id: cache
|
||||||
with:
|
with:
|
||||||
path: |
|
path: |
|
||||||
${{ steps.paths.outputs.artifacts-path }}
|
${{ steps.paths.outputs.cache-paths }}
|
||||||
${{ steps.paths.outputs.packages-path }}
|
|
||||||
${{ steps.paths.outputs.registries-path }}
|
|
||||||
${{ steps.paths.outputs.scratchspaces-path }}
|
|
||||||
${{ steps.paths.outputs.compiled-path }}
|
|
||||||
${{ steps.paths.outputs.logs-path }}
|
|
||||||
|
|
||||||
key: ${{ steps.keys.outputs.key }}
|
key: ${{ steps.keys.outputs.key }}
|
||||||
restore-keys: ${{ steps.keys.outputs.restore-key }}
|
restore-keys: ${{ steps.keys.outputs.restore-key }}
|
||||||
enableCrossOsArchive: false
|
enableCrossOsArchive: false
|
||||||
|
|||||||
Reference in New Issue
Block a user