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"