Skip to content

Commit 06fd7ef

Browse files
authored
Merge pull request #1776 from lzutao/shellcheck
Enable shellcheck and fold Travis log
2 parents 540f4ea + d3b0a00 commit 06fd7ef

File tree

5 files changed

+139
-47
lines changed

5 files changed

+139
-47
lines changed

.travis.yml

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
sudo: required
2-
dist: trusty
1+
dist: xenial
32
services:
43
- docker
54
language: rust
65

6+
git:
7+
depth: false
8+
quiet: true
9+
710
matrix:
11+
fast_finish: true
812
include:
913
# Linux builds use the `rust-slave-dist` image so we link them against a
1014
# "super old glibc" to ensure that it runs on as many platforms as possible.
@@ -46,16 +50,16 @@ matrix:
4650
os: osx
4751
osx_image: xcode9.2
4852
if: branch != master
49-
env: MACOSX_DEPLOYMENT_TARGET=10.7 TARGET=i686-apple-darwin
50-
- <<: *mac
5153
env: MACOSX_DEPLOYMENT_TARGET=10.7 TARGET=x86_64-apple-darwin NO_ADD=1
54+
- <<: *mac
55+
env: MACOSX_DEPLOYMENT_TARGET=10.7 TARGET=i686-apple-darwin
5256

5357
install:
54-
- if [ -z "$NO_ADD" ]; then rustup target add $TARGET; fi
58+
- if [ -z "$NO_ADD" ]; then rustup target add "$TARGET"; fi
5559
- rustup component add rustfmt
5660

5761
script:
58-
- mkdir -p target/$TARGET;
62+
- mkdir -p target/"$TARGET";
5963
- >
6064
case "$TARGET" in
6165
*-linux-android) DOCKER=android ;; # Android uses a local docker image
@@ -68,9 +72,12 @@ script:
6872
else
6973
PATH="$HOME/rust/bin:$PATH" sh ci/run.sh;
7074
fi
75+
- if [ "${TRAVIS_OS_NAME}" = linux ]; then
76+
shellcheck -s dash -e SC1090 -- rustup-init.sh ci/*.sh;
77+
fi
7178

7279
before_deploy:
73-
- bash ci/prepare-deploy-travis.sh
80+
- sh ci/prepare-deploy-travis.sh
7481

7582
deploy:
7683
- provider: s3

ci/build-run-docker.sh

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,35 @@
11
#!/bin/bash
22

3-
set -ex
3+
script_dir=$(cd "$(dirname "$0")" && pwd)
4+
. "$script_dir/shared.sh"
5+
6+
set -e
7+
# Disable cause it makes shared script not to work properly
8+
#set -x
49

510
mkdir -p target
611

712
DOCKER="$1"
813
TARGET="$2"
914
SKIP_TESTS="$3"
1015

11-
bash ci/fetch-rust-docker.sh "$TARGET"
16+
travis_fold start "fetch.image.${TARGET}"
17+
travis_time_start
18+
travis_do_cmd sh ci/fetch-rust-docker.sh "$TARGET"
19+
travis_time_finish
20+
travis_fold end "fetch.image.${TARGET}"
21+
1222
if [ -f "ci/docker/$DOCKER/Dockerfile" ]; then
13-
docker build -t "$DOCKER" "ci/docker/$DOCKER/"
23+
travis_fold start "build.Dockerfile.${DOCKER}"
24+
travis_time_start
25+
travis_do_cmd docker build -t "$DOCKER" "ci/docker/$DOCKER/"
26+
travis_time_finish
27+
travis_fold end "build.Dockerfile.${DOCKER}"
1428
fi
1529

30+
# shellcheck disable=SC2016
1631
docker run \
17-
--entrypoint bash \
32+
--entrypoint sh \
1833
--user "$(id -u)":"$(id -g)" \
1934
--volume "$(rustc --print sysroot)":/travis-rust:ro \
2035
--volume "$(pwd)":/src:ro \
@@ -25,11 +40,10 @@ docker run \
2540
--env CARGO_HOME=/src/target/cargo-home \
2641
--env CARGO_TARGET_DIR=/src/target \
2742
--env LIBZ_SYS_STATIC=1 \
28-
--entrypoint sh \
2943
--tty \
3044
--init \
3145
"$DOCKER" \
32-
-c 'PATH="$PATH":/travis-rust/bin exec bash ci/run.sh'
46+
-c 'PATH="$PATH":/travis-rust/bin exec sh ci/run.sh'
3347

3448
# check that rustup-init was built with ssl support
3549
# see https://github.com/rust-lang/rustup.rs/issues/1051

ci/fetch-rust-docker.sh

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,17 @@
11
#!/bin/bash
22

3-
set -ex
3+
script_dir=$(cd "$(dirname "$0")" && pwd)
4+
. "$script_dir/shared.sh"
5+
6+
set -e
7+
# Disable cause it makes shared script not to work properly
8+
#set -x
49

510
TARGET="$1"
611

712
RUST_REPO="https://github.com/rust-lang/rust"
813
S3_BASE_URL="https://s3-us-west-1.amazonaws.com/rust-lang-ci2/rustc-builds"
914

10-
# See http://unix.stackexchange.com/questions/82598
11-
# Duplicated from rust-lang/rust/src/ci/shared.sh
12-
function retry {
13-
echo "Attempting with retry:" "$@"
14-
local n=1
15-
local max=5
16-
while true; do
17-
"$@" && break || {
18-
if [[ $n -lt $max ]]; then
19-
sleep $n # don't retry immediately
20-
((n++))
21-
echo "Command failed. Attempt $n/$max:"
22-
else
23-
echo "The command has failed after $n attempts."
24-
return 1
25-
fi
26-
}
27-
done
28-
}
29-
3015
# Use images from rustc master
3116
case "$TARGET" in
3217
mips-unknown-linux-gnu) image=dist-mips-linux ;;
@@ -48,14 +33,14 @@ rm -f "$info"
4833
curl -o "$info" "$image_url"
4934
digest=$(grep -m1 ^sha "$info")
5035

51-
if ! docker tag "$digest" "rust-$TARGET"; then
36+
if [ -z "$(docker images -q "rust-$TARGET")" ]; then
5237
url=$(grep -m1 ^https "$info")
5338
cache=/tmp/rustci_docker_cache
5439
echo "Attempting to download $url"
5540
rm -f "$cache"
5641
set +e
57-
retry curl -y 30 -Y 10 --connect-timeout 30 -f -L -C - -o "$cache" "$url"
58-
docker load -i "$cache"
42+
travis_retry curl -y 30 -Y 10 --connect-timeout 30 -f -L -C - -o "$cache" "$url"
5943
set -e
44+
docker load --quiet -i "$cache"
6045
docker tag "$digest" "rust-$TARGET"
6146
fi

ci/run.sh

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
set -ex
44

5-
printf 'toolchain versions\n------------------\n'
6-
75
rustc -vV
86
cargo -vV
97
rustfmt -vV
@@ -18,11 +16,3 @@ fi
1816
# Check the formatting last because test failures are more interesting to have
1917
# discovered for contributors lacking some platform access for testing beforehand
2018
cargo fmt --all -- --check
21-
22-
# Then check the shell scripts, if shellcheck is present (which it is on Travis CI)
23-
if command -v shellcheck > /dev/null 2>&1; then
24-
shellcheck --version
25-
shellcheck -- *.sh ci/*.sh
26-
else
27-
echo No shellcheck found, skipping.
28-
fi

ci/shared.sh

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
#!/bin/bash
2+
#
3+
# This file is intended to be sourced, so it is not being marked as
4+
# an executable file in git.
5+
6+
# This is from
7+
# https://github.com/travis-ci/travis-build/blob/master/lib/travis/build/bash/travis_setup_env.bash
8+
travis_setup_env() {
9+
export ANSI_RED='\033[31;1m'
10+
export ANSI_GREEN='\033[32;1m'
11+
export ANSI_YELLOW='\033[33;1m'
12+
export ANSI_RESET='\033[0m'
13+
export ANSI_CLEAR='\033[0K'
14+
}
15+
16+
# This is from
17+
# https://github.com/travis-ci/travis-build/blob/master/lib/travis/build/bash/travis_fold.bash
18+
travis_fold() {
19+
local action="${1}"
20+
local name="${2}"
21+
printf 'travis_fold:%s:%s\r'"${ANSI_CLEAR}" "${action}" "${name}"
22+
}
23+
24+
# This is modified loop version of
25+
# https://github.com/travis-ci/travis-build/blob/master/lib/travis/build/bash/travis_retry.bash
26+
travis_retry() {
27+
local result=0
28+
local count=1
29+
local max=5
30+
while [ "${count}" -le "${max}" ]; do
31+
[ "${result}" -ne 0 ] && {
32+
printf "${ANSI_RED}"'The command "%s" failed. Retrying, %s of %s.'"${ANSI_RESET}"'\n' "${*}" "${count}" "${max}" >&2
33+
}
34+
"${@}" && { result=0 && break; } || result="${?}"
35+
: $((count=count+1))
36+
sleep 1
37+
done
38+
39+
[ "${count}" -gt "${max}" ] && {
40+
printf "${ANSI_RED}"'The command "%s" failed %s times.'"${ANSI_RESET}"'\n' "${*}" "${max}" >&2
41+
}
42+
43+
return "${result}"
44+
}
45+
46+
# This is from
47+
# https://github.com/travis-ci/travis-build/blob/master/lib/travis/build/bash/
48+
travis_nanoseconds() {
49+
local cmd='date'
50+
local format='+%s%N'
51+
52+
if command -v gdate >/dev/null 2>&1; then
53+
cmd='gdate'
54+
elif [ "$(uname)" = Darwin ]; then
55+
format='+%s000000000'
56+
fi
57+
58+
"${cmd}" -u "${format}"
59+
}
60+
61+
# Generate random integer like bash's `$RANDOM`.
62+
travis_generate_rand() {
63+
shuf -i 0-$((0xffffffff)) -n 1
64+
}
65+
66+
travis_time_start() {
67+
TRAVIS_TIMER_ID="$(printf '%08x' "$(travis_generate_rand)")"
68+
TRAVIS_TIMER_START_TIME="$(travis_nanoseconds)"
69+
export TRAVIS_TIMER_ID TRAVIS_TIMER_START_TIME
70+
printf 'travis_time:start:%s\r'"${ANSI_CLEAR}" "${TRAVIS_TIMER_ID}"
71+
}
72+
73+
travis_time_finish() {
74+
travis_timer_end_time="$(travis_nanoseconds)"
75+
local duration="$((travis_timer_end_time - TRAVIS_TIMER_START_TIME))"
76+
printf '\ntravis_time:end:%s:start=%s,finish=%s,duration=%s\r'"${ANSI_CLEAR}" \
77+
"${TRAVIS_TIMER_ID}" "${TRAVIS_TIMER_START_TIME}" \
78+
"${travis_timer_end_time}" "${duration}"
79+
}
80+
81+
travis_do_cmd() {
82+
echo "$ ${*}"
83+
"${@}"
84+
local result="$?"
85+
export TRAVIS_TEST_RESULT=$((${TRAVIS_TEST_RESULT:-0} | $((result != 0))))
86+
87+
if [ "${result}" -eq 0 ]; then
88+
printf '%b' "${ANSI_GREEN}"
89+
else
90+
printf '%b' "${ANSI_RED}"
91+
fi
92+
printf 'The command "%s" exited with %d.'"${ANSI_RESET}"'\n' "${*}" "${result}"
93+
return "$result"
94+
}
95+
96+
travis_setup_env

0 commit comments

Comments
 (0)