Skip to content

Commit 72c333d

Browse files
authored
Robustify the Cache Cleanup Scripts (#3650)
Make changes to handle the cases where the workflow names contain spaces. Note that none of the workflow names in amrex has spaces.
1 parent 6e8c125 commit 72c333d

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

.github/workflows/cleanup-cache-postpr.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ jobs:
3131
set +e
3232
3333
keys=$(gh actions-cache list -L 100 -R $REPO -B $BRANCH | cut -f 1)
34+
# $keys might contain spaces. Thus we set IFS to \n.
35+
IFS=$'\n'
3436
for k in $keys
3537
do
36-
gh actions-cache delete $k -R $REPO -B $BRANCH --confirm
38+
gh actions-cache delete "$k" -R $REPO -B $BRANCH --confirm
3739
done
40+
unset IFS

.github/workflows/cleanup-cache.yml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
EVENT=${{ github.event.workflow_run.event }}
2828
2929
# Triggering workflow run name (e.g., LinuxClang)
30-
WORKFLOW_NAME=${{ github.event.workflow_run.name }}
30+
WORKFLOW_NAME="${{ github.event.workflow_run.name }}"
3131
3232
if [[ $EVENT == "pull_request" ]]; then
3333
gh run download ${{ github.event.workflow_run.id }} -n pr_number
@@ -45,16 +45,19 @@ jobs:
4545
# The goal is to keep the last used key of each job and delete all others.
4646
4747
# something like ccache-LinuxClang-
48-
keyprefix=ccache-${WORKFLOW_NAME}-
48+
keyprefix="ccache-${WORKFLOW_NAME}-"
4949
50-
cached_jobs=$(gh actions-cache list -L 100 -R $REPO -B $BRANCH --key $keyprefix | awk -F '-git-' '{print $1}' | sort | uniq)
50+
cached_jobs=$(gh actions-cache list -L 100 -R $REPO -B $BRANCH --key "$keyprefix" | awk -F '-git-' '{print $1}' | sort | uniq)
5151
5252
# cached_jobs is something like "ccache-LinuxClang-configure-1d ccache-LinuxClang-configure-2d".
53+
# It might also contain spaces. Thus we set IFS to \n.
54+
IFS=$'\n'
5355
for j in $cached_jobs
5456
do
55-
old_keys=$(gh actions-cache list -L 100 -R $REPO -B $BRANCH --key ${j}-git- --sort last-used | cut -f 1 | tail -n +2)
57+
old_keys=$(gh actions-cache list -L 100 -R $REPO -B $BRANCH --key "${j}-git-" --sort last-used | cut -f 1 | tail -n +2)
5658
for k in $old_keys
5759
do
58-
gh actions-cache delete $k -R $REPO -B $BRANCH --confirm
60+
gh actions-cache delete "$k" -R $REPO -B $BRANCH --confirm
5961
done
6062
done
63+
unset IFS

0 commit comments

Comments
 (0)