Skip to content

Commit

Permalink
*: add license header checking and tweak Makefile
Browse files Browse the repository at this point in the history
- move file-finding logic into lint check script
- move lint check script into .tool/ subdirectory (similar to
  opencontainers/runtime-spec)
- add a simple `check-license` script to .tool/ to ensure all Go source
  files have an Apache license header, and wire up to `check-license`
  make target
- invoke this from travis
- add `schema-fs` target to generate schema/fs.go (including header)
- add header everywhere it's missing so far
- add `output/` directory to .gitignore

Signed-off-by: Jonathan Boulle <jonathanboulle@gmail.com>
  • Loading branch information
jonboulle committed May 19, 2016
1 parent 6b5d048 commit 10e6ff7
Show file tree
Hide file tree
Showing 15 changed files with 285 additions and 290 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
oci-validate-examples
code-of-conduct.md
oci-image-tool
oci-validate-examples
output
14 changes: 14 additions & 0 deletions .header
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright 2016 The Linux Foundation
//
// 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.

13 changes: 13 additions & 0 deletions .tool/check-license
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash

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

ret=0

for file in $(find . -type f -iname '*.go' ! -path './vendor/*'); do
(head -n3 "${file}" | grep -Eq "(Copyright|generated|GENERATED)") || (echo -e "${file}:missing license header" && ret=1)
done

exit $ret
23 changes: 23 additions & 0 deletions .tool/lint
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env bash

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

if [ ! $(command -v gometalinter) ]; then
go get github.com/alecthomas/gometalinter
gometalinter --update --install
fi

for d in $(find . -type d -not -iwholename '*.git*' -a -not -iname '.tool'); do
gometalinter \
--exclude='error return value not checked.*(Close|Log|Print).*\(errcheck\)$' \
--exclude='.*_test\.go:.*error return value not checked.*\(errcheck\)$' \
--exclude='duplicate of.*_test.go.*\(dupl\)$' \
--exclude='schema/fs.go' \
--disable=aligncheck \
--disable=gotype \
--cyclo-over=20 \
--tests \
--deadline=10s "${d}"
done
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ install: true
script:
- git-validation -run DCO,short-subject -v -range ${TRAVIS_COMMIT_RANGE}
- make lint
- make check-license
- make test
- make oci-image-tool
12 changes: 11 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,17 @@ oci-validate-examples: cmd/oci-validate-examples/main.go
oci-image-tool:
go build ./cmd/oci-image-tool

schema-fs:
@echo "generating schema fs"
@cd schema && echo -e "$$(cat ../.header)\n\n$$(go generate)" > fs.go

check-license:
@echo "checking license headers"
@./.tool/check-license

lint:
for d in $(shell find . -type d -not -iwholename '*.git*'); do echo "$${d}" && ./lint "$${d}"; done
@echo "checking lint"
@./.tool/lint

test:
go test -race ./...
Expand All @@ -78,6 +87,7 @@ media-types.png: media-types.dot
.PHONY: \
validate-examples \
oci-image-tool \
check-license \
lint \
docs \
test
14 changes: 14 additions & 0 deletions cmd/oci-image-tool/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2016 The Linux Foundation
//
// 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

import (
Expand Down
14 changes: 14 additions & 0 deletions cmd/oci-image-tool/validate.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2016 The Linux Foundation
//
// 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

import (
Expand Down
22 changes: 0 additions & 22 deletions lint

This file was deleted.

14 changes: 14 additions & 0 deletions schema/doc.go
Original file line number Diff line number Diff line change
@@ -1,2 +1,16 @@
// Copyright 2016 The Linux Foundation
//
// 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 schema defines the OCI image media types, schema definitions and validation functions.
package schema
Loading

0 comments on commit 10e6ff7

Please sign in to comment.