-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
run-checks.sh
executable file
·69 lines (56 loc) · 1.82 KB
/
run-checks.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
#!/bin/sh
set -eu
build_docker_image() {
if ! which docker >/dev/null 2>&1; then
printf '\033[31mError:\033[m Docker not found. Install it from https://docs.docker.com/get-docker/ and restart the shell.\n' >&2
exit 1
fi
if test -n "$show_docker_build" -o -z "$(docker image ls -q osu-wiki)"; then
DOCKER_BUILDKIT=1 docker build --tag osu-wiki . && :
else
DOCKER_BUILDKIT=1 docker build --quiet --tag osu-wiki . >/dev/null && :
fi
if test $? -ne 0; then
printf '\033[31mError:\033[m Failed to build Docker image.\n' >&2
exit 1
fi
}
run_in_docker() {
msys="$(test -z "${MSYSTEM:-}" || printf 1)"
remove_node_modules="$(test -e node_modules || printf 1)"
# Map the host repo directory to /osu-wiki, but use node_modules from the
# image. Don't exit the script on fail; store the exit code to return later
MSYS_NO_PATHCONV="$msys" docker run \
-e "OSU_WIKI_MSYS=$msys" \
--rm \
--volume "$(pwd):/osu-wiki" \
--volume /osu-wiki/node_modules/ \
osu-wiki "$@" \
&& :
exit_code=$?
# FIXME: The above command leaves behind an empty node_modules directory if it
# didn't already exist, and I can't figure out how to prevent that... so
# here I delete the node_modules directory if it is new. —clayton
if test -n "$remove_node_modules"; then
rm -rf node_modules
fi
return "$exit_code"
}
show_docker_build=
case "${1:-}" in
--show-build)
show_docker_build=1
shift
;;
-*|help)
exec >&2
printf 'Run the test suite on files changed since master:\n\n'
printf ' \033[4m%s\033[m [--show-build]\n\n' "$0"
printf 'Run a command in the osu-wiki Docker container:\n\n'
printf ' \033[4m%s\033[m [--show-build] <command> [<arguments>]\n' "$0"
exit 1
;;
esac
cd -- "$(dirname "$0")"
build_docker_image
run_in_docker "$@"