From e0c48185d605b1ee4379585ebece9b673f6a3ebb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Michaj=C5=82ow?= Date: Sun, 19 May 2024 14:20:29 +0200 Subject: [PATCH] fuck_this_shit --- .github/workflows/cleanup_caches.yml | 37 +++++++++++++++++++++++++ .github/workflows/cleanup_caches_pr.yml | 22 +++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 .github/workflows/cleanup_caches.yml create mode 100644 .github/workflows/cleanup_caches_pr.yml diff --git a/.github/workflows/cleanup_caches.yml b/.github/workflows/cleanup_caches.yml new file mode 100644 index 0000000000000..912b895db07af --- /dev/null +++ b/.github/workflows/cleanup_caches.yml @@ -0,0 +1,37 @@ +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/(?[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 + done + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/cleanup_caches_pr.yml b/.github/workflows/cleanup_caches_pr.yml new file mode 100644 index 0000000000000..1c630f3530ae3 --- /dev/null +++ b/.github/workflows/cleanup_caches_pr.yml @@ -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