-
Notifications
You must be signed in to change notification settings - Fork 33
48 lines (43 loc) · 1.83 KB
/
Cleanup Caches by a branch.yml
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# SPDX-License-Identifier: Apache-2.0
# Licensed to the Ed-Fi Alliance under one or more agreements.
# The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0.
# See the LICENSE and NOTICES files in the project root for more information.
name: Cleanup Caches by a branch
on:
pull_request:
branches: [main, 'b-v*-patch*','feature-*']
types: [ closed ]
permissions: read-all
jobs:
cleanup:
runs-on: ubuntu-24.04
steps:
- name: Check out code
uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4
- name: Cleanup
run: |
gh extension install actions/gh-actions-cache
REPO=${{ github.repository }}
PULLREQUESTBRANCH="refs/pull/${{ github.event.pull_request.number }}/merge"
cacheKeysForPR=$(gh actions-cache list -R $REPO -B $PULLREQUESTBRANCH | cut -f 1 )
## Setting this to not fail the workflow while deleting cache keys.
set +e
echo "Deleting caches for PULLREQUESTBRANCH $PULLREQUESTBRANCH..."
for cacheKey in $cacheKeysForPR
do
gh actions-cache delete $cacheKey -R $REPO -B $PULLREQUESTBRANCH --confirm
done
WORKINGBRANCH=${{ GITHUB.HEAD_REF }}
echo "HEAD_REF: " ${{ GITHUB.HEAD_REF }}
echo "REF_NAME: " ${{ GITHUB.REF_NAME }}
echo "Fetching list of cache key"
cacheKeysForPR=$(gh actions-cache list -R $REPO -B $WORKINGBRANCH | cut -f 1 )
set +e
echo "Deleting caches for WORKINGBRANCH $WORKINGBRANCH..."
for cacheKey in $cacheKeysForPR
do
gh actions-cache delete $cacheKey -R $REPO -B $WORKINGBRANCH --confirm
done
echo "Done"
env:
GH_TOKEN: ${{ secrets.REPO_DISPATCH_TOKEN }}