Skip to content

Commit

Permalink
Travis config, attempt 2
Browse files Browse the repository at this point in the history
  • Loading branch information
gmarek committed Oct 6, 2016
1 parent cdfd864 commit 4c48e8e
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 42 deletions.
19 changes: 14 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
branches:
only:
- master
language: python
python:
- "2.7"

services:
- docker

language: go

matrix:
include:
- go: 1.6

install:
# Create and move build under the go path
- mkdir -p $HOME/gopath/src/k8s.io
- mv $TRAVIS_BUILD_DIR $HOME/gopath/src/k8s.io/perf-tests
- cd $HOME/gopath/src/k8s.io/perf-tests
- hack/install-verify-tools.sh
- export PATH=$GOPATH/bin:$PATH

script:
- ./verify/verify-boilerplate.py
- ./verify/verify-boilerplate.sh
- ./verify/verify-gofmt.sh
- ./verify/verify-golint.sh
- go test k8s.io/perf-tests/...
54 changes: 17 additions & 37 deletions verify/verify-boilerplate.py → verify/boilerplate/boilerplate.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# Verifies that all source files contain the necessary copyright boilerplate
# snippet.

from __future__ import print_function

import argparse
Expand All @@ -29,20 +26,14 @@

parser = argparse.ArgumentParser()
parser.add_argument("filenames", help="list of files to check, all files if unspecified", nargs='*')

rootdir = os.path.dirname(__file__) + "/../"
rootdir = os.path.abspath(rootdir)
parser.add_argument("--rootdir", default=rootdir, help="root directory to examine")

default_boilerplate_dir = os.path.join(rootdir, "verify/boilerplate")
parser.add_argument("--boilerplate-dir", default=default_boilerplate_dir)
args = parser.parse_args()

rootdir = os.path.dirname(__file__) + "/../../"
rootdir = os.path.abspath(rootdir)

def get_refs():
refs = {}

for path in glob.glob(os.path.join(args.boilerplate_dir, "boilerplate.*.txt")):
for path in glob.glob(os.path.join(rootdir, "hack/boilerplate/boilerplate.*.txt")):
extension = os.path.basename(path).split(".")[1]

ref_file = open(path, 'r')
Expand All @@ -61,20 +52,16 @@ def file_passes(filename, refs, regexs):
data = f.read()
f.close()

basename = os.path.basename(filename)
extension = file_extension(filename)
if extension != "":
ref = refs[extension]
else:
ref = refs[basename]
ref = refs[extension]

# remove build tags from the top of Go files
if extension == "go":
p = regexs["go_build_constraints"]
(data, found) = p.subn("", data, 1)

# remove shebang from the top of shell files
if extension == "sh" or extension == "py":
if extension == "sh":
p = regexs["shebang"]
(data, found) = p.subn("", data, 1)

Expand Down Expand Up @@ -108,8 +95,7 @@ def file_passes(filename, refs, regexs):
def file_extension(filename):
return os.path.splitext(filename)[1].split(".")[-1].lower()

skipped_dirs = ['Godeps', 'third_party', '_gopath', '_output', '.git', 'vendor', '__init__.py']

skipped_dirs = ['Godeps', 'third_party', '_output', '.git', 'vendor']
def normalize_files(files):
newfiles = []
for pathname in files:
Expand All @@ -118,15 +104,15 @@ def normalize_files(files):
newfiles.append(pathname)
for i, pathname in enumerate(newfiles):
if not os.path.isabs(pathname):
newfiles[i] = os.path.join(args.rootdir, pathname)
newfiles[i] = os.path.join(rootdir, pathname)
return newfiles

def get_files(extensions):
files = []
if len(args.filenames) > 0:
files = args.filenames
else:
for root, dirs, walkfiles in os.walk(args.rootdir):
for root, dirs, walkfiles in os.walk(rootdir):
# don't visit certain dirs. This is just a performance improvement
# as we would prune these later in normalize_files(). But doing it
# cuts down the amount of filesystem walking we do and cuts down
Expand All @@ -142,37 +128,31 @@ def get_files(extensions):
files = normalize_files(files)
outfiles = []
for pathname in files:
basename = os.path.basename(pathname)
extension = file_extension(pathname)
if extension in extensions or basename in extensions:
if extension in extensions:
outfiles.append(pathname)
return outfiles

def get_regexs():
regexs = {}
# Search for "YEAR" which exists in the boilerplate, but shouldn't in the real thing
regexs["year"] = re.compile( 'YEAR' )
# dates can be 2014, 2015 or 2016, company holder names can be anything
# dates can be 2014 or 2015, company holder names can be anything
regexs["date"] = re.compile( '(2014|2015|2016)' )
# strip // +build \n\n build constraints
regexs["go_build_constraints"] = re.compile(r"^(// \+build.*\n)+\n", re.MULTILINE)
# strip #!.* from shell/python scripts
# strip #!.* from shell scripts
regexs["shebang"] = re.compile(r"^(#!.*\n)\n*", re.MULTILINE)
return regexs

if __name__ == "__main__":
exit_code = 0
def main():
regexs = get_regexs()
refs = get_refs()
filenames = get_files(refs.keys())
nonconforming_files = []

for filename in filenames:
if not file_passes(filename, refs, regexs):
nonconforming_files.append(filename)

if nonconforming_files:
print('%d files have incorrect boilerplate headers:' %
len(nonconforming_files))
for filename in sorted(nonconforming_files):
print(filename)
sys.exit(1)
print(filename, file=sys.stdout)

if __name__ == "__main__":
sys.exit(main())
2 changes: 2 additions & 0 deletions verify/boilerplate/boilerplate.py.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env python

# Copyright YEAR The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
31 changes: 31 additions & 0 deletions verify/install-verify-tools.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

# Copyright 2014 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -o errexit
set -o nounset
set -o pipefail

KUBE_ROOT=$(dirname "${BASH_SOURCE}")/..
GO_VERSION=($(go version))

# golint only works for golang 1.5+
if [[ -z $(echo "${GO_VERSION[2]}" | grep -E 'go1.1|go1.2|go1.3|go1.4') ]]; then
go get -u github.com/golang/lint/golint
fi

go get -u github.com/tools/godep

# ex: ts=2 sw=2 et filetype=sh
32 changes: 32 additions & 0 deletions verify/verify-boilerplate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash

# Copyright 2014 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -o errexit
set -o nounset
set -o pipefail

KUBE_ROOT=$(dirname "${BASH_SOURCE}")/..
boiler="${KUBE_ROOT}/hack/boilerplate/boilerplate.py"

files_need_boilerplate=($(${boiler} "$@"))

if [[ ${#files_need_boilerplate[@]} -gt 0 ]]; then
for file in "${files_need_boilerplate[@]}"; do
echo "Boilerplate header is wrong for: ${file}"
done

exit 1
fi

0 comments on commit 4c48e8e

Please sign in to comment.