-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtravis.sh
executable file
·128 lines (106 loc) · 2.78 KB
/
travis.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/bin/bash
# shellcheck disable=SC1091
set -o errexit -o nounset -o pipefail
command -v shellcheck > /dev/null && shellcheck "$0"
#
# Travis helpers
#
function fold_start() {
export CURRENT_FOLD_NAME="$1"
if [[ "${TRAVIS_COMMIT:-}" != "" ]]; then
travis_fold start "$CURRENT_FOLD_NAME"
travis_time_start "$CURRENT_FOLD_NAME"
else
echo "Starting $CURRENT_FOLD_NAME"
fi
}
function fold_end() {
if [[ "${TRAVIS_COMMIT:-}" != "" ]]; then
travis_time_finish "$CURRENT_FOLD_NAME"
travis_fold end "$CURRENT_FOLD_NAME"
else
echo "Done with $CURRENT_FOLD_NAME"
fi
}
#
# Environment
#
TRAVIS_BUILD_VERSION=$(echo "${TRAVIS_COMMIT:-}" | cut -c 1-10)
BUILD_VERSION=${TRAVIS_BUILD_VERSION:-manual}
#
# Install
#
fold_start "yarn-install"
yarn install
fold_end
#
# Build
#
fold_start "yarn-build"
yarn build
fold_end
fold_start "check-dirty"
# Ensure build step didn't modify source files to avoid unprettified repository state
SOURCE_CHANGES=$(git status --porcelain)
if [[ -n "$SOURCE_CHANGES" ]]; then
echo "Error: repository contains changes."
echo "Showing 'git status' and 'git diff' for debugging reasons now:"
git status
git diff
exit 1
fi
fold_end
#
# Unit tests
#
fold_start "unit-tests"
yarn test
fold_end
#
# Start blockchains
#
fold_start "bnsd-start"
./scripts/bnsd/start.sh
fold_end
#
# Integration tests
#
fold_start "integration-tests"
yarn dev-start &
# observe logs of background faucet a bit
sleep 20
curl --fail -sS http://localhost:8000/status
curl --fail -sS \
--header "Content-Type: application/json" \
--request POST \
--data '{"ticker":"CASH","address":"tiov1k898u78hgs36uqw68dg7va5nfkgstu5z0fhz3f"}' \
http://localhost:8000/credit
fold_end
#
# Deploy
#
fold_start "docker-build"
docker build -t "iov1/iov-faucet:${BUILD_VERSION}" .
fold_end
fold_start "docker-run-tests"
docker run --read-only --rm "iov1/iov-faucet:${BUILD_VERSION}" version
docker run --read-only --rm "iov1/iov-faucet:${BUILD_VERSION}" help
docker run --read-only --rm "iov1/iov-faucet:${BUILD_VERSION}" generate bns some-test-chain-id
fold_end
fold_start "dockerhub-upload"
if [[ "${TRAVIS_NODE_VERSION:-}" == "10" && "${TRAVIS_OS_NAME:-}" == "linux" ]]; then
# only run in one job of the build matrix
if [[ "$TRAVIS_BRANCH" == "master" ]] && [[ "$TRAVIS_TAG" == "" ]] && [[ "$TRAVIS_PULL_REQUEST_BRANCH" == "" ]]; then
docker login -u "$DOCKER_USERNAME" -p "$DOCKER_PASSWORD"
docker tag "iov1/iov-faucet:${BUILD_VERSION}" "iov1/iov-faucet:latest"
docker push "iov1/iov-faucet:latest"
docker logout
fi
if [[ "$TRAVIS_TAG" != "" ]]; then
docker login -u "$DOCKER_USERNAME" -p "$DOCKER_PASSWORD"
docker tag "iov1/iov-faucet:${BUILD_VERSION}" "iov1/iov-faucet:$TRAVIS_TAG"
docker push "iov1/iov-faucet:$TRAVIS_TAG"
docker logout
fi
fi
fold_end