From 2a5ff48e3d0342c1978adf97c63414fa06c8b9ed Mon Sep 17 00:00:00 2001 From: CJ Horton Date: Wed, 16 Aug 2023 12:49:09 -0700 Subject: [PATCH 1/3] run copyright header check recursively We have a few directories in this repo that will be remaining MPL licensed (the provider protocol definitions). This is something that the copywrite tool does not support out of the box - we need to run the tool for each directory that contains a .copywrite.hcl file in order to make sure that new files have the correct header. To avoid adding yet more boilerplate with a `copyright_headers.go` file in each package, let's move the copyright check to its own make target and script the process of discovering all directories with copywrite config. --- .github/workflows/checks.yml | 4 ++-- Makefile | 3 +++ copyright_headers.go | 13 ------------- scripts/copyright.sh | 17 +++++++++++++++++ tools.go | 1 + 5 files changed, 23 insertions(+), 15 deletions(-) delete mode 100644 copyright_headers.go create mode 100755 scripts/copyright.sh diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index b5e7b7632c..196763cb89 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -182,9 +182,9 @@ jobs: - name: "Code consistency checks" run: | - make fmtcheck importscheck generate staticcheck exhaustive protobuf + make fmtcheck importscheck generate staticcheck exhaustive protobuf copyright if [[ -n "$(git status --porcelain)" ]]; then - echo >&2 "ERROR: Generated files are inconsistent. Run 'make generate' and 'make protobuf' locally and then commit the updated files." + echo >&2 "ERROR: Generated files are inconsistent. Run 'make generate protobuf copyright' locally and then commit the updated files." git >&2 status --porcelain exit 1 fi diff --git a/Makefile b/Makefile index 84a5dfabf5..f2e17a1193 100644 --- a/Makefile +++ b/Makefile @@ -26,6 +26,9 @@ staticcheck: exhaustive: "$(CURDIR)/scripts/exhaustive.sh" +copyright: + "$(CURDIR)/scripts/copyright.sh" + # Run this if working on the website locally to run in watch mode. website: $(MAKE) -C website website diff --git a/copyright_headers.go b/copyright_headers.go deleted file mode 100644 index f0d87a1080..0000000000 --- a/copyright_headers.go +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright (c) HashiCorp, Inc. -// SPDX-License-Identifier: BUSL-1.1 - -//go:build tools -// +build tools - -package main - -import ( - _ "github.com/hashicorp/copywrite" -) - -//go:generate go run github.com/hashicorp/copywrite headers diff --git a/scripts/copyright.sh b/scripts/copyright.sh new file mode 100755 index 0000000000..8ce102a89f --- /dev/null +++ b/scripts/copyright.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash +# Copyright (c) HashiCorp, Inc. +# SPDX-License-Identifier: BUSL-1.1 + +# This script checks that all files have the appropriate copyright headers, +# according to their nearest .copywrite.hcl config file. The copyright tool +# does not natively support repos with multiple licenses, so we have to +# script this ourselves. + +set -euo pipefail + +# Find all directories containing a .copywrite.hcl config file +directories=$(find . -type f -name '.copywrite.hcl' -execdir pwd \;) + +for dir in $directories; do + cd $dir && go run github.com/hashicorp/copywrite headers +done \ No newline at end of file diff --git a/tools.go b/tools.go index 6a3eeb8389..702c7c8937 100644 --- a/tools.go +++ b/tools.go @@ -11,6 +11,7 @@ package tools // Go toolchain to see that we need to include them in go.mod and go.sum. import ( + _ "github.com/hashicorp/copywrite" _ "github.com/nishanths/exhaustive/cmd/exhaustive" _ "golang.org/x/tools/cmd/stringer" _ "honnef.co/go/tools/cmd/staticcheck" From 813369f317738f5920c8e557e5fd5e30063aaa6a Mon Sep 17 00:00:00 2001 From: CJ Horton Date: Thu, 17 Aug 2023 19:02:34 -0700 Subject: [PATCH 2/3] stick with go generate check instead --- .github/workflows/checks.yml | 4 ++-- Makefile | 3 --- copyright_headers.go | 6 ++++++ docs/plugin-protocol/copyright_headers.go | 6 ++++++ internal/tfplugin5/copyright_headers.go | 6 ++++++ internal/tfplugin6/copyright_headers.go | 6 ++++++ scripts/copyright.sh | 17 ----------------- 7 files changed, 26 insertions(+), 22 deletions(-) create mode 100644 copyright_headers.go create mode 100644 docs/plugin-protocol/copyright_headers.go create mode 100644 internal/tfplugin5/copyright_headers.go create mode 100644 internal/tfplugin6/copyright_headers.go delete mode 100755 scripts/copyright.sh diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index 196763cb89..b5e7b7632c 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -182,9 +182,9 @@ jobs: - name: "Code consistency checks" run: | - make fmtcheck importscheck generate staticcheck exhaustive protobuf copyright + make fmtcheck importscheck generate staticcheck exhaustive protobuf if [[ -n "$(git status --porcelain)" ]]; then - echo >&2 "ERROR: Generated files are inconsistent. Run 'make generate protobuf copyright' locally and then commit the updated files." + echo >&2 "ERROR: Generated files are inconsistent. Run 'make generate' and 'make protobuf' locally and then commit the updated files." git >&2 status --porcelain exit 1 fi diff --git a/Makefile b/Makefile index f2e17a1193..84a5dfabf5 100644 --- a/Makefile +++ b/Makefile @@ -26,9 +26,6 @@ staticcheck: exhaustive: "$(CURDIR)/scripts/exhaustive.sh" -copyright: - "$(CURDIR)/scripts/copyright.sh" - # Run this if working on the website locally to run in watch mode. website: $(MAKE) -C website website diff --git a/copyright_headers.go b/copyright_headers.go new file mode 100644 index 0000000000..7900ce788d --- /dev/null +++ b/copyright_headers.go @@ -0,0 +1,6 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: BUSL-1.1 + +package main + +//go:generate go run github.com/hashicorp/copywrite headers diff --git a/docs/plugin-protocol/copyright_headers.go b/docs/plugin-protocol/copyright_headers.go new file mode 100644 index 0000000000..06fb0e9441 --- /dev/null +++ b/docs/plugin-protocol/copyright_headers.go @@ -0,0 +1,6 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-1.1 + +package plugin_protocol + +//go:generate go run github.com/hashicorp/copywrite headers diff --git a/internal/tfplugin5/copyright_headers.go b/internal/tfplugin5/copyright_headers.go new file mode 100644 index 0000000000..ff7f9ca2d6 --- /dev/null +++ b/internal/tfplugin5/copyright_headers.go @@ -0,0 +1,6 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-1.1 + +package tfplugin5 + +//go:generate go run github.com/hashicorp/copywrite headers diff --git a/internal/tfplugin6/copyright_headers.go b/internal/tfplugin6/copyright_headers.go new file mode 100644 index 0000000000..493fe6f362 --- /dev/null +++ b/internal/tfplugin6/copyright_headers.go @@ -0,0 +1,6 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-1.1 + +package tfplugin6 + +//go:generate go run github.com/hashicorp/copywrite headers diff --git a/scripts/copyright.sh b/scripts/copyright.sh deleted file mode 100755 index 8ce102a89f..0000000000 --- a/scripts/copyright.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env bash -# Copyright (c) HashiCorp, Inc. -# SPDX-License-Identifier: BUSL-1.1 - -# This script checks that all files have the appropriate copyright headers, -# according to their nearest .copywrite.hcl config file. The copyright tool -# does not natively support repos with multiple licenses, so we have to -# script this ourselves. - -set -euo pipefail - -# Find all directories containing a .copywrite.hcl config file -directories=$(find . -type f -name '.copywrite.hcl' -execdir pwd \;) - -for dir in $directories; do - cd $dir && go run github.com/hashicorp/copywrite headers -done \ No newline at end of file From 1706d643d67cf0ddb9a282ca804db965b5a2f04b Mon Sep 17 00:00:00 2001 From: CJ Horton Date: Wed, 30 Aug 2023 14:55:24 -0700 Subject: [PATCH 3/3] more missing headers --- internal/backend/local/test.go | 3 +++ internal/backend/remote-state/s3/errors.go | 3 +++ internal/cloudplugin/binary.go | 3 +++ internal/cloudplugin/binary_test.go | 3 +++ internal/cloudplugin/client.go | 3 +++ internal/cloudplugin/client_test.go | 3 +++ internal/cloudplugin/errors.go | 3 +++ internal/cloudplugin/testing.go | 3 +++ internal/command/cloud_test.go | 3 +++ internal/releaseauth/all.go | 3 +++ internal/releaseauth/all_test.go | 3 +++ internal/releaseauth/checksum.go | 3 +++ internal/releaseauth/doc.go | 3 +++ internal/releaseauth/hash.go | 3 +++ internal/releaseauth/matching_sums.go | 3 +++ internal/releaseauth/signature.go | 3 +++ 16 files changed, 48 insertions(+) diff --git a/internal/backend/local/test.go b/internal/backend/local/test.go index ca8654477e..76892d18e4 100644 --- a/internal/backend/local/test.go +++ b/internal/backend/local/test.go @@ -1,3 +1,6 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: BUSL-1.1 + package local import ( diff --git a/internal/backend/remote-state/s3/errors.go b/internal/backend/remote-state/s3/errors.go index 1b2e93bf99..065e652c9a 100644 --- a/internal/backend/remote-state/s3/errors.go +++ b/internal/backend/remote-state/s3/errors.go @@ -1,3 +1,6 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: BUSL-1.1 + package s3 import ( diff --git a/internal/cloudplugin/binary.go b/internal/cloudplugin/binary.go index a4d2744c97..6bf5bbb458 100644 --- a/internal/cloudplugin/binary.go +++ b/internal/cloudplugin/binary.go @@ -1,3 +1,6 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: BUSL-1.1 + package cloudplugin import ( diff --git a/internal/cloudplugin/binary_test.go b/internal/cloudplugin/binary_test.go index e1839ab463..40140015b5 100644 --- a/internal/cloudplugin/binary_test.go +++ b/internal/cloudplugin/binary_test.go @@ -1,3 +1,6 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: BUSL-1.1 + package cloudplugin import ( diff --git a/internal/cloudplugin/client.go b/internal/cloudplugin/client.go index 872ad516d8..54f7e04809 100644 --- a/internal/cloudplugin/client.go +++ b/internal/cloudplugin/client.go @@ -1,3 +1,6 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: BUSL-1.1 + package cloudplugin import ( diff --git a/internal/cloudplugin/client_test.go b/internal/cloudplugin/client_test.go index 9898da3c3a..8e73afe622 100644 --- a/internal/cloudplugin/client_test.go +++ b/internal/cloudplugin/client_test.go @@ -1,3 +1,6 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: BUSL-1.1 + package cloudplugin import ( diff --git a/internal/cloudplugin/errors.go b/internal/cloudplugin/errors.go index a208aa3802..4c3d9755b0 100644 --- a/internal/cloudplugin/errors.go +++ b/internal/cloudplugin/errors.go @@ -1,3 +1,6 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: BUSL-1.1 + package cloudplugin import ( diff --git a/internal/cloudplugin/testing.go b/internal/cloudplugin/testing.go index 4724a42a12..cafe688279 100644 --- a/internal/cloudplugin/testing.go +++ b/internal/cloudplugin/testing.go @@ -1,3 +1,6 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: BUSL-1.1 + package cloudplugin import ( diff --git a/internal/command/cloud_test.go b/internal/command/cloud_test.go index 0a72353959..2edd8f2bcf 100644 --- a/internal/command/cloud_test.go +++ b/internal/command/cloud_test.go @@ -1,3 +1,6 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: BUSL-1.1 + package command import ( diff --git a/internal/releaseauth/all.go b/internal/releaseauth/all.go index 2b69bac4c5..95c027d138 100644 --- a/internal/releaseauth/all.go +++ b/internal/releaseauth/all.go @@ -1,3 +1,6 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: BUSL-1.1 + package releaseauth // Authenticator is a generic interface for interacting with types that authenticate diff --git a/internal/releaseauth/all_test.go b/internal/releaseauth/all_test.go index bd8dc38032..4daab7c410 100644 --- a/internal/releaseauth/all_test.go +++ b/internal/releaseauth/all_test.go @@ -1,3 +1,6 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: BUSL-1.1 + package releaseauth import ( diff --git a/internal/releaseauth/checksum.go b/internal/releaseauth/checksum.go index a30248609b..d46addd5f7 100644 --- a/internal/releaseauth/checksum.go +++ b/internal/releaseauth/checksum.go @@ -1,3 +1,6 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: BUSL-1.1 + package releaseauth import ( diff --git a/internal/releaseauth/doc.go b/internal/releaseauth/doc.go index a6ad34f4fd..23d8c36bf9 100644 --- a/internal/releaseauth/doc.go +++ b/internal/releaseauth/doc.go @@ -1,3 +1,6 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: BUSL-1.1 + // Package releaseauth helps authenticates archives downloaded from a service // like releases.hashicorp.com by providing some simple authentication tools: // diff --git a/internal/releaseauth/hash.go b/internal/releaseauth/hash.go index ed95743485..1a8105d610 100644 --- a/internal/releaseauth/hash.go +++ b/internal/releaseauth/hash.go @@ -1,3 +1,6 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: BUSL-1.1 + package releaseauth import ( diff --git a/internal/releaseauth/matching_sums.go b/internal/releaseauth/matching_sums.go index a44a41fab6..6201269e34 100644 --- a/internal/releaseauth/matching_sums.go +++ b/internal/releaseauth/matching_sums.go @@ -1,3 +1,6 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: BUSL-1.1 + package releaseauth import "fmt" diff --git a/internal/releaseauth/signature.go b/internal/releaseauth/signature.go index f1124b65c6..d70071a406 100644 --- a/internal/releaseauth/signature.go +++ b/internal/releaseauth/signature.go @@ -1,3 +1,6 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: BUSL-1.1 + package releaseauth import (