Skip to content

Commit

Permalink
Add update/add-license-header makefile target
Browse files Browse the repository at this point in the history
Signed-off-by: torredil <torredil@amazon.com>
  • Loading branch information
torredil committed May 2, 2024
1 parent 09ce01b commit 8223810
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ test/coverage:
tools: bin/aws bin/ct bin/eksctl bin/ginkgo bin/golangci-lint bin/gomplate bin/helm bin/kops bin/kubetest2 bin/mockgen bin/shfmt

.PHONY: update
update: update/gofmt update/kustomize update/mockgen update/gomod update/shfmt
update: update/gofmt update/kustomize update/mockgen update/gomod update/shfmt update/generate-license-header
@echo "All updates succeeded!"

.PHONY: verify
Expand Down Expand Up @@ -263,6 +263,10 @@ update/gomod:
update/shfmt: bin/shfmt
./bin/shfmt -w -i 2 -d ./hack/

.PHONY: update/generate-license-header
update/generate-license-header:
./hack/generate-license-header.sh

## Verifiers
# Linters and similar

Expand Down
20 changes: 20 additions & 0 deletions hack/generate-license-header.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

set -euo pipefail

echo "Adding license header..."

current_year=$(date +%Y)
find . -type d \( -name "deploy" -o -name "charts" \) -prune -o -type f \( -name "*.go" -o -name "*.sh" -o -name "*.yaml" -o -name "*.yml" \) -print | while read -r file; do
case "$file" in
*.go)
comment_prefix="//"
;;
*.sh | *.yaml | *.yml)
comment_prefix="#"
;;
esac
if ! grep -q "The Kubernetes Authors." "$file"; then
echo -e "${comment_prefix} Copyright ${current_year} The Kubernetes Authors.\n${comment_prefix}\n${comment_prefix} Licensed under the Apache License, Version 2.0 (the 'License');\n${comment_prefix} you may not use this file except in compliance with the License.\n${comment_prefix} You may obtain a copy of the License at\n${comment_prefix}\n${comment_prefix} http://www.apache.org/licenses/LICENSE-2.0\n${comment_prefix}\n${comment_prefix} Unless required by applicable law or agreed to in writing, software\n${comment_prefix} distributed under the License is distributed on an 'AS IS' BASIS,\n${comment_prefix} WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n${comment_prefix} See the License for the specific language governing permissions and\n${comment_prefix} limitations under the License.\n" | cat - "$file" >temp && mv temp "$file"
fi
done

0 comments on commit 8223810

Please sign in to comment.