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 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275
|
#!/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
if [ -z "$CI_NIX_SHELL" ]; then
verify_environment
if [ "$TRAVIS_OS_NAME" = "$os" ]; then
echo "${@}"
eval "${@}"
return $?
else
return 0
fi
else
return 0
fi
}
on_linux() {
fail_on_error on_os "linux" "${@}"
}
on_osx() {
fail_on_error on_os "osx" "${@}"
}
on_nix_shell_eval() {
if [ -n "$CI_NIX_SHELL" ]; then
echo "${@}"
eval "${@}"
return $?
else
return 0
fi
}
on_nix_shell() {
fail_on_error on_nix_shell_eval "${@}"
}
on_github() {
if [ "$GITHUB_ACTIONS" = "true" ]; then
eval "${@}"
return $?
else
return 0
fi
}
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
}
build() {
with_build_env 'make std_spec clean threads=1 junit_output=.junit/std_spec.xml'
case $ARCH in
i386)
with_build_env 'make crystal threads=1'
with_build_env 'SPEC_SPLIT="0%4" make std_spec threads=1 junit_output=.junit/std_spec.0.xml'
with_build_env 'SPEC_SPLIT="1%4" make std_spec threads=1 junit_output=.junit/std_spec.1.xml'
with_build_env 'SPEC_SPLIT="2%4" make std_spec threads=1 junit_output=.junit/std_spec.2.xml'
with_build_env 'SPEC_SPLIT="3%4" make std_spec threads=1 junit_output=.junit/std_spec.3.xml'
parts=16
i=0
while [ $i -lt $parts ]; do
with_build_env "CRYSTAL_SPEC_COMPILER_THREADS=1 SPEC_SPLIT=\"$i%$parts\" make compiler_spec threads=1 junit_output=.junit/compiler_spec.$i.xml"
i=$((i + 1))
done
with_build_env 'make primitives_spec threads=1 junit_output=.junit/primitives_spec.xml'
with_build_env 'make docs threads=1'
;;
*)
with_build_env 'make crystal primitives_spec std_spec compiler_spec docs threads=1 junit_output=.junit/spec.xml DOCS_OPTIONS="--json-config-url=/api/versions.json --canonical-base-url=https://crystal-lang.org/api/latest/"'
;;
esac
with_build_env 'make samples'
with_build_env 'CRYSTAL_OPTS=--debug make samples'
}
format() {
with_build_env 'make clean crystal format threads=1 check=1'
}
prepare_build() {
on_linux verify_linux_environment
on_osx curl -L https://github.com/crystal-lang/crystal/releases/download/1.5.0/crystal-1.5.0-1-darwin-universal.tar.gz -o ~/crystal.tar.gz
on_osx 'pushd ~;gunzip -c ~/crystal.tar.gz | tar xopf -;mv crystal-1.5.0-1 crystal;popd'
# These commands may take a few minutes to run due to the large size of the repositories.
# This restriction has been made on GitHub's request because updating shallow
# clones is an extremely expensive operation due to the tree layout and
# traffic of Homebrew/homebrew-core and Homebrew/homebrew-cask. We don't do
# this for you automatically to avoid repeatedly performing an expensive
# unshallow operation in CI systems (which should instead be fixed to not use
# shallow clones). Sorry for the inconvenience!
on_osx git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core fetch --unshallow
on_osx git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask fetch --unshallow
on_osx brew update --preinstall
on_osx brew bundle --no-lock
# Install a recent bash version for nix-shell.
# macos ships with an ancient one.
if [ `uname` = "Darwin" ]; then
on_nix_shell "brew install bash"
fi
# initialize nix environment
on_nix_shell nix-shell
# Note: brew link --force might show:
# Warning: Refusing to link macOS-provided software: llvm
#
# If you need to have llvm first in your PATH run:
# echo 'export PATH="/usr/local/opt/llvm/bin:$PATH"' >> ~/.bash_profile
#
# This is added in the .circleci/config.yml
on_tag verify_version
}
verify_version() {
# If building a tag, check it matches with file
FILE_VERSION=`cat ./src/VERSION`
if [ "$FILE_VERSION" != "$CURRENT_TAG" ]
then
fail "VERSION ($FILE_VERSION) does not match GIT TAG ($CURRENT_TAG)"
fi
}
with_build_env() {
command="$1"
on_github "echo '::group::$1'"
# Ensure non GMT timezone
export TZ="America/New_York"
on_linux verify_linux_environment
export DOCKER_TEST_PREFIX="${DOCKER_TEST_PREFIX:=crystallang/crystal:1.5.0}"
case $ARCH in
x86_64)
export DOCKER_TEST_IMAGE="$DOCKER_TEST_PREFIX-build"
;;
x86_64-musl)
export DOCKER_TEST_IMAGE="$DOCKER_TEST_PREFIX-alpine-build"
;;
i386)
export DOCKER_TEST_IMAGE="$DOCKER_TEST_PREFIX-i386-build"
;;
esac
on_linux docker run \
--rm -t \
-u $(id -u) \
-v $PWD:/mnt \
-v /etc/passwd:/etc/passwd \
-v /etc/group:/etc/group \
-w /mnt \
-e CRYSTAL_CACHE_DIR="/tmp/crystal" \
-e SPEC_SPLIT_DOTS \
"$DOCKER_TEST_IMAGE" \
"$ARCH_CMD" /bin/sh -c "'$command'"
on_osx sudo systemsetup -settimezone $TZ
on_osx PATH="~/crystal/bin:\$PATH" \
CRYSTAL_LIBRARY_PATH="~/crystal/embedded/lib" \
CRYSTAL_CACHE_DIR="/tmp/crystal" \
/bin/sh -c "'$command'"
on_nix_shell nix-shell --pure $CI_NIX_SHELL_ARGS --run "'TZ=$TZ $command'"
on_github echo "::endgroup::"
}
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, build samples, build the docs
format build crystal, run format check
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
;;
format)
format
;;
-h|--help|help)
usage
;;
*)
if [ -n "$command" ]; then
fail "Unknown command $command"
else
usage
exit 1
fi
;;
esac
|