Skip to content

Commit

Permalink
fuck_this_shit
Browse files Browse the repository at this point in the history
  • Loading branch information
kasper93 committed May 19, 2024
1 parent 2c68e6c commit fc69cdc
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/cleanup_caches.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Cleanup caches

on:
workflow_run:
workflows: [build]
types: [completed]

jobs:
cache:
runs-on: ubuntu-latest
steps:
- run: |
caches=$(gh cache list -R ${{ github.repository }} -L 100 --json id,key,ref -S last_accessed_at -O desc)
echo "$caches" | jq -c '
map(select(.key | startswith("x86_64-w64-mingw32-") or
startswith("i686-w64-mingw32-") or
startswith("x86_64-windows-msvc-"))) |
group_by(.ref) |
map({
ref: .[0].ref,
caches: map(.key)
}) |
.[]
' | while read -r group; do
pr=$(echo "$group" | jq -r '.ref | capture("refs/pull/(?<num>[0-9]+)/merge").num')
if [[ -n "$pr" ]] && [ "$(gh pr view -R ${{ github.repository }} $pr --json state --jq '.state')" == "OPEN" ]; then
keys=$(echo "$group" | jq -c '.caches[1:]')
else
keys=$(echo "$group" | jq -c '.caches')
fi
echo "$keys" | jq -r '.[]' | while read -r key; do
gh cache delete "$key" -R ${{ github.repository }}
done
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
22 changes: 22 additions & 0 deletions .github/workflows/cleanup_caches_pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Cleanup caches PR

on:
pull_request_target:
types: closed

jobs:
pr_cache:
runs-on: ubuntu-latest
steps:
- run: |
gh extension install actions/gh-actions-cache
set +e
keys=$(gh actions-cache list -R ${{ github.repository }} -B $BRANCH | cut -f 1)
set +e
for key in $keys
do
gh actions-cache delete $key -R ${{ github.repository }} -B $BRANCH --confirm
done
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BRANCH: refs/pull/${{ github.event.pull_request.number }}/merge

0 comments on commit fc69cdc

Please sign in to comment.