forked from crystal-lang/crystal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ci
executable file
·174 lines (141 loc) · 3.37 KB
/
ci
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#!/bin/sh
fail() {
echo "${@}" >&2
exit 1
}
on_tag() {
if [ -n "$CURRENT_TAG" ]; then
echo "${@}"
eval "${@}"
return $?
else
return 0
fi
}
fail_on_error() {
"${@}"
exit=$?
if [ "$exit" -ne "0" ]; then
fail "${@} exited with $exit"
fi
return 0
}
verify_environment() {
if [ -z "$TRAVIS_OS_NAME" ]; then
fail "\$TRAVIS_OS_NAME is not set or empty."
fi
}
verify_linux_environment() {
if [ -z "$ARCH" ]; then
fail "\$ARCH is not set or empty."
fi
if [ -z "$ARCH_CMD" ]; then
fail "\$ARCH_CMD is not set or empty."
fi
}
on_os() {
os="$1"
shift
verify_environment
if [ "$TRAVIS_OS_NAME" = "$os" ]; then
echo "${@}"
eval "${@}"
return $?
else
return 0
fi
}
on_linux() {
fail_on_error on_os "linux" "${@}"
}
on_osx() {
fail_on_error on_os "osx" "${@}"
}
prepare_system() {
on_linux 'echo '"'"'{"ipv6":true, "fixed-cidr-v6":"2001:db8:1::/64"}'"'"' | sudo tee /etc/docker/daemon.json'
on_linux sudo service docker restart
on_osx brew update
}
build() {
with_build_env 'make std_spec clean'
with_build_env 'make crystal std_spec compiler_spec docs'
with_build_env 'find samples -name "*.cr" | xargs -L 1 ./bin/crystal build --no-codegen'
with_build_env './bin/crystal tool format --check samples spec src'
}
prepare_build() {
on_linux verify_linux_environment
on_linux docker pull "jhass/crystal-build-$ARCH"
on_osx brew install crystal-lang pkg-config
# Make sure binaries from llvm are available in PATH
on_osx brew install jq
on_osx OSX_LLVM_PACKAGE=`brew info --json=v1 crystal-lang | jq '.[].dependencies | .[] | select(startswith("llvm"))'`
on_osx brew link --force $OSX_LLVM_PACKAGE
}
with_build_env() {
command="$1"
# Ensure non GMT timezone
export TZ="America/New_York"
on_linux verify_linux_environment
export DOCKER_TEST_PREFIX="crystallang/crystal:0.24.2"
case $ARCH in
x86_64)
export DOCKER_TEST_IMAGE="$DOCKER_TEST_PREFIX-build"
;;
i386)
export DOCKER_TEST_IMAGE="$DOCKER_TEST_PREFIX-i386-build"
;;
esac
on_linux docker run \
--rm -t \
-u $(id -u) \
-v $PWD:/mnt \
-w /mnt \
-e CRYSTAL_CACHE_DIR="/tmp/crystal" \
"$DOCKER_TEST_IMAGE" \
"$ARCH_CMD" /bin/sh -c "'$command'"
on_osx sudo systemsetup -settimezone $TZ
on_osx PATH="/usr/local/opt/llvm/bin:\$PATH" \
CRYSTAL_CACHE_DIR="/tmp/crystal" \
PKG_CONFIG_PATH="$(brew --prefix)/opt/openssl/lib/pkgconfig:$PKG_CONFIG_PATH" \
/bin/sh -c "'$command'"
}
usage() {
cat <<EOF
bin/ci [-h|--help] command [parameter ...]
Helper script to prepare and run the testsuite on Travis CI.
Commands:
prepare_system setup any necessaries repositories etc.
prepare_build download and extract any dependencies needed for the build
build run specs, build crystal, run format check, build samples, build the docs
with_build_env command run command in the build environment
help display this
EOF
}
command="$1"
shift
case $command in
prepare_system)
prepare_system
;;
prepare_build)
prepare_build
;;
with_build_env)
target_command="${@}"
with_build_env "$target_command"
;;
build)
build
;;
-h|--help|help)
usage
;;
*)
if [ -n "$command" ]; then
fail "Unknown command $command"
else
usage
exit 1
fi
;;
esac