Compare commits

...

3 Commits

Author SHA1 Message Date
Deepak Dahiya
a90fbffdad minor 2022-11-14 05:55:57 +00:00
Deepak Dahiya
b65f98495c minor 2022-11-13 21:44:53 +00:00
Deepak Dahiya
e1165c0dec Readmee update for deleting caches 2022-11-13 21:40:58 +00:00

View File

@@ -230,6 +230,43 @@ jobs:
```
</details>
## Deleting caches
We can not re-use caches from pull request branches in other branches like main, such caches can eat up the storage quota and hence causing thrashing on more useful branches like main. In order to resolve this issue, we can use [gh-actions-cache cli](https://github.com/actions/gh-actions-cache/) to delete caches. This workflow uses `gh-actions-cache` to delete all the caches created by all the pull requests.
```
name: cleanup-caches
on:
workflow_dispatch
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v3
- name: Cleanup
run: |
gh extension install actions/gh-actions-cache
REPO=${{ github.repository }}
echo "Fetching list of cache key"
## This will extract out all the cache keys for pull requests
cacheKeysForPR=$(gh actions-cache list -R $REPO | grep "refs/pull" | cut -d $'\t' -f 1 )
## Setting this to not fail the workflow while deleting duplicate cache keys. We can have same cache key for multiple branches based on the cache key generation.
set +e
echo "Deleting caches..."
for cacheKey in $cacheKeysForPR
do
gh actions-cache delete $cacheKey -R $REPO --confirm
done
echo "Done"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
```
## Known practices and workarounds
Following are some of the known practices/workarounds which community has used to fulfill specific requirements. You may choose to use them if suits your use case. Note these are not necessarily the only or the recommended solution.