Skip to content

Commit

Permalink
feat(ci): Bump up the actions/cache to v4, and force overwriting the …
Browse files Browse the repository at this point in the history
…cache (#164)

* feat(ci): Bump up the actions/cache to v4, and force overwriting the cache

The force overwriting implementation comes from https://github.com/actions/cache/blob/a2ed59d39b352305bdd2f628719a53b2cc4f9613/tips-and-workarounds.md?plain=1#L38

* Specify shell
  • Loading branch information
sasa-tomic authored Feb 6, 2024
1 parent 096ed24 commit f204cdc
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,5 @@ jobs:
########################################
- uses: ./.github/workflows/manage-runner-post
name: "🪓 Tear down runner"
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
32 changes: 30 additions & 2 deletions .github/workflows/manage-runner-post/action.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
name: Setup runner
description: Reusable action for tearing down the github runner

inputs:
github_token:
description: 'Automatically assigned GitHub Token'
required: true

runs:
using: composite
steps:
Expand All @@ -18,12 +23,35 @@ runs:
# Cache is saved on main only to avoid cache evictions due to github restrictions:
# https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#restrictions-for-accessing-a-cache
########################################
- name: First delete cache entry if it exists
if: ${{ github.ref == 'refs/heads/main' }}
run: |
set -eExou pipefail
gh extension install actions/gh-actions-cache
REPO=${{ github.repository }}
BRANCH=${{ github.ref }}
echo "Fetching list of cache key"
cacheKeys=$(gh actions-cache list -R $REPO -B $BRANCH | cut -f 1 )
## Setting this to not fail the workflow while deleting cache keys.
echo "Deleting caches..."
for cacheKey in $cacheKeys
do
gh actions-cache delete $cacheKey -R $REPO -B $BRANCH --confirm || true
done
echo "Done"
env:
GH_TOKEN: ${{ inputs.GITHUB_TOKEN }}
shell: bash
- name: "☁️ ⬆️ Saving cache on main only"
if: ${{ github.ref == 'refs/heads/main' }}
uses: actions/cache/save@v3
uses: actions/cache/save@v4
with:
path: "~/.cache/bazel"
# Configure cache updates
# https://github.com/actions/cache/blob/main/tips-and-workarounds.md#update-a-cache
# https://github.com/actions/cache/blob/main/examples.md#---bazel
key: ${{ runner.os }}-bazel-${{ hashFiles('.bazelversion', '.bazelrc', 'WORKSPACE', 'WORKSPACE.bazel', 'MODULE.bazel', 'Cargo.Bazel.lock') }}
key: ${{ runner.os }}-bazel-${{ hashFiles('.bazelversion', '.bazelrc', 'WORKSPACE.bazel', 'Cargo.Bazel.lock', 'requirements.txt') }}
4 changes: 2 additions & 2 deletions .github/workflows/manage-runner-pre/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ runs:
# Download and unpack cache
########################################
- name: "☁️ ⬇️ Restore bazel cache"
uses: actions/cache/restore@v3
uses: actions/cache/restore@v4
with:
path: "~/.cache/bazel"
# Configure cache updates
# https://github.com/actions/cache/blob/main/tips-and-workarounds.md#update-a-cache
# https://github.com/actions/cache/blob/main/examples.md#---bazel
key: ${{ runner.os }}-bazel-${{ hashFiles('.bazelversion', '.bazelrc', 'WORKSPACE', 'WORKSPACE.bazel', 'MODULE.bazel', 'Cargo.Bazel.lock') }}
key: ${{ runner.os }}-bazel-${{ hashFiles('.bazelversion', '.bazelrc', 'WORKSPACE.bazel', 'Cargo.Bazel.lock', 'requirements.txt') }}
restore-keys: |
${{ runner.os }}-bazel-
- name: "🧹 Clean bazel cache if we're preparing a new release"
Expand Down

0 comments on commit f204cdc

Please sign in to comment.