Browse code

Add --check option to run golint and gofmt in ./hack/build-in-docker.sh

Michal Fojtik authored on 2015/02/03 21:25:20
Showing 6 changed files
... ...
@@ -8,4 +8,5 @@ set -o nounset
8 8
 set -o pipefail
9 9
 
10 10
 origin_path="src/github.com/openshift/origin"
11
-docker run -v ${GOPATH}/${origin_path}:/go/${origin_path} openshift/origin-release /opt/bin/build.sh
11
+docker run --rm -v ${GOPATH}/${origin_path}:/go/${origin_path} \
12
+  openshift/origin-release /usr/bin/openshift-origin-build.sh $@
... ...
@@ -7,7 +7,6 @@ set -o nounset
7 7
 set -o pipefail
8 8
 
9 9
 GO_VERSION=($(go version))
10
-echo "Detected go version: $(go version)"
11 10
 
12 11
 if [[ ${GO_VERSION[2]} != "go1.3"* && ${GO_VERSION[2]} != "go1.4"* ]]; then
13 12
   echo "Unknown go version, skipping gofmt."
... ...
@@ -10,10 +10,9 @@ if ! which golint &>/dev/null; then
10 10
 fi
11 11
 
12 12
 GO_VERSION=($(go version))
13
-echo "Detected go version: $(go version)"
14 13
 
15
-if [[ ${GO_VERSION[2]} != "go1.2" && ${GO_VERSION[2]} != "go1.3.1" && ${GO_VERSION[2]} != "go1.3.3" ]]; then
16
-  echo "Unknown go version, skipping golint."
14
+if [[ -z $(echo "${GO_VERSION[2]}" | grep -E 'go1.2|go1.3') ]]; then
15
+  echo "Unknown go version '${GO_VERSION}', skipping golint."
17 16
   exit 0
18 17
 fi
19 18
 
... ...
@@ -27,9 +26,16 @@ bad_files=""
27 27
 
28 28
 if [ "$arg" == "-m" ]; then
29 29
   head=$(git rev-parse --short HEAD | xargs echo -n)
30
-  bad_files=$(git diff-tree --no-commit-id --name-only -r master..$head | \
30
+  set +e
31
+  modified_files=$(git diff-tree --no-commit-id --name-only -r master..$head | \
31 32
     grep "^pkg" | grep ".go$" | grep -v "bindata.go$" | grep -v "Godeps" | \
32
-    grep -v "third_party" | xargs golint)
33
+    grep -v "third_party")
34
+  if [ -n "${modified_files}" ]; then
35
+    echo -e "Checking modified files: ${modified_files}\n"
36
+    for f in $modified_files; do golint $f; done
37
+    echo
38
+  fi
39
+  set -e
33 40
 else
34 41
   find_files() {
35 42
     find . -not \( \
... ...
@@ -11,7 +11,7 @@ RUN yum install -y hg golang golang-pkg-darwin golang-pkg-windows && yum clean a
11 11
 ENV GOPATH /go
12 12
 
13 13
 # Get the code coverage tool and godep
14
-RUN go get code.google.com/p/go.tools/cmd/cover github.com/tools/godep
14
+RUN go get code.google.com/p/go.tools/cmd/cover github.com/tools/godep github.com/golang/lint/golint
15 15
 
16 16
 # Mark this as a os-build container
17 17
 RUN touch /os-build-image
... ...
@@ -24,7 +24,8 @@ ENV PATH $PATH:$GOROOT/bin:$GOPATH/bin
24 24
 
25 25
 ENV OS_VERSION_FILE /go/src/github.com/openshift/origin/os-version-defs
26 26
 
27
-ADD build.sh /opt/bin/build.sh
27
+# Allows building Origin sources mounted using volume
28
+ADD openshift-origin-build.sh /usr/bin/openshift-origin-build.sh
28 29
 
29 30
 # Expect a tar with the source of OpenShift Origin (and /os-version-defs in the root)
30 31
 CMD tar mxzf - && hack/build-cross.sh
31 32
deleted file mode 100755
... ...
@@ -1,10 +0,0 @@
1
-#!/bin/bash -e
2
-
3
-cat <<EOF > /tmp/build_script.sh
4
-#!/bin/bash -ex
5
-cd \${GOPATH}/src/github.com/openshift/origin
6
-OS_VERSION_FILE="" ./hack/build-go.sh && chmod -R go+rw {Godeps/_workspace/pkg,_output}
7
-EOF
8
-
9
-chmod +x /tmp/build_script.sh
10
-exec /tmp/build_script.sh
11 1
new file mode 100755
... ...
@@ -0,0 +1,26 @@
0
+#!/bin/bash
1
+
2
+os_dir="${GOPATH}/src/github.com/openshift/origin"
3
+build_script_path=`mktemp /tmp/build.XXX.sh`
4
+
5
+cat <<EOF > ${build_script_path}
6
+#!/bin/bash -e
7
+cd ${os_dir}
8
+OS_VERSION_FILE="" ./hack/build-go.sh && chmod -R go+rw {Godeps/_workspace/pkg,_output}
9
+EOF
10
+
11
+echo "++ Checking for gofmt errors"
12
+./hack/verify-gofmt.sh
13
+if [ "$?" != "0" ]; then
14
+  echo "Fix the gofmt errors above and then run this command again."
15
+  exit 1
16
+fi
17
+
18
+if [ "$1" == "--check" ]; then
19
+  echo "++ Checking for golint errors"
20
+  pushd ${os_dir} >/dev/null
21
+  ./hack/verify-golint.sh -m
22
+  popd >/dev/null
23
+fi
24
+
25
+exec sh ${build_script_path}