From 3f0aa454533b434d188de1fd763615dfd56a637e Mon Sep 17 00:00:00 2001 From: Mike Brown Date: Thu, 14 May 2020 17:21:30 -0500 Subject: [PATCH] removing boilerplate test replace by projectboiler check Signed-off-by: Mike Brown --- .github/workflows/ci.yml | 3 +- Makefile | 7 +- docs/testing.md | 2 +- hack/boilerplate/.gitignore | 4 - hack/boilerplate/BUILD | 3 - .../boilerplate/{test/pass.go => boilerplate} | 2 - hack/boilerplate/boilerplate.Dockerfile.txt | 13 - hack/boilerplate/boilerplate.Makefile.txt | 13 - hack/boilerplate/boilerplate.go.txt | 15 -- hack/boilerplate/boilerplate.py | 242 ------------------ hack/boilerplate/boilerplate.py.txt | 13 - hack/boilerplate/boilerplate.sh.txt | 13 - hack/boilerplate/boilerplate_test.py | 52 ---- hack/boilerplate/test/fail.go | 19 -- hack/boilerplate/test/fail.py | 17 -- hack/boilerplate/test/pass.py | 17 -- hack/update-proto.sh | 3 +- hack/verify-boilerplate.sh | 56 ---- 18 files changed, 4 insertions(+), 490 deletions(-) delete mode 100644 hack/boilerplate/.gitignore delete mode 100644 hack/boilerplate/BUILD rename hack/boilerplate/{test/pass.go => boilerplate} (97%) delete mode 100644 hack/boilerplate/boilerplate.Dockerfile.txt delete mode 100644 hack/boilerplate/boilerplate.Makefile.txt delete mode 100644 hack/boilerplate/boilerplate.go.txt delete mode 100755 hack/boilerplate/boilerplate.py delete mode 100644 hack/boilerplate/boilerplate.py.txt delete mode 100644 hack/boilerplate/boilerplate.sh.txt delete mode 100644 hack/boilerplate/boilerplate_test.py delete mode 100644 hack/boilerplate/test/fail.go delete mode 100644 hack/boilerplate/test/fail.py delete mode 100644 hack/boilerplate/test/pass.py delete mode 100755 hack/verify-boilerplate.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e41e29620..37acbb0e5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -64,11 +64,10 @@ jobs: ../project/script/validate/dco # TODO: (mikebrow) removed test/ due to ltag not working with test/e3e symlink - # TODO: (mikebrow) removed hack/ due to prior boilerplate tests - name: Headers working-directory: src/github.com/containerd/cri run: | - ltag -t "../project/script/validate/template" --excludes "vendor test hack" --check -v + ltag -t "../project/script/validate/template" --excludes "vendor test" --check -v - name: Vendor working-directory: src/github.com/containerd/cri diff --git a/Makefile b/Makefile index dea775acf..cdfc4ec1f 100644 --- a/Makefile +++ b/Makefile @@ -49,7 +49,7 @@ all: binaries help: ## this help @awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z0-9._-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST) | sort -verify: lint gofmt boiler check-vendor ## execute the source code verification tools +verify: lint gofmt check-vendor ## execute the source code verification tools version: ## print current cri plugin release version @echo $(VERSION) @@ -62,10 +62,6 @@ gofmt: @echo "$(WHALE) $@" @./hack/verify-gofmt.sh -boiler: - @echo "$(WHALE) $@" - @./hack/verify-boilerplate.sh - check-vendor: @echo "$(WHALE) $@" @./hack/verify-vendor.sh @@ -209,7 +205,6 @@ install.tools: .install.gitvalidation .install.golangci-lint .install.vndr ## in install-containerd \ release \ push \ - boiler \ clean \ default \ gofmt \ diff --git a/docs/testing.md b/docs/testing.md index 4f387e2e8..ba74db5d2 100644 --- a/docs/testing.md +++ b/docs/testing.md @@ -4,7 +4,7 @@ This document assumes you have already setup the development environment (go, gi Before sending pull requests you should at least make sure your changes have passed code verification, unit, integration and CRI validation tests. ## Code Verification -Code verification includes lint, code formatting, boilerplate check etc. +Code verification includes lint, and code formatting check etc. * Install tools used by code verification: ```bash make install.tools diff --git a/hack/boilerplate/.gitignore b/hack/boilerplate/.gitignore deleted file mode 100644 index 749ccdafd..000000000 --- a/hack/boilerplate/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -# Byte-compiled / optimized / DLL files -__pycache__/ -*.py[cod] -*$py.class diff --git a/hack/boilerplate/BUILD b/hack/boilerplate/BUILD deleted file mode 100644 index c405bde04..000000000 --- a/hack/boilerplate/BUILD +++ /dev/null @@ -1,3 +0,0 @@ -package(default_visibility = ["//visibility:public"]) - -exports_files(glob(["*.txt"])) diff --git a/hack/boilerplate/test/pass.go b/hack/boilerplate/boilerplate similarity index 97% rename from hack/boilerplate/test/pass.go rename to hack/boilerplate/boilerplate index 913d608a5..c073fa4ad 100644 --- a/hack/boilerplate/test/pass.go +++ b/hack/boilerplate/boilerplate @@ -13,5 +13,3 @@ See the License for the specific language governing permissions and limitations under the License. */ - -package main diff --git a/hack/boilerplate/boilerplate.Dockerfile.txt b/hack/boilerplate/boilerplate.Dockerfile.txt deleted file mode 100644 index e3ab7208f..000000000 --- a/hack/boilerplate/boilerplate.Dockerfile.txt +++ /dev/null @@ -1,13 +0,0 @@ -# Copyright 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. diff --git a/hack/boilerplate/boilerplate.Makefile.txt b/hack/boilerplate/boilerplate.Makefile.txt deleted file mode 100644 index e3ab7208f..000000000 --- a/hack/boilerplate/boilerplate.Makefile.txt +++ /dev/null @@ -1,13 +0,0 @@ -# Copyright 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. diff --git a/hack/boilerplate/boilerplate.go.txt b/hack/boilerplate/boilerplate.go.txt deleted file mode 100644 index 5f158183b..000000000 --- a/hack/boilerplate/boilerplate.go.txt +++ /dev/null @@ -1,15 +0,0 @@ -/* - Copyright 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. -*/ diff --git a/hack/boilerplate/boilerplate.py b/hack/boilerplate/boilerplate.py deleted file mode 100755 index 29dcde76f..000000000 --- a/hack/boilerplate/boilerplate.py +++ /dev/null @@ -1,242 +0,0 @@ -#!/usr/bin/env python - -# Copyright The containerd 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. - -from __future__ import print_function - -import argparse -import difflib -import glob -import json -import mmap -import os -import re -import sys -from datetime import date - -parser = argparse.ArgumentParser() -parser.add_argument( - "filenames", - help="list of files to check, all files if unspecified", - nargs='*') - -# Rootdir defaults to the directory **above** the hack/repo-infra dir. -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, "hack/boilerplate") -parser.add_argument( - "--boilerplate-dir", default=default_boilerplate_dir) - -parser.add_argument( - "-v", "--verbose", - help="give verbose output regarding why a file does not pass", - action="store_true") - -args = parser.parse_args() - -verbose_out = sys.stderr if args.verbose else open("/dev/null", "w") - -def get_refs(): - refs = {} - - for path in glob.glob(os.path.join(args.boilerplate_dir, "boilerplate.*.txt")): - extension = os.path.basename(path).split(".")[1] - - ref_file = open(path, 'r') - ref = ref_file.read().splitlines() - ref_file.close() - refs[extension] = ref - - return refs - -def file_passes(filename, refs, regexs): - try: - f = open(filename, 'r') - except Exception as exc: - print("Unable to open %s: %s" % (filename, exc), file=verbose_out) - return False - - data = f.read() - f.close() - - basename = os.path.basename(filename) - extension = file_extension(filename) - if extension != "": - ref = refs[extension] - else: - ref = refs[basename] - - # 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": - p = regexs["shebang"] - (data, found) = p.subn("", data, 1) - - data = data.splitlines() - - # if our test file is smaller than the reference it surely fails! - if len(ref) > len(data): - print('File %s smaller than reference (%d < %d)' % - (filename, len(data), len(ref)), - file=verbose_out) - return False - - p = regexs["year"] - foundyear = 0 - for d in ref: - if p.search(d): - foundyear = 1 - break - - # if YEAR is found date is a requirement and should be in the range - # new rule is if YEAR is not found date is optional - p = regexs["date"] - for i, d in enumerate(data): - (data[i], found) = p.subn('YEAR', d) - # remove the year and extra space when year is optional - if foundyear == 0: - p = regexs["yearsp"] - for i, d in enumerate(data): - (data[i], found) = p.subn('', d) - - p = regexs["authors"] - found = 0 - for d in ref: - if p.search(d): - found = 1 - break - if found == 0: - print('File %s is missing AUTHORS' % filename, file=verbose_out) - return False - - # Replace all occurrences of the regex "The validNameHere Authors" with "AUTHORS" - p = regexs["auth"] - for i, d in enumerate(data): - (data[i], found) = p.subn('AUTHORS', d) - - # Remove extra copyright notices only one is necessary - p = regexs["copyright"] - keepgoing = 1 - while keepgoing == 1: - keepgoing = 0 - count = 0 - for d in data: - if p.search(d): - count = count + 1 - if count > 1: - keepgoing = 1 - data.remove(d) - break - - # trim our file to the same number of lines as the reference file - data = data[:len(ref)] - - # if we don't match the reference at this point, fail - if ref != data: - print("Header in %s does not match reference, diff:" % filename, file=verbose_out) - if args.verbose: - print(file=verbose_out) - for line in difflib.unified_diff(ref, data, 'reference', filename, lineterm=''): - print(line, file=verbose_out) - print(file=verbose_out) - return False - - return True - -def file_extension(filename): - return os.path.splitext(filename)[1].split(".")[-1].lower() - -skipped_dirs = ['Godeps', 'third_party', '_gopath', '_output', '.git', - 'cluster/env.sh', 'vendor', 'test/e2e/generated/bindata.go', - 'hack/boilerplate/test', '.glide'] - -def normalize_files(files): - newfiles = [] - for pathname in files: - if any(x in pathname for x in skipped_dirs): - continue - newfiles.append(pathname) - for i, pathname in enumerate(newfiles): - if not os.path.isabs(pathname): - newfiles[i] = os.path.join(args.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): - # 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 - # the size of the file list - for d in skipped_dirs: - if d in dirs: - dirs.remove(d) - - for name in walkfiles: - pathname = os.path.join(root, name) - files.append(pathname) - - 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: - 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' ) - regexs["yearsp"] = re.compile( 'YEAR ' ) - # dates can be 2014, 2015, 2016, ..., CURRENT_YEAR, company holder names can be anything - years = range(2014, date.today().year + 1) - regexs["date"] = re.compile( '(%s)' % "|".join(map(lambda l: str(l), years)) ) - # strip // +build \n\n build constraints - regexs["go_build_constraints"] = re.compile(r"^(// \+build.*\n)+\n", re.MULTILINE) - # strip #!.* from shell scripts - regexs["shebang"] = re.compile(r"^(#!.*\n)\n*", re.MULTILINE) - regexs["authors"] = re.compile( 'AUTHORS' ) - authors = [ 'The Kubernetes Authors', 'The Containerd Authors', 'The containerd Authors' ] - regexs["auth"] = re.compile( '(%s)' % "|".join(map(lambda l: str(l), authors)) ) - copyrightLines = [ 'Copyright YEAR AUTHORS', 'Copyright AUTHORS' ] - regexs["copyright"] = re.compile( '(%s)' % "|".join(map(lambda l: str(l), copyrightLines)) ) - return regexs - -def main(): - regexs = get_regexs() - refs = get_refs() - filenames = get_files(refs.keys()) - - for filename in filenames: - if not file_passes(filename, refs, regexs): - print(filename, file=sys.stdout) - - return 0 - -if __name__ == "__main__": - sys.exit(main()) diff --git a/hack/boilerplate/boilerplate.py.txt b/hack/boilerplate/boilerplate.py.txt deleted file mode 100644 index e3ab7208f..000000000 --- a/hack/boilerplate/boilerplate.py.txt +++ /dev/null @@ -1,13 +0,0 @@ -# Copyright 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. diff --git a/hack/boilerplate/boilerplate.sh.txt b/hack/boilerplate/boilerplate.sh.txt deleted file mode 100644 index e3ab7208f..000000000 --- a/hack/boilerplate/boilerplate.sh.txt +++ /dev/null @@ -1,13 +0,0 @@ -# Copyright 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. diff --git a/hack/boilerplate/boilerplate_test.py b/hack/boilerplate/boilerplate_test.py deleted file mode 100644 index 38e6a412b..000000000 --- a/hack/boilerplate/boilerplate_test.py +++ /dev/null @@ -1,52 +0,0 @@ -#!/usr/bin/env python - -# Copyright The containerd 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. - -import boilerplate -import unittest -import StringIO -import os -import sys - -class TestBoilerplate(unittest.TestCase): - """ - Note: run this test from the hack/boilerplate directory. - - $ python -m unittest boilerplate_test - """ - - def test_boilerplate(self): - os.chdir("test/") - - class Args(object): - def __init__(self): - self.filenames = [] - self.rootdir = "." - self.boilerplate_dir = "../" - self.verbose = True - - # capture stdout - old_stdout = sys.stdout - sys.stdout = StringIO.StringIO() - - boilerplate.args = Args() - ret = boilerplate.main() - - output = sorted(sys.stdout.getvalue().split()) - - sys.stdout = old_stdout - - self.assertEquals( - output, ['././fail.go', '././fail.py']) diff --git a/hack/boilerplate/test/fail.go b/hack/boilerplate/test/fail.go deleted file mode 100644 index 75fed70e5..000000000 --- a/hack/boilerplate/test/fail.go +++ /dev/null @@ -1,19 +0,0 @@ -/* - Copyright The containerd Authors. - - fail - - 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. -*/ - -package main diff --git a/hack/boilerplate/test/fail.py b/hack/boilerplate/test/fail.py deleted file mode 100644 index 93ab146c6..000000000 --- a/hack/boilerplate/test/fail.py +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env python - -# Copyright The Kubernetes Authors. -# -# failed -# -# 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. diff --git a/hack/boilerplate/test/pass.py b/hack/boilerplate/test/pass.py deleted file mode 100644 index c85a2520f..000000000 --- a/hack/boilerplate/test/pass.py +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env python - -# Copyright The containerd 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. - -True diff --git a/hack/update-proto.sh b/hack/update-proto.sh index 4b4eeedca..505bb8d6c 100755 --- a/hack/update-proto.sh +++ b/hack/update-proto.sh @@ -39,7 +39,6 @@ protoc \ --gogo_out=plugins=grpc:${API_ROOT} ${API_ROOT}/api.proto # Update boilerplate for the generated file. -echo "$(cat hack/boilerplate/boilerplate.go.txt ${API_ROOT}/api.pb.go)" > ${API_ROOT}/api.pb.go -sed -i".bak" "s/Copyright AUTHORS/Copyright $(date '+%Y') The containerd Authors/g" ${API_ROOT}/api.pb.go +echo "$(cat hack/boilerplate/boilerplate ${API_ROOT}/api.pb.go)" > ${API_ROOT}/api.pb.go gofmt -l -s -w ${API_ROOT}/api.pb.go diff --git a/hack/verify-boilerplate.sh b/hack/verify-boilerplate.sh deleted file mode 100755 index 602ac641a..000000000 --- a/hack/verify-boilerplate.sh +++ /dev/null @@ -1,56 +0,0 @@ -#!/bin/bash - -# Copyright The containerd 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 - -# This script is intended to be used via subtree in a top-level directory: -# / -# repo-infra/ -# verify/ - -REPO_ROOT=$(dirname "${BASH_SOURCE}")/.. - -boilerDir="${REPO_ROOT}/hack/boilerplate" -boiler="${boilerDir}/boilerplate.py" - -files_need_boilerplate=($(${boiler} "$@")) - -# Run boilerplate.py unit tests -unitTestOut="$(mktemp)" -trap cleanup EXIT -cleanup() { - rm "${unitTestOut}" -} - -pushd "${boilerDir}" >/dev/null -if ! python -m unittest boilerplate_test 2>"${unitTestOut}"; then - echo "boilerplate_test.py failed" - echo - cat "${unitTestOut}" - exit 1 -fi -popd >/dev/null - -# Run boilerplate check -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