Skip to content

Commit

Permalink
Add --check option to run golint and gofmt in ./hack/build-in-docker.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
mfojtik committed Feb 3, 2015
1 parent d619578 commit 6406d71
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 19 deletions.
3 changes: 2 additions & 1 deletion hack/build-in-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ set -o nounset
set -o pipefail

origin_path="src/github.com/openshift/origin"
docker run -v ${GOPATH}/${origin_path}:/go/${origin_path} openshift/origin-release /opt/bin/build.sh
docker run --rm -v ${GOPATH}/${origin_path}:/go/${origin_path} \
openshift/origin-release /usr/bin/openshift-origin-build.sh $@
1 change: 0 additions & 1 deletion hack/verify-gofmt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ set -o nounset
set -o pipefail

GO_VERSION=($(go version))
echo "Detected go version: $(go version)"

if [[ ${GO_VERSION[2]} != "go1.3"* && ${GO_VERSION[2]} != "go1.4"* ]]; then
echo "Unknown go version, skipping gofmt."
Expand Down
16 changes: 11 additions & 5 deletions hack/verify-golint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ if ! which golint &>/dev/null; then
fi

GO_VERSION=($(go version))
echo "Detected go version: $(go version)"

if [[ ${GO_VERSION[2]} != "go1.2" && ${GO_VERSION[2]} != "go1.3.1" && ${GO_VERSION[2]} != "go1.3.3" ]]; then
echo "Unknown go version, skipping golint."
if [[ -z $(echo "${GO_VERSION[2]}" | grep -E 'go1.2|go1.3') ]]; then
echo "Unknown go version '${GO_VERSION}', skipping golint."
exit 0
fi

Expand All @@ -27,9 +26,16 @@ bad_files=""

if [ "$arg" == "-m" ]; then
head=$(git rev-parse --short HEAD | xargs echo -n)
bad_files=$(git diff-tree --no-commit-id --name-only -r master..$head | \
set +e
modified_files=$(git diff-tree --no-commit-id --name-only -r master..$head | \
grep "^pkg" | grep ".go$" | grep -v "bindata.go$" | grep -v "Godeps" | \
grep -v "third_party" | xargs golint)
grep -v "third_party")
if [ -n "${modified_files}" ]; then
echo -e "Checking modified files: ${modified_files}\n"
for f in $modified_files; do golint $f; done
echo
fi
set -e
else
find_files() {
find . -not \( \
Expand Down
5 changes: 3 additions & 2 deletions images/release/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ RUN yum install -y hg golang golang-pkg-darwin golang-pkg-windows && yum clean a
ENV GOPATH /go

# Get the code coverage tool and godep
RUN go get code.google.com/p/go.tools/cmd/cover github.com/tools/godep
RUN go get code.google.com/p/go.tools/cmd/cover github.com/tools/godep github.com/golang/lint/golint

# Mark this as a os-build container
RUN touch /os-build-image
Expand All @@ -24,7 +24,8 @@ ENV PATH $PATH:$GOROOT/bin:$GOPATH/bin

ENV OS_VERSION_FILE /go/src/github.com/openshift/origin/os-version-defs

ADD build.sh /opt/bin/build.sh
# Allows building Origin sources mounted using volume
ADD openshift-origin-build.sh /usr/bin/openshift-origin-build.sh

# Expect a tar with the source of OpenShift Origin (and /os-version-defs in the root)
CMD tar mxzf - && hack/build-cross.sh
10 changes: 0 additions & 10 deletions images/release/build.sh

This file was deleted.

26 changes: 26 additions & 0 deletions images/release/openshift-origin-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

os_dir="${GOPATH}/src/github.com/openshift/origin"
build_script_path=`mktemp /tmp/build.XXX.sh`

cat <<EOF > ${build_script_path}
#!/bin/bash -e
cd ${os_dir}
OS_VERSION_FILE="" ./hack/build-go.sh && chmod -R go+rw {Godeps/_workspace/pkg,_output}
EOF

echo "++ Checking for gofmt errors"
./hack/verify-gofmt.sh
if [ "$?" != "0" ]; then
echo "Fix the gofmt errors above and then run this command again."
exit 1
fi

if [ "$1" == "--check" ]; then
echo "++ Checking for golint errors"
pushd ${os_dir} >/dev/null
./hack/verify-golint.sh -m
popd >/dev/null
fi

exec sh ${build_script_path}

0 comments on commit 6406d71

Please sign in to comment.