mirror of
https://github.com/netfun2000/hipudding-teslamate.git
synced 2026-02-27 09:44:28 +08:00
50 lines
1.4 KiB
YAML
50 lines
1.4 KiB
YAML
name: Cleanup caches by a branch
|
|
|
|
on:
|
|
pull_request:
|
|
types:
|
|
- closed
|
|
pull_request_target:
|
|
types:
|
|
- closed
|
|
paths:
|
|
- "**/*"
|
|
- "!.github/**" # Important: Exclude PRs related to .github from auto-run
|
|
- "!.github/workflows/**" # Important: Exclude PRs related to .github/workflows from auto-run
|
|
- "!.github/actions/**" # Important: Exclude PRs related to .github/actions from auto-run
|
|
|
|
permissions:
|
|
contents: read
|
|
packages: read
|
|
|
|
jobs:
|
|
check_paths:
|
|
uses: ./.github/workflows/check_paths.yml
|
|
|
|
cleanup:
|
|
name: Delete caches when PR is closed
|
|
needs: check_paths
|
|
if: needs.check_paths.outputs.githubfolder != 'true'
|
|
runs-on: ubuntu-24.04
|
|
|
|
steps:
|
|
- name: Cleanup
|
|
run: |
|
|
gh extension install actions/gh-actions-cache
|
|
|
|
echo "Fetching list of cache key"
|
|
cacheKeysForPR=$(gh actions-cache list -R $REPO -B $BRANCH -L 100 | cut -f 1 )
|
|
|
|
## Setting this to not fail the workflow while deleting cache keys.
|
|
set +e
|
|
echo "Deleting caches..."
|
|
for cacheKey in $cacheKeysForPR
|
|
do
|
|
gh actions-cache delete $cacheKey -R $REPO -B $BRANCH --confirm
|
|
done
|
|
echo "Done"
|
|
env:
|
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
REPO: ${{ github.repository }}
|
|
BRANCH: refs/pull/${{ github.event.pull_request.number }}/merge
|