Merge pull request #313 from vmware-tanzu/copyright-year
Copyright year validation in linter and pre-commit hook
This commit is contained in:
commit
e7884d8793
@ -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
|
||||
|
@ -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
4
.pre-commit-hooks.yaml
Normal 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
26
hack/check-copyright-year.sh
Executable 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
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user