forked from web-platform-tests/wpt.fyi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pre-push
executable file
·75 lines (64 loc) · 2.04 KB
/
pre-push
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
#!/bin/bash
REPO_DIR="$(git rev-parse --show-toplevel)"
source "${REPO_DIR}/util/logging.sh"
source "${REPO_DIR}/util/commands.sh"
DOCKER_INSTANCE="${DOCKER_INSTANCE:-wptd-dev-instance}"
info "Checking where we're pushing..."
IS_MASTER="false"
while read local_ref local_sha remote_ref remote_sha
do
debug "$local_ref $local_sha $remote_ref $remote_sha"
if [[ -n "$remote_ref" ]];
then
if [[ "$(echo $remote_ref | sed -e 's,.*/\(.*\),\1,')" == "master" ]]
then
IS_MASTER="true"
fi
fi
done
if [[ "${IS_MASTER}" == "true" ]]
then
confirm "Are you sure you want to push master?" || fatal "User cancelled the push"
fi
# Check for uncommitted changes.
info "Checking for uncommitted changes..."
! git diff . 2>&1 | read > /dev/null 2>&1
DIFF_STATUS="${?}"
if [ "${DIFF_STATUS}" != "0" ]; then
confirm "You have uncommitted local changes. Push committed changes anyway?" \
|| fatal "User cancelled the push"
fi
info "Running pre-push checks in docker..."
docker inspect "${DOCKER_INSTANCE}" > /dev/null 2>&1
INSPECT_STATUS="${?}"
DOCKER_INSTANCE_PID=""
if [ "${INSPECT_STATUS}" != "0" ]; then
info "Docker instance ${DOCKER_INSTANCE} not found. Starting it..."
docker run -t -d --entrypoint /bin/bash \
-v "${WPTD_PATH}":/home/user/wpt.fyi \
-u $(id -u $USER):$(id -g $USER) \
--name "${DOCKER_INSTANCE}" wptd-dev &
DOCKER_INSTANCE_PID="${!}"
# Ensure rights.
wptd_useradd
wptd_chown "/home/user"
else
info "Found existing docker instance ${DOCKER_INSTANCE}"
fi
docker exec -t -u $(id -u $USER):$(id -g $USER) "${DOCKER_INSTANCE}" make prepush
LINT_STATUS="${?}"
FINAL_STATUS="${LINT_STATUS}"
if [ "${LINT_STATUS}" != "0" ]; then
confirm "Lint failed. Push anyway?" || fatal "User cancelled the push"
info "Pushing in spite of lint errors..."
FINAL_STATUS="0"
fi
if [ "${DOCKER_INSTANCE_PID}" != "" ]; then
kill "${DOCKER_INSTANCE_PID}"
fi
if [ "${FINAL_STATUS}" == "0" ]; then
info "Pre-push exit status: ${FINAL_STATUS}"
else
error "Pre-push exit status: ${FINAL_STATUS}"
fi
exit "${FINAL_STATUS}"