Skip to content

Commit

Permalink
fix: use env, rename variables
Browse files Browse the repository at this point in the history
  • Loading branch information
erikburt committed Nov 13, 2024
1 parent 33801b5 commit 89f4d07
Showing 1 changed file with 21 additions and 23 deletions.
44 changes: 21 additions & 23 deletions .github/workflows/delete-caches.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ jobs:
# See also: https://docs.github.com/en/rest/actions/cache?apiVersion=2022-11-28#delete-a-github-actions-cache-for-a-repository-using-a-cache-id
actions: write
contents: read
env:
REPO: ${{ github.repository }}
PR_NUMBER: ${{ github.event.pull_request.number }}
steps:
- name: Check out code
uses: actions/[email protected]
Expand All @@ -26,40 +29,35 @@ jobs:
- name: Retrieve Trunk SHA
id: get-sha
run: |
REPO=${{ github.repository }}
PR_NUMBER=${{ github.event.pull_request.number }}
SHA=$(gh pr view -R $REPO $PR_NUMBER --json mergeCommit --jq .mergeCommit.oid)
echo "sha=$SHA" >> $GITHUB_OUTPUT
- name: Cleanup Caches
env:
TRUNK_SHA: ${{ steps.get-sha.outputs.sha }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set +e
REPO=${{ github.repository }}
PR_NUMBER=${{ github.event.pull_request.number }}
PR_BRANCH=refs/pull/$PR_NUMBER/merge
echo "Fetching list of cache keys for the PR branch"
cacheKeysForPR=$(gh actions-cache list -R $REPO -B $PR_BRANCH | cut -f 1)
PR_BRANCH=refs/pull/$PR_NUMBER/merge
echo "Fetching list of cache keys for the PR branch ($PR_BRANCH)"
PR_CACHE_KEYS=$(gh actions-cache list -R $REPO -B $PR_BRANCH | cut -f 1)
echo "Deleting caches for PR branch..."
for cacheKey in $cacheKeysForPR; do
gh actions-cache delete $cacheKey -R $REPO -B $PR_BRANCH --confirm
echo "Deleting caches for PR branch ($PR_BRANCH)..."
for CACHE_KEY in $PR_CACHE_KEYS; do
gh actions-cache delete $CACHE_KEY -R $REPO -B $PR_BRANCH --confirm
done
if [[ -n ${{ steps.get-sha.outputs.sha }} ]]; then
echo "Found corresponding merge commit ${{ steps.get-sha.outputs.sha }}"
QUEUE_BRANCH="gh-readonly-queue/develop/pr-${PR_NUMBER}-${{ steps.get-sha.outputs.sha }}"
echo "Fetching list of cache keys for the merge queue branch"
cacheKeysForQueue=$(gh actions-cache list -R $REPO -B $QUEUE_BRANCH | cut -f 1)
echo "Deleting caches for merge queue branch..."
for cacheKey in $cacheKeysForQueue; do
gh actions-cache delete $cacheKey -R $REPO -B $QUEUE_BRANCH --confirm
if [[ -n "$TRUNK_SHA" ]]; then
echo "Found corresponding merge commit $TRUNK_SHA"
QUEUE_BRANCH="gh-readonly-queue/develop/pr-${PR_NUMBER}-${TRUNK_SHA}"
echo "Fetching list of cache keys for the merge queue branch ($QUEUE_BRANCH)"
QUEUE_CACHE_KEYS=$(gh actions-cache list -R $REPO -B $QUEUE_BRANCH | cut -f 1)
echo "Deleting caches for merge queue branch ($QUEUE_BRANCH)..."
for CACHE_KEY in $QUEUE_CACHE_KEYS; do
gh actions-cache delete $CACHE_KEY -R $REPO -B $QUEUE_BRANCH --confirm
done
fi
echo "Done"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 comments on commit 89f4d07

Please sign in to comment.