diff --git a/.bazeliskrc b/.bazeliskrc index 65af518..2a00219 100644 --- a/.bazeliskrc +++ b/.bazeliskrc @@ -1,2 +1 @@ -BAZELISK_HOME=.cache/bazelisk USE_BAZEL_VERSION=7.1.1 diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index 4ddd675..1ec422b 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -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 @@ -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 }} diff --git a/.gitignore b/.gitignore index 699707c..679186e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ # Bazel /bazel-* MODULE.bazel.lock + +# For CI +/.bazelisk-bin diff --git a/execute_tests.bash b/execute_tests.bash index 2960e01..c63c3e5 100755 --- a/execute_tests.bash +++ b/execute_tests.bash @@ -9,6 +9,7 @@ BAZEL_EXECUTABLE=( "env" "-i" BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1 + BAZELISK_HOME=.cache/bazelisk "HOME=${HOME}" "PATH=${PATH}" bazelisk