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

chore: refactor bazel test execution to a GitHub action #72

Merged
merged 16 commits into from
Dec 15, 2023
14 changes: 14 additions & 0 deletions .github/actions/run_bazel_test/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Execute Bazel test
description: Handles platform-specific settings.

inputs:
working-directory:
type: string

runs:
using: composite
steps:
- shell: bash
env:
RBT_WORKING_DIR: ${{ inputs.working-directory }}
run: ${GITHUB_ACTION_PATH}/run_bazel_test.sh
25 changes: 25 additions & 0 deletions .github/actions/run_bazel_test/run_bazel_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env bash

set -o errexit -o nounset -o pipefail

is_windows() {
local os_name
os_name="$( uname )"
# Examples: MINGW64_NT-10.0-17763
[[ "${os_name}" =~ ^MING ]]
}

working_dir="${RBT_WORKING_DIR:-}"

if is_windows; then
export BAZEL_SH='C:\msys64\usr\bin\bash.exe'
bzl_pkgs='///...'
else
bzl_pkgs='//...'
fi

if [[ -n "${working_dir:-}" ]]; then
cd "${working_dir}"
fi

bazel test "${bzl_pkgs}"
35 changes: 9 additions & 26 deletions .github/workflows/workflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
- name: Disable stardoc
# Windows: Stardoc complains about docstring quote indentation on Windows.
# bzlmod: Stardoc does not work with bzlmod.
if: ${{ runner.os == 'Windows' || matrix.bazel_mode == 'module' }}
if: ${{ matrix.os == 'windows-2019' || matrix.bazel_mode == 'module' }}
cgrindel marked this conversation as resolved.
Show resolved Hide resolved
uses: tweag/write-bazelrc@v0
with:
content: build --config=no-stardoc
Expand All @@ -55,34 +55,17 @@ jobs:
if: ${{ matrix.bazel_mode == 'module' }}
with:
content: build --experimental_enable_bzlmod
- name: Run tests (bzlmod)
if: matrix.bazel_mode == 'module'
working-directory: ./tests
run: |
echo "USE_BAZEL_VERSION=${{ matrix.version }}" > .bazeliskrc

if [[ ${{ runner.os }} == Windows ]]; then
# On Windows `//...` expands to `/...`.
BAZEL_SH='C:\msys64\usr\bin\bash.exe' bazel test ///...
else
bazel test //...
fi

- name: Run tests (workspace)
if: matrix.bazel_mode == 'workspace'
- name: Configure the Bazel version
run: |
echo "USE_BAZEL_VERSION=${{ matrix.version }}" > .bazeliskrc
echo "USE_BAZEL_VERSION=${{ matrix.version }}" > tests/.bazeliskrc

if [[ ${{ runner.os }} == Windows ]]; then
# Because of the docstring quote issue on Windows we skip the stardoc test on the main workspace.
# On Windows `//...` expands to `/...`.
cd tests && BAZEL_SH='C:\msys64\usr\bin\bash.exe' bazel test ///...
else
bazel test //...

cd tests && bazel test //...
fi
- name: Run Bazel test at the root
if: ${{ matrix.bazel_mode == 'workspace' && matrix.os != 'windows-2019' }}
uses: ./.github/actions/run_bazel_test
- name: Run Bazel test under the tests directory
uses: ./.github/actions/run_bazel_test
with:
working-directory: tests

all_ci_tests:
runs-on: ubuntu-latest
Expand Down