Skip to content

Commit 10e6ff7

Browse files
committed
*: add license header checking and tweak Makefile
- 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 <[email protected]>
1 parent 6b5d048 commit 10e6ff7

File tree

15 files changed

+285
-290
lines changed

15 files changed

+285
-290
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
oci-validate-examples
21
code-of-conduct.md
32
oci-image-tool
3+
oci-validate-examples
4+
output

.header

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright 2016 The Linux Foundation
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+

.tool/check-license

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env bash
2+
3+
set -o errexit
4+
set -o nounset
5+
set -o pipefail
6+
7+
ret=0
8+
9+
for file in $(find . -type f -iname '*.go' ! -path './vendor/*'); do
10+
(head -n3 "${file}" | grep -Eq "(Copyright|generated|GENERATED)") || (echo -e "${file}:missing license header" && ret=1)
11+
done
12+
13+
exit $ret

.tool/lint

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env bash
2+
3+
set -o errexit
4+
set -o nounset
5+
set -o pipefail
6+
7+
if [ ! $(command -v gometalinter) ]; then
8+
go get github.com/alecthomas/gometalinter
9+
gometalinter --update --install
10+
fi
11+
12+
for d in $(find . -type d -not -iwholename '*.git*' -a -not -iname '.tool'); do
13+
gometalinter \
14+
--exclude='error return value not checked.*(Close|Log|Print).*\(errcheck\)$' \
15+
--exclude='.*_test\.go:.*error return value not checked.*\(errcheck\)$' \
16+
--exclude='duplicate of.*_test.go.*\(dupl\)$' \
17+
--exclude='schema/fs.go' \
18+
--disable=aligncheck \
19+
--disable=gotype \
20+
--cyclo-over=20 \
21+
--tests \
22+
--deadline=10s "${d}"
23+
done

.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@ install: true
1818
script:
1919
- git-validation -run DCO,short-subject -v -range ${TRAVIS_COMMIT_RANGE}
2020
- make lint
21+
- make check-license
2122
- make test
2223
- make oci-image-tool

Makefile

+11-1
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,17 @@ oci-validate-examples: cmd/oci-validate-examples/main.go
6464
oci-image-tool:
6565
go build ./cmd/oci-image-tool
6666

67+
schema-fs:
68+
@echo "generating schema fs"
69+
@cd schema && echo -e "$$(cat ../.header)\n\n$$(go generate)" > fs.go
70+
71+
check-license:
72+
@echo "checking license headers"
73+
@./.tool/check-license
74+
6775
lint:
68-
for d in $(shell find . -type d -not -iwholename '*.git*'); do echo "$${d}" && ./lint "$${d}"; done
76+
@echo "checking lint"
77+
@./.tool/lint
6978

7079
test:
7180
go test -race ./...
@@ -78,6 +87,7 @@ media-types.png: media-types.dot
7887
.PHONY: \
7988
validate-examples \
8089
oci-image-tool \
90+
check-license \
8191
lint \
8292
docs \
8393
test

cmd/oci-image-tool/main.go

+14
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
// Copyright 2016 The Linux Foundation
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
115
package main
216

317
import (

cmd/oci-image-tool/validate.go

+14
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
// Copyright 2016 The Linux Foundation
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
115
package main
216

317
import (

lint

-22
This file was deleted.

schema/doc.go

+14
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,16 @@
1+
// Copyright 2016 The Linux Foundation
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
115
// Package schema defines the OCI image media types, schema definitions and validation functions.
216
package schema

0 commit comments

Comments
 (0)