Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: improve CI cache #7

Merged
merged 9 commits into from
Apr 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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