Skip to content

Commit

Permalink
Migrate from travis to github actions
Browse files Browse the repository at this point in the history
Also,
1. Use bazelisk to fetch bazel.
2. Improve test script verbosity.
  • Loading branch information
Siddhartha Bagaria authored and siddharthab committed Apr 25, 2020
1 parent c72e179 commit ff8231b
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 61 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -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
36 changes: 0 additions & 36 deletions .travis.yml

This file was deleted.

19 changes: 12 additions & 7 deletions tests/coverage/coverage_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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() {
Expand All @@ -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 //...
12 changes: 7 additions & 5 deletions tests/repro/repro_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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() {
Expand Down
23 changes: 10 additions & 13 deletions tests/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
39 changes: 39 additions & 0 deletions tests/setup-bazel.sh
Original file line number Diff line number Diff line change
@@ -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"
)

0 comments on commit ff8231b

Please sign in to comment.