-
Notifications
You must be signed in to change notification settings - Fork 72
/
cibuild
executable file
·57 lines (44 loc) · 1.63 KB
/
cibuild
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
#!/bin/bash
set -e
output_fold() {
# Exit early if no label provided
if [ -z "$1" ]; then
echo "output_fold(): requires a label argument."
return
fi
exit_value=0 # exit_value is used to record exit status of the given command
label=$1 # human-readable label describing what's being folded up
shift 1 # having retrieved the output_fold()-specific arguments, strip them off $@
# Only echo the tags when in CI_MODE
if [ "$CI_MODE" ]; then
echo "%%%FOLD {$label}%%%"
fi
# run the remaining arguments. If the command exits non-0, the `||` will
# prevent the `-e` flag from seeing the failure exit code, and we'll see
# the second echo execute
"$@" || exit_value=$?
# Only echo the tags when in CI_MODE
if [ "$CI_MODE" ]; then
echo "%%%END FOLD%%%"
fi
# preserve the exit code from the subcommand.
return $exit_value
}
function cleanup() {
echo
echo "%%%FOLD {Shutting down services...}%%%"
docker-compose down -v
echo "%%%END FOLD%%%"
}
trap cleanup EXIT
export CI_MODE=true
if [ -z "$MYSQL_VERSION" ]; then export MYSQL_VERSION=8 ; fi
if [ -z "$DISTRIBUTION" ]; then export DISTRIBUTION=debian:buster ; fi
if [ -z "$RUBY_VERSION" ]; then export RUBY_VERSION=3.2 ; fi
DISTRIBUTION_SLUG="$(echo "$DISTRIBUTION" | awk '{ gsub(":", "_") ; print $0 }')"
export DISTRIBUTION_SLUG
docker-compose rm -s -f -v
output_fold "Pull cache image..." docker-compose pull app || true
output_fold "Bootstrapping container..." docker-compose build
output_fold "Running tests..." docker-compose run --rm app
output_fold "Pushing cache image..." docker-compose push app || true # Don't fail if push fails