-
Notifications
You must be signed in to change notification settings - Fork 5
/
lint
executable file
·58 lines (50 loc) · 1.65 KB
/
lint
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
#!/bin/bash
set -e
ROOT="$(git rev-parse --show-superproject-working-tree --show-toplevel | \
head -n1)"
CONTAINER_IMAGE=omegaup/hook_tools:20200927
if [[ $# != 0 ]]; then
# The caller has given us the explicit arguments.
ARGS="$@"
else
# Try to guess the set of changed files. Only specifying one commit so it
# diffs against the current working tree.
REMOTE="origin"
if [ -d "${ROOT}/.git/refs/remotes/upstream" ]; then
REMOTE="upstream"
fi
REMOTE_HASH="$(git rev-parse "${REMOTE}/main")"
MERGE_BASE="$(git merge-base "${REMOTE_HASH}" HEAD)"
ARGS="fix ${MERGE_BASE}"
fi
if [[ -t 0 ]]; then
# This is being run in an environment where stdin is connected to a TTY.
TTY_ARGS="--interactive --tty"
else
TTY_ARGS=""
fi
if [[ -d /proc ]] && grep -q pids:/docker /proc/1/cgroup; then
echo "Running ./stuff/lint.sh inside a container is not supported." 1>&2
echo "Please run this command outside the container" 1>&2
exit 1
fi
DOCKER_PATH="$(which docker)"
if [[ -z "${DOCKER_PATH}" ]]; then
echo "Docker binary not found." 1>&2
echo "Please install docker or run this command outside the container." 1>&2
exit 1
fi
if [[ "${ARGS}" == '--only-pull-image' ]]; then
exec "${DOCKER_PATH}" pull "${CONTAINER_IMAGE}"
fi
"${DOCKER_PATH}" run $TTY_ARGS --rm \
--user "$(id -u):$(id -g)" \
--env "GIT_AUTHOR_NAME=$(git config user.name)" \
--env "GIT_AUTHOR_EMAIL=$(git config user.email)" \
--env "GIT_COMMITTER_NAME=$(git config user.name)" \
--env "GIT_COMMITTER_EMAIL=$(git config user.email)" \
--volume "${ROOT}:/src" \
--env 'PYTHONIOENCODING=utf-8' \
--env "MYPYPATH=${ROOT}/stuff" \
"${CONTAINER_IMAGE}" --command-name="./stuff/lint.sh" $ARGS
echo OK