Skip to content

Commit

Permalink
fix: improve CI cache (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyawk authored Apr 7, 2024
1 parent e0d8c82 commit d2d0430
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 7 deletions.
1 change: 0 additions & 1 deletion .bazeliskrc
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
BAZELISK_HOME=.cache/bazelisk
USE_BAZEL_VERSION=7.1.1
48 changes: 42 additions & 6 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
# Location to store the bazelisk executable
BAZELISK_BIN_DIR: .bazelisk-bin
# Version of the bazelisk to use
BAZELISK_VERSION: v1.19.0/bazelisk-linux-amd64

jobs:
unit-tests:
runs-on: ubuntu-22.04
Expand All @@ -18,12 +24,42 @@ jobs:
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
- name: Install bazelisk
- name: Get build cache key
id: build-cache-key
run: |
echo "key=${{ runner.os }}-build-${{ hashFiles('**') }}" \
>> "${GITHUB_OUTPUT}"
- name: Try to restore build cache
uses: actions/cache/restore@v4
with:
path: .cache
key: ${{ steps.build-cache-key.outputs.key }}
restore-keys: ${{ runner.os }}-build-
- name: Try to restore bazelisk binary
id: cache-bazelisk-bin
uses: actions/cache/restore@v4
with:
path: ${{ env.BAZELISK_BIN_DIR }}
key: ${{ env.BAZELISK_VERSION }}-bazelisk-bin
- name: Install bazelisk if it's needed
if: steps.cache-bazelisk-bin.outputs.cache-hit != 'true'
run: |
bazelisk_dir="$(realpath "$(mktemp -d -p .)")"
wget https://github.com/bazelbuild/bazelisk/releases/download/v1.19.0/bazelisk-linux-amd64 \
-O "${bazelisk_dir}/bazelisk"
chmod +x "${bazelisk_dir}/bazelisk"
echo "${bazelisk_dir}" >> "${GITHUB_PATH}"
mkdir -p ${{ env.BAZELISK_BIN_DIR }}
wget https://github.com/bazelbuild/bazelisk/releases/download/${{ env.BAZELISK_VERSION }} \
-O "${{ env.BAZELISK_BIN_DIR }}/bazelisk"
chmod +x "${{ env.BAZELISK_BIN_DIR }}/bazelisk"
- name: Save bazelisk binary
uses: actions/cache/save@v4
if: steps.cache-bazelisk-bin.outputs.cache-hit != 'true'
with:
path: ${{ env.BAZELISK_BIN_DIR }}
key: ${{ env.BAZELISK_VERSION }}-bazelisk-bin
- name: Add bazelisk to PATH
run: echo "${{ env.BAZELISK_BIN_DIR }}" >> "${GITHUB_PATH}"
- name: Run unit tests
run: ./execute_tests.bash
- name: Save build cache
uses: actions/cache/save@v4
with:
path: .cache
key: ${{ steps.build-cache-key.outputs.key }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Bazel
/bazel-*
MODULE.bazel.lock

# For CI
/.bazelisk-bin
1 change: 1 addition & 0 deletions execute_tests.bash
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ BAZEL_EXECUTABLE=(
"env"
"-i"
BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1
BAZELISK_HOME=.cache/bazelisk
"HOME=${HOME}"
"PATH=${PATH}"
bazelisk
Expand Down

0 comments on commit d2d0430

Please sign in to comment.