Skip to content

Regenerate cache

Regenerate cache #75

name: Regenerate cache
on:
schedule:
# Daily
- cron: '23 4 * * *'
jobs:
regenerate-cache:
permissions:
actions: write
runs-on: ubuntu-latest
steps:
- name: Delete prior caches
run: |
gh extension install actions/gh-actions-cache
echo "Fetching prior cache keys"
cacheKeysForPR=$(gh actions-cache list -R $REPO -B $BRANCH -L 100 | cut -f 1 )
## Setting this to not fail the workflow while deleting cache keys.
set +e
echo "Deleting prior caches..."
for cacheKey in $cacheKeysForPR
do
gh actions-cache delete $cacheKey -R $REPO -B $BRANCH --confirm
done
echo "Done"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO: ${{ github.repository }}
BRANCH: ${{ github.ref }}
# Caches and restores the bazelisk download directory, the bazel build directory.
- name: Cache bazel
uses: actions/cache@v4
env:
cache-name: bazel-cache
with:
path: |
~/.cache/bazelisk
~/.cache/bazel
~/.cache/bazel-repo
key: ${{ runner.os }}-${{ env.cache-name }}-${{ github.ref }}-${{ github.sha }}
# Pull caches from:
# - The current sha,
# - The current branch,
# - base branch
restore-keys: |
${{ runner.os }}-${{ env.cache-name }}-${{ github.ref }}-${{ github.sha }}
${{ runner.os }}-${{ env.cache-name }}-${{ github.ref }}-
${{ runner.os }}-${{ env.cache-name }}-refs/heads/${{ github.base_ref }}-
- name: Checkout
uses: actions/checkout@v4
- name: Bazel clean
run: bazel --bazelrc=.github/workflows/ci.bazelrc --bazelrc=.bazelrc clean --expunge
- name: bazel test //...
run: bazel --bazelrc=.github/workflows/ci.bazelrc --bazelrc=.bazelrc test //...