From c76869e50b1b4eb4818e2b64b9ece71a1ebeea70 Mon Sep 17 00:00:00 2001 From: jpflueger Date: Thu, 26 Mar 2020 12:14:01 -0600 Subject: [PATCH 1/3] adding script to validate copyright headers --- Makefile | 6 +++++- pkg/helpers/rand.go | 3 +++ pkg/resourcemanager/apim/apimgmt/apimgmt.go | 17 ++-------------- .../apim/apimgmt/apimgmt_test.go | 17 +++------------- pkg/resourcemanager/apim/apimgmt/manager.go | 17 ++-------------- .../apim/apimgmt/suite_test.go | 17 ++-------------- scripts/validate-copyright-headers.sh | 20 +++++++++++++++++++ 7 files changed, 37 insertions(+), 60 deletions(-) create mode 100755 scripts/validate-copyright-headers.sh diff --git a/Makefile b/Makefile index 37eac79ffe1..907d3f6c35e 100644 --- a/Makefile +++ b/Makefile @@ -108,6 +108,10 @@ delete: kubectl delete -f config/crd/bases kustomize build config/default | kubectl delete -f - +# Validate copyright headers +validate-copyright-headers: + @./scripts/validate-copyright-headers.sh + # Generate manifests for helm and package them up helm-chart-manifests: manifests kustomize build ./config/default -o ./charts/azure-service-operator/templates @@ -125,7 +129,7 @@ fmt: go fmt ./... # Run go vet against code -vet: +vet: go vet ./... # Generate code diff --git a/pkg/helpers/rand.go b/pkg/helpers/rand.go index 3dcb6fc72e1..edd9a89c33e 100644 --- a/pkg/helpers/rand.go +++ b/pkg/helpers/rand.go @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + // copied from github.com/Azure/open-service-broker-azure/ package helpers diff --git a/pkg/resourcemanager/apim/apimgmt/apimgmt.go b/pkg/resourcemanager/apim/apimgmt/apimgmt.go index c4244b5f3fc..abce2a47542 100644 --- a/pkg/resourcemanager/apim/apimgmt/apimgmt.go +++ b/pkg/resourcemanager/apim/apimgmt/apimgmt.go @@ -1,18 +1,5 @@ -/* -MIT License - -Copyright (c) Microsoft Corporation. All rights reserved. - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. -*/ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. package apimgmt diff --git a/pkg/resourcemanager/apim/apimgmt/apimgmt_test.go b/pkg/resourcemanager/apim/apimgmt/apimgmt_test.go index f8af79ea676..f8d00dc19f9 100644 --- a/pkg/resourcemanager/apim/apimgmt/apimgmt_test.go +++ b/pkg/resourcemanager/apim/apimgmt/apimgmt_test.go @@ -1,19 +1,8 @@ -/* -MIT License +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. -Copyright (c) Microsoft Corporation. All rights reserved. - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. -*/ // +build all apimgmt + package apimgmt import ( diff --git a/pkg/resourcemanager/apim/apimgmt/manager.go b/pkg/resourcemanager/apim/apimgmt/manager.go index 371b993f214..e24779e45d9 100644 --- a/pkg/resourcemanager/apim/apimgmt/manager.go +++ b/pkg/resourcemanager/apim/apimgmt/manager.go @@ -1,18 +1,5 @@ -/* -MIT License - -Copyright (c) Microsoft Corporation. All rights reserved. - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. -*/ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. package apimgmt diff --git a/pkg/resourcemanager/apim/apimgmt/suite_test.go b/pkg/resourcemanager/apim/apimgmt/suite_test.go index 01bcb012ca8..d266bd86ec0 100644 --- a/pkg/resourcemanager/apim/apimgmt/suite_test.go +++ b/pkg/resourcemanager/apim/apimgmt/suite_test.go @@ -1,18 +1,5 @@ -/* -MIT License - -Copyright (c) Microsoft Corporation. All rights reserved. - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. -*/ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. package apimgmt diff --git a/scripts/validate-copyright-headers.sh b/scripts/validate-copyright-headers.sh new file mode 100755 index 00000000000..71345670f40 --- /dev/null +++ b/scripts/validate-copyright-headers.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash +# +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT license. + +set -euo pipefail + +echo "==> Checking copyright headers <==" + +regx="(Copyright.*Microsoft.*Licensed.*MIT)|(generated)" +files=$(find . -type f -iname '*.go' ! -path './vendor/*' ! -path './hack/tools/*' ! -path './test/e2e/vendor/*') +licRes=$(for file in $files; do + head -4 "$file" | tr -d '\n' | grep -Eiq "$regx" || echo "$file"; + done) + +if [ -n "$licRes" ]; then + echo "Copyright header check failed:"; + echo "${licRes}"; + exit 1; +fi \ No newline at end of file From bce3f6f9477685f62ae5f59be76c31fc32e444eb Mon Sep 17 00:00:00 2001 From: jpflueger Date: Thu, 26 Mar 2020 12:19:27 -0600 Subject: [PATCH 2/3] adding step to pipeline for copyright validation --- devops/azure-pipelines.yaml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/devops/azure-pipelines.yaml b/devops/azure-pipelines.yaml index 1ed8b68838c..1d909b87c62 100644 --- a/devops/azure-pipelines.yaml +++ b/devops/azure-pipelines.yaml @@ -99,6 +99,12 @@ steps: # REQUEUE_AFTER: $(REQUEUE_AFTER) # workingDirectory: '$(MODULE_PATH)' +- script: | + make validate-copyright-headers + continueOnError: 'false' + displayName: 'Validate Copyright Headers' + workingDirectory: '$(MODULE_PATH)' + - script: | set -e GO111MODULE="on" go get sigs.k8s.io/kind@v0.4.0 @@ -136,7 +142,7 @@ steps: REQUEUE_AFTER: $(REQUEUE_AFTER) KUBEBUILDER_ASSETS: $(MODULE_PATH)/bin BUILD_ID: $(Build.BuildId) - workingDirectory: '$(MODULE_PATH)' + workingDirectory: '$(MODULE_PATH)' - task: AzureCLI@2 displayName: 'Clean up Azure Resources' From 6e18ec3ba2998276b765dc80d4dc874a8b8a9b6d Mon Sep 17 00:00:00 2001 From: jpflueger Date: Fri, 27 Mar 2020 09:52:53 -0600 Subject: [PATCH 3/3] build flag causing vet error --- pkg/resourcemanager/apim/apimgmt/apimgmt_test.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/pkg/resourcemanager/apim/apimgmt/apimgmt_test.go b/pkg/resourcemanager/apim/apimgmt/apimgmt_test.go index f8d00dc19f9..dab131d2512 100644 --- a/pkg/resourcemanager/apim/apimgmt/apimgmt_test.go +++ b/pkg/resourcemanager/apim/apimgmt/apimgmt_test.go @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -// +build all apimgmt - package apimgmt import (