Skip to content

Commit

Permalink
Robustify the Cache Cleanup Scripts (AMReX-Codes#3650)
Browse files Browse the repository at this point in the history
Make changes to handle the cases where the workflow names contain
spaces. Note that none of the workflow names in amrex has spaces.
  • Loading branch information
WeiqunZhang authored and guj committed Dec 13, 2023
1 parent 1b20800 commit c06a325
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/cleanup-cache-postpr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ jobs:
set +e
keys=$(gh actions-cache list -L 100 -R $REPO -B $BRANCH | cut -f 1)
# $keys might contain spaces. Thus we set IFS to \n.
IFS=$'\n'
for k in $keys
do
gh actions-cache delete $k -R $REPO -B $BRANCH --confirm
gh actions-cache delete "$k" -R $REPO -B $BRANCH --confirm
done
unset IFS
13 changes: 8 additions & 5 deletions .github/workflows/cleanup-cache.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
EVENT=${{ github.event.workflow_run.event }}
# Triggering workflow run name (e.g., LinuxClang)
WORKFLOW_NAME=${{ github.event.workflow_run.name }}
WORKFLOW_NAME="${{ github.event.workflow_run.name }}"
if [[ $EVENT == "pull_request" ]]; then
gh run download ${{ github.event.workflow_run.id }} -n pr_number
Expand All @@ -45,16 +45,19 @@ jobs:
# The goal is to keep the last used key of each job and delete all others.
# something like ccache-LinuxClang-
keyprefix=ccache-${WORKFLOW_NAME}-
keyprefix="ccache-${WORKFLOW_NAME}-"
cached_jobs=$(gh actions-cache list -L 100 -R $REPO -B $BRANCH --key $keyprefix | awk -F '-git-' '{print $1}' | sort | uniq)
cached_jobs=$(gh actions-cache list -L 100 -R $REPO -B $BRANCH --key "$keyprefix" | awk -F '-git-' '{print $1}' | sort | uniq)
# cached_jobs is something like "ccache-LinuxClang-configure-1d ccache-LinuxClang-configure-2d".
# It might also contain spaces. Thus we set IFS to \n.
IFS=$'\n'
for j in $cached_jobs
do
old_keys=$(gh actions-cache list -L 100 -R $REPO -B $BRANCH --key ${j}-git- --sort last-used | cut -f 1 | tail -n +2)
old_keys=$(gh actions-cache list -L 100 -R $REPO -B $BRANCH --key "${j}-git-" --sort last-used | cut -f 1 | tail -n +2)
for k in $old_keys
do
gh actions-cache delete $k -R $REPO -B $BRANCH --confirm
gh actions-cache delete "$k" -R $REPO -B $BRANCH --confirm
done
done
unset IFS

0 comments on commit c06a325

Please sign in to comment.