| 1 |
name: "Clean GH Actions Cache" |
| 2 |
description: "Remove GH Actions cache entries for closed branches." |
| 3 |
|
| 4 |
inputs: |
| 5 |
gh-token: |
| 6 |
description: "GitHub token for API access" |
| 7 |
required: true |
| 8 |
gh-repo: |
| 9 |
description: "GitHub repository in owner/repo format" |
| 10 |
required: true |
| 11 |
branch: |
| 12 |
description: "Target branch" |
| 13 |
required: true |
| 14 |
|
| 15 |
runs: |
| 16 |
using: "composite" |
| 17 |
steps: |
| 18 |
- name: Clean Cache |
| 19 |
shell: bash |
| 20 |
env: |
| 21 |
# https://cli.github.com/manual/gh_help_environment |
| 22 |
GH_TOKEN: ${{ inputs.gh-token }} |
| 23 |
GH_REPO: ${{ inputs.gh-repo }} |
| 24 |
BRANCH: ${{ inputs.branch }} |
| 25 |
run: | |
| 26 |
# Setting this to not fail the workflow while listing/deleting cache entries. |
| 27 |
set +e |
| 28 |
|
| 29 |
# Get cache IDs for target branch |
| 30 |
echo "Fetching list of cache IDs for $BRANCH" |
| 31 |
cacheIDs=$(gh cache list --ref "$BRANCH" --json id --jq '.[].id') |
| 32 |
|
| 33 |
# Delete the cache entries |
| 34 |
if [ -z "$cacheIDs" ]; then |
| 35 |
echo "No cache entries found for $BRANCH" |
| 36 |
else |
| 37 |
echo "Deleting caches..." |
| 38 |
fi |
| 39 |
for cacheID in $cacheIDs |
| 40 |
do |
| 41 |
gh cache delete "$cacheID" |
| 42 |
done |
| 43 |
echo "Done" |