Skip to content

Commit

Permalink
run copyright header check recursively
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
radditude committed Aug 30, 2023
1 parent 400f6ee commit 2a5ff48
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 15 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 0 additions & 13 deletions copyright_headers.go

This file was deleted.

17 changes: 17 additions & 0 deletions scripts/copyright.sh
Original file line number Diff line number Diff line change
@@ -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 change: 1 addition & 0 deletions tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 2a5ff48

Please sign in to comment.