From 59f1206fdecaa4cc1251b00532771c918125b37a Mon Sep 17 00:00:00 2001 From: Grimes Date: Mon, 28 May 2018 12:48:14 -0700 Subject: [PATCH 1/7] s/label:/name:/g --- ci/buildkite.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/ci/buildkite.yml b/ci/buildkite.yml index a1d8c755dc8bbc..d1cacc25c02dc7 100644 --- a/ci/buildkite.yml +++ b/ci/buildkite.yml @@ -1,6 +1,6 @@ steps: - command: "ci/coverage.sh" - label: "coverage [public]" + name: "coverage [public]" # TODO: Run coverage in a docker image rather than assuming kcov/cargo-kcov # is installed on the build agent... #plugins: @@ -10,30 +10,30 @@ steps: # environment: # - CODECOV_TOKEN - command: "ci/test-stable.sh" - label: "stable [public]" + name: "stable [public]" plugins: docker#v1.1.1: image: "rust" user: "998:997" # buildkite-agent:buildkite-agent - command: "ci/test-nightly.sh || true" - label: "nightly - FAILURES IGNORED [public]" + name: "nightly - FAILURES IGNORED [public]" plugins: docker#v1.1.1: image: "rustlang/rust:nightly" user: "998:997" # buildkite-agent:buildkite-agent - command: "ci/test-ignored.sh" - label: "ignored [public]" + name: "ignored [public]" plugins: docker#v1.1.1: image: "rust" user: "998:997" # buildkite-agent:buildkite-agent - command: "ci/test-cuda.sh" - label: "cuda" + name: "cuda" - command: "ci/shellcheck.sh" - label: "shellcheck [public]" + name: "shellcheck [public]" - wait - command: "ci/publish.sh" - label: "publish release artifacts" + name: "publish release artifacts" plugins: docker#v1.1.1: image: "rust" From 0c16ec7cf123ff64bb9fa053fb7d35ab50e4cd06 Mon Sep 17 00:00:00 2001 From: Grimes Date: Mon, 28 May 2018 13:04:51 -0700 Subject: [PATCH 2/7] Don't fail if CODECOV_TOKEN is undefined --- ci/coverage.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ci/coverage.sh b/ci/coverage.sh index af5e4e89d1e1b4..dfae3ca66b2e36 100755 --- a/ci/coverage.sh +++ b/ci/coverage.sh @@ -19,8 +19,8 @@ cargo kcov --lib if [[ -z "$CODECOV_TOKEN" ]]; then echo CODECOV_TOKEN undefined - exit 1 +else + bash <(curl -s https://codecov.io/bash) fi -bash <(curl -s https://codecov.io/bash) exit 0 From d4ab12a8ad02508fea3e10413eadf74dd59902fe Mon Sep 17 00:00:00 2001 From: Grimes Date: Mon, 28 May 2018 13:05:16 -0700 Subject: [PATCH 3/7] Support local .a, skip if unable to find .a --- ci/test-cuda.sh | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/ci/test-cuda.sh b/ci/test-cuda.sh index 236f4fb0b531c7..ef92733786f223 100755 --- a/ci/test-cuda.sh +++ b/ci/test-cuda.sh @@ -2,11 +2,17 @@ cd "$(dirname "$0")/.." -: "${libcuda_verify_ed25519_URL:?environment variable undefined}" +LIB=libcuda_verify_ed25519.a +if [[ ! -r $LIB ]]; then + if [[ -z "${libcuda_verify_ed25519_URL:-}" ]]; then + echo "$0 skipped. Unable to locate $LIB" + exit 0 + fi -export LD_LIBRARY_PATH=/usr/local/cuda/lib64 -export PATH=$PATH:/usr/local/cuda/bin -curl -X GET -o libcuda_verify_ed25519.a "$libcuda_verify_ed25519_URL" + export LD_LIBRARY_PATH=/usr/local/cuda/lib64 + export PATH=$PATH:/usr/local/cuda/bin + curl -X GET -o $LIB "$libcuda_verify_ed25519_URL" +fi # shellcheck disable=SC1090 # <-- shellcheck can't follow ~ source ~/.cargo/env From 38d4ed4d0497af24ab68739b791829a604adced9 Mon Sep 17 00:00:00 2001 From: Grimes Date: Mon, 28 May 2018 12:38:55 -0700 Subject: [PATCH 4/7] Add local buildkite CI runner --- ci/.gitignore | 2 ++ ci/run-local.sh | 19 +++++++++++++++++++ ci/shellcheck.sh | 2 +- 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 ci/.gitignore create mode 100755 ci/run-local.sh diff --git a/ci/.gitignore b/ci/.gitignore new file mode 100644 index 00000000000000..936e5c57af9478 --- /dev/null +++ b/ci/.gitignore @@ -0,0 +1,2 @@ +/node_modules/ +/package-lock.json diff --git a/ci/run-local.sh b/ci/run-local.sh new file mode 100755 index 00000000000000..884825765887ce --- /dev/null +++ b/ci/run-local.sh @@ -0,0 +1,19 @@ +#!/bin/bash -e +# +# Run the entire buildkite CI pipeline locally for pre-testing before sending a +# Github pull request +# + +cd "$(dirname "$0")/.." +BKRUN=ci/node_modules/.bin/bkrun + +if [[ ! -x $BKRUN ]]; then + ( + set -x + cd ci/ + npm install bkrun + ) +fi + +set -x +./ci/node_modules/.bin/bkrun ci/buildkite.yml diff --git a/ci/shellcheck.sh b/ci/shellcheck.sh index 8a33cec9d5665d..551a029146a4ef 100755 --- a/ci/shellcheck.sh +++ b/ci/shellcheck.sh @@ -6,7 +6,7 @@ cd "$(dirname "$0")/.." set -x docker pull koalaman/shellcheck -find . -name "*.sh" -not -regex ".*/.cargo/.*" -print0 \ +find -E . -name "*.sh" -not -regex ".*/(.cargo|node_modules)/.*" -print0 \ | xargs -0 \ docker run -w /work -v "$PWD:/work" \ koalaman/shellcheck --color=always --external-sources --shell=bash From 521ba92a4d5801e36ee8c8545c8241d89d92e171 Mon Sep 17 00:00:00 2001 From: Grimes Date: Mon, 28 May 2018 14:07:30 -0700 Subject: [PATCH 5/7] Avoid docker buildkite plugin, which is not supported by bkrun --- ci/buildkite.yml | 33 +++------------------------------ ci/coverage.sh | 21 ++++++++------------- ci/docker-run.sh | 41 +++++++++++++++++++++++++++++++++++++++++ ci/publish.sh | 4 ++-- ci/shellcheck.sh | 7 ++----- 5 files changed, 56 insertions(+), 50 deletions(-) create mode 100755 ci/docker-run.sh diff --git a/ci/buildkite.yml b/ci/buildkite.yml index d1cacc25c02dc7..56d4a54acc164e 100644 --- a/ci/buildkite.yml +++ b/ci/buildkite.yml @@ -1,32 +1,12 @@ steps: - command: "ci/coverage.sh" name: "coverage [public]" - # TODO: Run coverage in a docker image rather than assuming kcov/cargo-kcov - # is installed on the build agent... - #plugins: - # docker#v1.1.1: - # image: "rust" - # user: "998:997" # buildkite-agent:buildkite-agent - # environment: - # - CODECOV_TOKEN - - command: "ci/test-stable.sh" + - command: "ci/docker-run.sh rust ci/test-stable.sh" name: "stable [public]" - plugins: - docker#v1.1.1: - image: "rust" - user: "998:997" # buildkite-agent:buildkite-agent - - command: "ci/test-nightly.sh || true" + - command: "ci/docker-run.sh rustlang/rust:nightly ci/test-nightly.sh || true" name: "nightly - FAILURES IGNORED [public]" - plugins: - docker#v1.1.1: - image: "rustlang/rust:nightly" - user: "998:997" # buildkite-agent:buildkite-agent - - command: "ci/test-ignored.sh" + - command: "ci/docker-run.sh rust ci/test-ignored.sh" name: "ignored [public]" - plugins: - docker#v1.1.1: - image: "rust" - user: "998:997" # buildkite-agent:buildkite-agent - command: "ci/test-cuda.sh" name: "cuda" - command: "ci/shellcheck.sh" @@ -34,10 +14,3 @@ steps: - wait - command: "ci/publish.sh" name: "publish release artifacts" - plugins: - docker#v1.1.1: - image: "rust" - user: "998:997" # buildkite-agent:buildkite-agent - environment: - - BUILDKITE_TAG - - CRATES_IO_TOKEN diff --git a/ci/coverage.sh b/ci/coverage.sh index dfae3ca66b2e36..fc6098fc3b8fc3 100755 --- a/ci/coverage.sh +++ b/ci/coverage.sh @@ -2,20 +2,15 @@ cd "$(dirname "$0")/.." -if [[ -r ~/.cargo/env ]]; then - # Pick up local install of kcov/cargo-kcov - # shellcheck disable=SC1090 - source ~/.cargo/env -fi - -rustc --version -cargo --version -kcov --version -cargo-kcov --version +ci/docker-run.sh evilmachines/rust-cargo-kcov \ + bash -exc "\ + export RUST_BACKTRACE=1; \ + cargo build --verbose; \ + cargo kcov --lib --verbose; \ + " -export RUST_BACKTRACE=1 -cargo build -cargo kcov --lib +echo Coverage report: +ls -l target/cov/index.html if [[ -z "$CODECOV_TOKEN" ]]; then echo CODECOV_TOKEN undefined diff --git a/ci/docker-run.sh b/ci/docker-run.sh new file mode 100755 index 00000000000000..889d568b760df3 --- /dev/null +++ b/ci/docker-run.sh @@ -0,0 +1,41 @@ +#!/bin/bash -e + +usage() { + echo "Usage: $0 [docker image name] [command]" + echo + echo Runs command in the specified docker image with + echo a CI-appropriate environment + echo +} + +cd "$(dirname "$0")/.." + +IMAGE="$1" +if [[ -z "$IMAGE" ]]; then + echo Error: image not defined + exit 1 +fi + +docker pull "$IMAGE" +shift + +ARGS=(--workdir /solana --volume "$PWD:/solana" --rm) + +ARGS+=(--env "CARGO_HOME=/solana/.cargo") + +# kcov tries to set the personality of the binary which docker +# doesn't allow by default. +ARGS+=(--security-opt "seccomp=unconfined") + +# Ensure files are created with the current host uid/gid +ARGS+=(--user "$(id -u):$(id -g)") + +# Environment variables to propagate into the container +ARGS+=( + --env BUILDKITE_TAG + --env CODECOV_TOKEN + --env CRATES_IO_TOKEN +) + +set -x +docker run "${ARGS[@]}" "$IMAGE" "$@" diff --git a/ci/publish.sh b/ci/publish.sh index fb700a6ae73778..3dd0832c2819e8 100755 --- a/ci/publish.sh +++ b/ci/publish.sh @@ -12,8 +12,8 @@ if [[ -z "$CRATES_IO_TOKEN" ]]; then exit 1 fi -cargo package # TODO: Ensure the published version matches the contents of BUILDKITE_TAG -cargo publish --token "$CRATES_IO_TOKEN" +ci/docker-run.sh rust \ + bash -exc "cargo package; cargo publish --token $CRATES_IO_TOKEN" exit 0 diff --git a/ci/shellcheck.sh b/ci/shellcheck.sh index 551a029146a4ef..808e1724c24ad4 100755 --- a/ci/shellcheck.sh +++ b/ci/shellcheck.sh @@ -5,10 +5,7 @@ cd "$(dirname "$0")/.." set -x -docker pull koalaman/shellcheck -find -E . -name "*.sh" -not -regex ".*/(.cargo|node_modules)/.*" -print0 \ +find . -name "*.sh" -not -regex ".*/.cargo/.*" -not -regex ".*/node_modules/.*" -print0 \ | xargs -0 \ - docker run -w /work -v "$PWD:/work" \ - koalaman/shellcheck --color=always --external-sources --shell=bash - + ci/docker-run.sh koalaman/shellcheck --color=always --external-sources --shell=bash exit 0 From 996727bd6d5546bcbba57db05840858b5b8a0faa Mon Sep 17 00:00:00 2001 From: Grimes Date: Mon, 28 May 2018 16:46:47 -0700 Subject: [PATCH 6/7] Update code coverage command --- README.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 143d67f76e870f..496747ddf8a235 100644 --- a/README.md +++ b/README.md @@ -129,6 +129,11 @@ Run the test suite: $ cargo test ``` +To emulate all the tests that will run on a Pull Request, run: +```bash +$ ./ci/run-local.sh +``` + Debugging --- @@ -169,8 +174,10 @@ Code coverage To generate code coverage statistics, run kcov via Docker: ```bash -$ docker run -it --rm --security-opt seccomp=unconfined --volume "$PWD:/volume" elmtai/docker-rust-kcov +$ ./ci/coverage.sh ``` +The coverage report will be written to `./target/cov/index.html` + Why coverage? While most see coverage as a code quality metric, we see it primarily as a developer productivity metric. When a developer makes a change to the codebase, presumably it's a *solution* to From b0b3abe9001b5826d8a634627a342987751bc6a9 Mon Sep 17 00:00:00 2001 From: Grimes Date: Mon, 28 May 2018 19:45:47 -0700 Subject: [PATCH 7/7] Add RUST_BACKTRACE --- ci/test-cuda.sh | 1 + ci/test-nightly.sh | 1 + ci/test-stable.sh | 1 + 3 files changed, 3 insertions(+) diff --git a/ci/test-cuda.sh b/ci/test-cuda.sh index ef92733786f223..53aedac5e8718e 100755 --- a/ci/test-cuda.sh +++ b/ci/test-cuda.sh @@ -16,6 +16,7 @@ fi # shellcheck disable=SC1090 # <-- shellcheck can't follow ~ source ~/.cargo/env +export RUST_BACKTRACE=1 cargo test --features=cuda exit 0 diff --git a/ci/test-nightly.sh b/ci/test-nightly.sh index 843c5ad1ab7ad1..a0ae0102eeb131 100755 --- a/ci/test-nightly.sh +++ b/ci/test-nightly.sh @@ -5,6 +5,7 @@ cd "$(dirname "$0")/.." rustc --version cargo --version +export RUST_BACKTRACE=1 rustup component add rustfmt-preview cargo build --verbose --features unstable cargo test --verbose --features unstable diff --git a/ci/test-stable.sh b/ci/test-stable.sh index e1414a9f338c63..f21b465ac2f91e 100755 --- a/ci/test-stable.sh +++ b/ci/test-stable.sh @@ -5,6 +5,7 @@ cd "$(dirname "$0")/.." rustc --version cargo --version +export RUST_BACKTRACE=1 rustup component add rustfmt-preview cargo fmt -- --write-mode=diff cargo build --verbose