-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Lexus Drumgold <[email protected]>
- Loading branch information
1 parent
edc7891
commit 12662c0
Showing
1 changed file
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# Cache Cleanup | ||
# | ||
# Delete caches when a pull request is closed or on workflow dispatch. | ||
# | ||
# References: | ||
# | ||
# - https://docs.github.com/actions/learn-github-actions/contexts | ||
# - https://docs.github.com/actions/learn-github-actions/expressions | ||
# - https://docs.github.com/actions/using-workflows/caching-dependencies-to-speed-up-workflows#force-deleting-cache-entries | ||
# - https://docs.github.com/actions/using-workflows/events-that-trigger-workflows#pull_request | ||
# - https://docs.github.com/actions/using-workflows/events-that-trigger-workflows#workflow_dispatch | ||
# - https://docs.github.com/actions/using-workflows/using-github-cli-in-workflows | ||
# - https://docs.github.com/webhooks-and-events/webhooks/webhook-events-and-payloads#pull_request | ||
# - https://docs.github.com/webhooks-and-events/webhooks/webhook-events-and-payloads#workflow_dispatch | ||
# - https://github.com/actions/checkout | ||
# - https://github.com/actions/gh-actions-cache | ||
# - https://github.com/hmarr/debug-action | ||
|
||
--- | ||
name: cache-cleanup | ||
on: | ||
pull_request: | ||
types: | ||
- closed | ||
workflow_dispatch: | ||
inputs: | ||
all: | ||
default: false | ||
description: delete caches without filtering by github.ref | ||
type: boolean | ||
permissions: | ||
actions: write | ||
env: | ||
BRANCH: ${{ github.head_ref || github.ref_name }} | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
concurrency: | ||
cancel-in-progress: true | ||
group: ${{ github.workflow }}-${{ github.ref }} | ||
jobs: | ||
cache-cleanup: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- id: debug | ||
name: Print environment variables and event payload | ||
uses: hmarr/[email protected] | ||
- id: checkout | ||
name: Checkout ${{ github.ref_name }} | ||
uses: actions/[email protected] | ||
with: | ||
persist-credentials: false | ||
ref: ${{ github.ref }} | ||
- id: gh-actions-cache | ||
name: Install actions/gh-actions-cache | ||
run: gh extension install actions/gh-actions-cache | ||
- id: cleanup | ||
name: Delete caches${{ !inputs.all && format(' created by {0}', env.BRANCH) || '' }} | ||
env: | ||
BRANCH_FILTER: ${{ !inputs.all && format('--branch {0}', env.BRANCH) || '' }} | ||
run: | | ||
# prevent workflow failure while deleting cache keys | ||
set +e | ||
# delete all caches or caches created by ${{ env.BRANCH }} | ||
for key in $(gh actions-cache list $BRANCH_FILTER --limit 100 | cut -f 1); do | ||
gh actions-cache delete $key $BRANCH_FILTER --confirm | ||
done |