Merge pull request #313 from vmware-tanzu/copyright-year

Copyright year validation in linter and pre-commit hook
This commit is contained in:
Margo Crawford 2021-01-06 09:08:19 -08:00 committed by GitHub
commit e7884d8793
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 42 additions and 2 deletions

View File

@ -61,8 +61,12 @@ linters-settings:
lines: 150
statements: 50
goheader:
values:
regexp:
# YYYY or YYYY-YYYY
YEARS: \d\d\d\d(-\d\d\d\d)?
template: |-
Copyright 2020 the Pinniped contributors. All Rights Reserved.
Copyright {{YEARS}} the Pinniped contributors. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
goimports:
local-prefixes: go.pinniped.dev

View File

@ -15,3 +15,9 @@ repos:
- id: detect-private-key
exclude: testdata
- id: mixed-line-ending
- repo: local
hooks:
- id: validate-copyright-year
name: Validate copyright year
entry: hack/check-copyright-year.sh
language: script

4
.pre-commit-hooks.yaml Normal file
View File

@ -0,0 +1,4 @@
- id: validate-copyright-year
name: Validate copyright year
entry: hack/check-copyright-year.sh
language: script

26
hack/check-copyright-year.sh Executable file
View File

@ -0,0 +1,26 @@
#!/bin/bash
# Copyright 2021 the Pinniped contributors. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Check if copyright statements include the current year
#
files=$(git diff --cached --name-only)
year=$(date +"%Y")
for f in $files; do
head -10 $f | grep -i copyright 2>&1 1>/dev/null || continue
if ! grep -i -e "copyright.*$year" $f 2>&1 1>/dev/null; then
missing_copyright_files="$missing_copyright_files $f"
fi
done
if [ -n "$missing_copyright_files" ]; then
echo "Copyright notice should include the year the file was created and the year the file was last modified."
echo "$year is missing in the copyright notice of the following files:"
for f in $missing_copyright_files; do
echo " $f"
done
exit 1
fi

View File

@ -1,4 +1,4 @@
// Copyright 2020 the Pinniped contributors. All Rights Reserved.
// Copyright 2020-2021 the Pinniped contributors. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
package generator