diff --git a/addlicense/main.go b/addlicense/main.go index a12c6fa..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 @@ -627,13 +637,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/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 a8be5cc..42ebbf3 100644 --- a/cmd/headers.go +++ b/cmd/headers.go @@ -92,15 +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", - } - 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:")