mirror of
https://github.com/hashicorp/terraform.git
synced 2026-02-03 20:50:59 -05:00
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.
This commit is contained in:
parent
400f6ee3f0
commit
2a5ff48e3d
5 changed files with 23 additions and 15 deletions
4
.github/workflows/checks.yml
vendored
4
.github/workflows/checks.yml
vendored
|
|
@ -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
|
||||
|
|
|
|||
3
Makefile
3
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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
17
scripts/copyright.sh
Executable file
17
scripts/copyright.sh
Executable file
|
|
@ -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
|
||||
1
tools.go
1
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"
|
||||
|
|
|
|||
Loading…
Reference in a new issue