-
Notifications
You must be signed in to change notification settings - Fork 1
/
pre-push
executable file
·45 lines (37 loc) · 1.19 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
#!/usr/bin/env bash
#
# Description
# -----------
# Runs fast validations against codebase on `git push`
# Includes:
# - linter;
# - unit tests;
# - go vet.
#
# Installation
# ------------
# Copy this file to .git/hooks
echo "Pre-push validation started... (see .git/hooks/pre-push)"
DOCKER_IMAGE_TAG=goapstra/tests:local
function build_image_or_exit_with_error() {
if ! docker build -t ${DOCKER_IMAGE_TAG} -f ci.Dockerfile . > /dev/null; then
exit $?
fi
}
if ! docker image inspect ${DOCKER_IMAGE_TAG} &>/dev/null; then
echo "Docker image ${DOCKER_IMAGE_TAG} does not exist, build it..."
build_image_or_exit_with_error
else
created=$(docker image inspect ${DOCKER_IMAGE_TAG} --format '{{ .Created }}' 2>/dev/null)
if [[ -n "${created}" ]]; then
image_epoch=$(date -u -jf "%Y-%m-%dT%H:%M:%S" ${created} +%s 2>/dev/null)
dockerfile_epoch=$(stat -f%m ci.Dockerfile)
if (( image_epoch < dockerfile_epoch )); then
echo "Docker image ${DOCKER_IMAGE_TAG} is older than Dockerfile, rebuild it..."
build_image_or_exit_with_error
fi
fi
fi
echo "Run 'make verify'"
docker run --rm -w /go/src -v "$(pwd)":/go/src ${DOCKER_IMAGE_TAG} make --keep-going fast-check
exit $?