github.com/bananabytelabs/wazero@v0.0.0-20240105073314-54b22a776da8/.github/workflows/clear_cache.yaml (about)

     1  # This job cleans up the unnecessary caches created on PRs.
     2  # https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#force-deleting-cache-entries
     3  name: cleanup caches by a branch
     4  on:
     5    # Only runs on the PRs are closed, regardless of it is merged or not.
     6    # https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#running-your-pull_request-workflow-when-a-pull-request-merges
     7    pull_request:
     8      types:
     9        - closed
    10  
    11  jobs:
    12    cleanup:
    13      runs-on: ubuntu-latest
    14      steps:
    15        - name: Check out code
    16          uses: actions/checkout@v3
    17  
    18        - name: Cleanup
    19          run: |
    20            gh extension install actions/gh-actions-cache
    21  
    22            REPO=${{ github.repository }}
    23            BRANCH="refs/pull/${{ github.event.pull_request.number }}/merge"
    24  
    25            echo "Fetching list of cache key"
    26            cacheKeysForPR=$(gh actions-cache list -R $REPO -B $BRANCH | cut -f 1 )
    27  
    28            ## Setting this to not fail the workflow while deleting cache keys.
    29            set +e
    30            echo "Deleting caches..."
    31            for cacheKey in $cacheKeysForPR
    32            do
    33                gh actions-cache delete $cacheKey -R $REPO -B $BRANCH --confirm
    34            done
    35            echo "Done"
    36          env:
    37            GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}