Skip to content

ci: Harden release workflow handling #78059

ci: Harden release workflow handling

ci: Harden release workflow handling #78059

Workflow file for this run

name: Cleanup branch caches
on:
pull_request:
types: [opened, closed, reopened, synchronize]
push:
workflow_dispatch:
workflow_call:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions:
actions: write
jobs:
cleanup:
runs-on: ubuntu-latest
timeout-minutes: 30
if: ${{ github.ref != 'refs/heads/main' }}
steps:
- name: Cleanup
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
REPO=${{ github.repository }}
BRANCH=${{ github.ref }}
echo "Fetching cache ids for ${BRANCH}"
cacheIdsForBranch=$(gh api --method GET "repos/${REPO}/actions/caches" \
-f ref="${BRANCH}" \
-f per_page=100 \
--jq '.actions_caches[].id')
# Cache deletion is best-effort so cleanup failures do not fail CI.
set +e
echo "Deleting caches..."
for cacheId in $cacheIdsForBranch
do
gh api --method DELETE "repos/${REPO}/actions/caches/${cacheId}"
done
echo "Done"