Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cleanup_caches.yml « workflows « .github - github.com/MHSanaei/3x-ui.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b7d8fc1a4100534127e47e3e98d7b1430fc31dc1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
name: Cleanup Caches
on:
  schedule:
    - cron: "0 3 * * *" # every day
  workflow_dispatch:

jobs:
  cleanup:
    runs-on: ubuntu-latest
    permissions:
      actions: write
    steps:
      - name: Delete caches older than 1 day
        env:
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: |
          CUTOFF_DATE=$(date -d "1 days ago" -Ins --utc | sed 's/+0000/Z/')
          echo "Deleting caches older than: $CUTOFF_DATE"

          CACHE_IDS=$(gh api --paginate repos/${{ github.repository }}/actions/caches \
            --jq ".actions_caches[] | select(.last_accessed_at < \"$CUTOFF_DATE\") | .id" 2>/dev/null)

          if [ -z "$CACHE_IDS" ]; then
            echo "No old caches found to delete."
          else
            echo "$CACHE_IDS" | while read CACHE_ID; do
              echo "Deleting cache: $CACHE_ID"
              gh api -X DELETE repos/${{ github.repository }}/actions/caches/$CACHE_ID
            done
            echo "Old caches deleted successfully."
          fi