diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..b2a82a5 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,30 @@ +name: Tests + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + test: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [macos-latest, ubuntu-latest] + steps: + - name: Check out repo + uses: actions/checkout@v2 + + - name: Setup R + uses: r-lib/actions/setup-r@v1 + + - name: Install additional packages + if: matrix.os == 'ubuntu-latest' + run: sudo apt-get install libcurl4-openssl-dev + + - name: Run tests + env: + BAZELISK_GITHUB_TOKEN: ${{ secrets.BAZELISK_GITHUB_TOKEN }} + run: tests/run_tests.sh diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 2fdf97a..0000000 --- a/.travis.yml +++ /dev/null @@ -1,36 +0,0 @@ -sudo: false # Not needing sudo enables container builds. - -os: - - linux - - osx - -osx_image: xcode9.3 - -addons: - apt: - sources: - - sourceline: 'deb [arch=amd64] http://storage.googleapis.com/bazel-apt stable jdk1.8' - key_url: 'https://bazel.build/bazel-release.pub.gpg' - - sourceline: 'ppa:marutter/rrutter3.5' - packages: - - bazel - - r-recommended - - texinfo - -before_install: - # brew r does not quite work. - # Track R version on macOS to be the same major version as from apt. - # When updating major version, also update CRAN package versions for compatibility. - # Also, try to upgrade python to python3. - - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then - wget https://cloud.r-project.org/bin/macosx/R-3.6.0.pkg -O /tmp/R.pkg && - sudo installer -pkg "/tmp/R.pkg" -target / && - rm "/tmp/R.pkg" && - ( brew upgrade python || true ) && - brew tap bazelbuild/tap && - brew install bazelbuild/tap/bazel && - brew install texinfo; - fi - -script: - - tests/run_tests.sh diff --git a/tests/coverage/coverage_test.sh b/tests/coverage/coverage_test.sh index fe18f5b..da6f983 100755 --- a/tests/coverage/coverage_test.sh +++ b/tests/coverage/coverage_test.sh @@ -17,8 +17,10 @@ set -euo pipefail cd "$(dirname "${BASH_SOURCE[0]}")" -if ! [[ "${BAZEL_TEST_OPTS[*]:+${BAZEL_TEST_OPTS[*]}}" ]]; then - BAZEL_TEST_OPTS=("--test_output=errors") +source "../setup-bazel.sh" + +if ! [[ "${bazel_test_opts[*]:+${bazel_test_opts[*]}}" ]]; then + bazel_test_opts=("--test_output=errors") fi # LLVM and gcc deal with code coverage differently: @@ -28,12 +30,15 @@ fi # # - With gcc, the function header and the first statement count as separate # hits, unless they are on the same line. +version_info="$($(R CMD config CC) --version)" +echo "Checking coverage results with the following system compiler:" +echo "${version_info}" suffix="_clang" -if [[ $(R CMD config CC) == "gcc"* ]]; then +if [[ "${version_info}" == "gcc"* ]]; then suffix="_gcc" fi -coverage_file="$(bazel info bazel-testlogs)/exampleC/test/coverage.dat" +coverage_file="$("${bazel}" info bazel-testlogs)/exampleC/test/coverage.dat" readonly coverage_file expect_equal() { @@ -52,13 +57,13 @@ expect_equal() { } # For instrumentation of dependencies in the same package. -bazel coverage "${BAZEL_TEST_OPTS[@]}" --instrumentation_filter=exampleC //exampleC:test +"${bazel}" coverage "${bazel_test_opts[@]}" --instrumentation_filter=exampleC //exampleC:test expect_equal "default_instrumented${suffix}.xml" "${coverage_file}" # For instrumentation of packages without tests, and of indirect test dependencies. -bazel coverage "${BAZEL_TEST_OPTS[@]}" --instrumentation_filter=// //... +"${bazel}" coverage "${bazel_test_opts[@]}" --instrumentation_filter=// //... expect_equal "workspace_instrumented${suffix}.xml" "${coverage_file}" # Set instrumentation filter to everything. # Packages tagged external-r-repo are never instrumented in rules_r; so we should not fail here. -bazel coverage "${BAZEL_TEST_OPTS[@]}" --instrumentation_filter='.' --test_output=summary //... +"${bazel}" coverage "${bazel_test_opts[@]}" --instrumentation_filter='.' --test_output=summary //... diff --git a/tests/repro/repro_test.sh b/tests/repro/repro_test.sh index dfe793a..57ca4aa 100755 --- a/tests/repro/repro_test.sh +++ b/tests/repro/repro_test.sh @@ -17,9 +17,11 @@ set -euo pipefail cd "$(dirname "${BASH_SOURCE[0]}")" +source "../setup-bazel.sh" + # Clean up bazel-* symlinks in workspace root to not confuse bazel when running # with a different output_path. -rm "$(bazel info workspace)/bazel-*" 2>/dev/null || true +rm "$("${bazel}" info workspace)/bazel-*" 2>/dev/null || true tmpdir="$(mktemp -d)" readonly tmpdir @@ -28,16 +30,16 @@ readonly second="${tmpdir}/second" run_bazel() { base="$1" - bazel --bazelrc=/dev/null --output_base="${base}" build //exampleC - bazel --bazelrc=/dev/null --output_base="${base}" info bazel-bin + "${bazel}" --bazelrc=/dev/null --output_base="${base}" build //exampleC + "${bazel}" --bazelrc=/dev/null --output_base="${base}" info bazel-bin } first_output="$(run_bazel "${first}")" second_output="$(run_bazel "${second}")" shutdown_bazel() { base="$1" - bazel --bazelrc=/dev/null --output_base="${base}" clean --expunge - bazel --bazelrc=/dev/null --output_base="${base}" shutdown + "${bazel}" --bazelrc=/dev/null --output_base="${base}" clean --expunge + "${bazel}" --bazelrc=/dev/null --output_base="${base}" shutdown } cleanup() { diff --git a/tests/run_tests.sh b/tests/run_tests.sh index 214c0b5..5951152 100755 --- a/tests/run_tests.sh +++ b/tests/run_tests.sh @@ -13,29 +13,26 @@ # See the License for the specific language governing permissions and # limitations under the License. -set -euxo pipefail +set -euo pipefail cd "$(dirname "${BASH_SOURCE[0]}")" +source "./setup-bazel.sh" + # r_binary related tests. Run these individually most layered target first, # before building everything so we don't have runfiles built for wrapped # targets. The alternative is to clean the workspace before each test. -bazel clean -bazel run //binary:binary_sh_test +set -x +"${bazel}" clean +"${bazel}" run //binary:binary_sh_test bazel-bin/binary/binary_sh_test -bazel run //binary:binary_r_test +"${bazel}" run //binary:binary_r_test bazel-bin/binary/binary_r_test -bazel run //binary +"${bazel}" run //binary bazel-bin/binary/binary +set +x -export BAZEL_TEST_OPTS=( -"--color=yes" -"--show_progress_rate_limit=30" -"--keep_going" -"--test_output=errors" -) - -bazel test "${BAZEL_TEST_OPTS[@]}" //... +"${bazel}" test "${bazel_test_opts[@]}" //... coverage/coverage_test.sh diff --git a/tests/setup-bazel.sh b/tests/setup-bazel.sh new file mode 100644 index 0000000..b89c18c --- /dev/null +++ b/tests/setup-bazel.sh @@ -0,0 +1,39 @@ +#!/bin/bash +# Copyright 2018 The Bazel Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# This script is intended to be sourced as a library, and makes available a +# bazel env var. + +os="$(uname -s | tr "[:upper:]" "[:lower:]")" +readonly os + +# Use bazelisk to catch migration problems. +# Value of BAZELISK_GITHUB_TOKEN is set as a secret on Travis. +readonly url="https://github.com/bazelbuild/bazelisk/releases/download/v1.4.0/bazelisk-${os}-amd64" +bazel="${TMPDIR:-/tmp}/bazelisk" +readonly bazel + +if ! [[ -x "${bazel}" ]]; then + curl -L -sSf -o "${bazel}" "${url}" + chmod a+x "${bazel}" +fi + +# Exported for scripts that will source this file. +bazel_test_opts=( +"--color=yes" +"--show_progress_rate_limit=30" +"--keep_going" +"--test_output=errors" +)