From d899796f65d55c16e55aa2507e9ef1ef6f6a5771 Mon Sep 17 00:00:00 2001 From: Radek Simko Date: Wed, 4 Mar 2026 11:22:35 +0000 Subject: [PATCH 1/2] addlicense: Ignore Terraform lock file by name (not pattern) --- addlicense/main.go | 5 +---- cmd/headers.go | 1 + 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/addlicense/main.go b/addlicense/main.go index a12c6fa..bd56cf9 100644 --- a/addlicense/main.go +++ b/addlicense/main.go @@ -627,13 +627,10 @@ var goGenerated = regexp.MustCompile(`(?m)^.{1,2} Code generated .* DO NOT EDIT\ // cargo raze: ^DO NOT EDIT! Replaced on runs of cargo-raze$ var cargoRazeGenerated = regexp.MustCompile(`(?m)^DO NOT EDIT! Replaced on runs of cargo-raze$`) -// terraform init: ^# This file is maintained automatically by "terraform init"\.$ -var terraformGenerated = regexp.MustCompile(`(?m)^# This file is maintained automatically by "terraform init"\.$`) - // isGenerated returns true if it contains a string that implies the file was // generated. func isGenerated(b []byte) bool { - return goGenerated.Match(b) || cargoRazeGenerated.Match(b) || terraformGenerated.Match(b) + return goGenerated.Match(b) || cargoRazeGenerated.Match(b) } func hasLicense(b []byte) bool { diff --git a/cmd/headers.go b/cmd/headers.go index a8be5cc..b8f593f 100644 --- a/cmd/headers.go +++ b/cmd/headers.go @@ -99,6 +99,7 @@ config, see the "copywrite init" command.`, "**/node_modules/**", ".copywrite.hcl", ".git/**/*.pack", + "**/.terraform.lock.hcl", } ignoredPatterns := lo.Union(conf.Project.HeaderIgnore, autoSkippedPatterns) From 988242f2cb70a757193e85b272823dfebc93c217 Mon Sep 17 00:00:00 2001 From: Radek Simko Date: Wed, 4 Mar 2026 12:03:57 +0000 Subject: [PATCH 2/2] addlicense: Reuse default ignorelist in tests --- addlicense/main.go | 10 ++++++++++ addlicense/main_test.go | 11 ++++++++++- cmd/headers.go | 11 +---------- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/addlicense/main.go b/addlicense/main.go index bd56cf9..b20ecad 100644 --- a/addlicense/main.go +++ b/addlicense/main.go @@ -50,6 +50,16 @@ Flags: ` +// AutoSkippedPatterns represent default ignored search patterns (e.g., GitHub Actions workflows) +var AutoSkippedPatterns = []string{ + ".github/workflows/**", + ".github/dependabot.yml", + "**/node_modules/**", + ".copywrite.hcl", + ".git/**/*.pack", + "**/.terraform.lock.hcl", +} + var ( skipExtensionFlags stringSlice ignorePatterns stringSlice diff --git a/addlicense/main_test.go b/addlicense/main_test.go index 86a9570..1e445fc 100644 --- a/addlicense/main_test.go +++ b/addlicense/main_test.go @@ -53,8 +53,17 @@ func TestInitial(t *testing.T) { for i := 0; i < 2; i++ { t.Logf("run #%d", i) targs := []string{"-test.run=TestInitial"} - cargs := []string{"-l", "apache", "-c", "Google LLC", "-y", "2018", tmp} + cargs := []string{"-l", "apache", "-c", "Google LLC", "-y", "2018"} + + // supply default ignore list to make test consistent with reality + for _, p := range AutoSkippedPatterns { + cargs = append(cargs, "-ignore", p) + } + + cargs = append(cargs, tmp) + c := exec.Command(os.Args[0], append(targs, cargs...)...) + t.Logf("args = %v", cargs) c.Env = []string{"RUNME=1"} if out, err := c.CombinedOutput(); err != nil { t.Fatalf("%v\n%s", err, out) diff --git a/cmd/headers.go b/cmd/headers.go index b8f593f..42ebbf3 100644 --- a/cmd/headers.go +++ b/cmd/headers.go @@ -92,16 +92,7 @@ config, see the "copywrite init" command.`, } cmd.Println("") - // Append default ignored search patterns (e.g., GitHub Actions workflows) - autoSkippedPatterns := []string{ - ".github/workflows/**", - ".github/dependabot.yml", - "**/node_modules/**", - ".copywrite.hcl", - ".git/**/*.pack", - "**/.terraform.lock.hcl", - } - ignoredPatterns := lo.Union(conf.Project.HeaderIgnore, autoSkippedPatterns) + ignoredPatterns := lo.Union(conf.Project.HeaderIgnore, addlicense.AutoSkippedPatterns) // STEP 1: Update existing copyright headers gha.StartGroup("Updating existing copyright headers:")