Rework Travis scripts

This commit is contained in:
Jan Bujak 2018-02-04 13:27:26 +01:00
parent a9636469ea
commit e9c7c125ea
4 changed files with 90 additions and 66 deletions

View File

@ -5,20 +5,21 @@ sudo: false
addons:
chrome: stable
cache:
cargo: true
directories:
- /home/travis/.local/share/cargo-web/emscripten
rust:
- nightly
- stable
- beta
- nightly
matrix:
allow_failures:
- rust: nightly
env:
- TARGET=wasm32-unknown-unknown
- TARGET=asmjs-unknown-emscripten
- TARGET=wasm32-unknown-emscripten
script:
- nvm install 9
- ./ci.sh
- ./ci/install_cargo_web.sh
- ./ci/run_tests.sh

59
ci.sh
View File

@ -1,59 +0,0 @@
#!/bin/bash
# Originally this ci script borrowed from https://github.com/koute/stdweb
# because both use `cargo-web` tool to check the compilation.
set -euo pipefail
IFS=$'\n\t'
set +e
echo "$(rustc --version)" | grep -q "nightly"
if [ "$?" = "0" ]; then
export IS_NIGHTLY=1
else
export IS_NIGHTLY=0
fi
set -e
echo "Is Rust from nightly: $IS_NIGHTLY"
if [ "$IS_NIGHTLY" = "0" ]; then
if [ "$TARGET" = "wasm32-unknown-unknown" ]; then
echo "Skipping tests; wasm32-unknown-unknown is only supported on nightly"
exit 0
fi
fi
cargo install cargo-web -f
if [ "$TARGET" = "asmjs-unknown-emscripten" ]; then
rustup target add asmjs-unknown-emscripten
export CARGO_WEB_ARGS="--target-asmjs-emscripten"
cargo web test --features web_test $CARGO_WEB_ARGS
fi
if [ "$TARGET" = "wasm32-unknown-emscripten" ]; then
rustup target add wasm32-unknown-emscripten
export CARGO_WEB_ARGS="--target-webasm-emscripten"
cargo web test --features web_test $CARGO_WEB_ARGS
fi
if [ "$TARGET" = "wasm32-unknown-unknown" ]; then
rustup target add wasm32-unknown-unknown
export CARGO_WEB_ARGS="--target-webasm"
cargo web test --nodejs $CARGO_WEB_ARGS
fi
check_example() {
echo "Checking example [$1]"
cd $1
cargo web build $CARGO_WEB_ARGS
# TODO Can't build some demos with release, need fix
# cargo web build --release $CARGO_WEB_ARGS
}
for EXAMPLE in $(pwd)/examples/*; do
if [ -d "$EXAMPLE" ]; then
check_example $EXAMPLE
fi
done

15
ci/install_cargo_web.sh Executable file
View File

@ -0,0 +1,15 @@
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'
CARGO_WEB_RELEASE=$(curl -L -s -H 'Accept: application/json' https://github.com/koute/cargo-web/releases/latest)
CARGO_WEB_VERSION=$(echo $CARGO_WEB_RELEASE | sed -e 's/.*"tag_name":"\([^"]*\)".*/\1/')
CARGO_WEB_URL="https://github.com/koute/cargo-web/releases/download/$CARGO_WEB_VERSION/cargo-web-x86_64-unknown-linux-gnu.gz"
echo "Downloading cargo-web from: $CARGO_WEB_URL"
curl -L $CARGO_WEB_URL | gzip -d > cargo-web
chmod +x cargo-web
mkdir -p ~/.cargo/bin
mv cargo-web ~/.cargo/bin

67
ci/run_tests.sh Executable file
View File

@ -0,0 +1,67 @@
#!/bin/bash
# Originally this ci script borrowed from https://github.com/koute/stdweb
# because both use `cargo-web` tool to check the compilation.
set -euo pipefail
IFS=$'\n\t'
set +e
echo "$(rustc --version)" | grep -q "nightly"
if [ "$?" = "0" ]; then
export IS_NIGHTLY=1
else
export IS_NIGHTLY=0
fi
set -e
echo "Is Rust from nightly: $IS_NIGHTLY"
echo "Testing for asmjs-unknown-emscripten..."
cargo web test --features web_test --target=asmjs-unknown-emscripten
echo "Testing for wasm32-unknown-emscripten..."
cargo web test --features web_test --target=wasm32-unknown-emscripten
if [ "$IS_NIGHTLY" = "1" ]; then
echo "Testing for wasm32-unknown-unknown..."
cargo web test --nodejs --target=wasm32-unknown-unknown
fi
check_example() {
echo "Checking example [$2]"
pushd $2 > /dev/null
cargo web build --target=$1
popd > /dev/null
# TODO Can't build some demos with release, need fix
# cargo web build --release $CARGO_WEB_ARGS
}
check_all_examples() {
echo "Checking examples on $1..."
for EXAMPLE in $(pwd)/examples/*; do
if [ "$1" == "wasm32-unknown-unknown" ]; then
# The counter example doesn't yet build here.
case $(basename $EXAMPLE) in
"counter")
continue
;;
*)
;;
esac
fi
if [ -d "$EXAMPLE" ]; then
check_example $1 $EXAMPLE
fi
done
}
check_all_examples asmjs-unknown-emscripten
check_all_examples wasm32-unknown-emscripten
if [ "$IS_NIGHTLY" = "1" ]; then
check_all_examples wasm32-unknown-unknown
fi