diff --git a/.github/actions/run_bazel_test/action.yaml b/.github/actions/run_bazel_test/action.yaml new file mode 100644 index 0000000..5da088e --- /dev/null +++ b/.github/actions/run_bazel_test/action.yaml @@ -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 diff --git a/.github/actions/run_bazel_test/run_bazel_test.sh b/.github/actions/run_bazel_test/run_bazel_test.sh new file mode 100755 index 0000000..9ced3d3 --- /dev/null +++ b/.github/actions/run_bazel_test/run_bazel_test.sh @@ -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}" diff --git a/.github/workflows/workflow.yaml b/.github/workflows/workflow.yaml index 49d6556..e16e2cd 100644 --- a/.github/workflows/workflow.yaml +++ b/.github/workflows/workflow.yaml @@ -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' }} uses: tweag/write-bazelrc@v0 with: content: build --config=no-stardoc @@ -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