-
Notifications
You must be signed in to change notification settings - Fork 0
Add copyright header enforcement #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| 9.2.0 | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| name: "main" | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
| pull_request: | ||
| push: | ||
| branches: | ||
| - main | ||
|
|
||
| concurrency: | ||
| group: ${{ github.workflow }}.${{ github.ref }} | ||
| cancel-in-progress: ${{ github.event_name == 'pull_request' }} | ||
|
|
||
| jobs: | ||
| copyright-headers-check: | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 10 | ||
|
|
||
| env: | ||
| ARCH: "x64" | ||
| OS: "linux" | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - name: Check copyright headers | ||
| if: success() | ||
| run: | | ||
| bazel run //infra/internal/check_copyright_headers |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| module(name = "any2bazel", version = "0.1.0") | ||
|
|
||
| bazel_dep(name = "rules_go", version = "0.63.0") |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| load("@rules_go//go:go_binary.bzl", "go_binary") | ||
| load("@rules_go//go:go_library.bzl", "go_library") | ||
|
|
||
| go_library( | ||
| name = "check_copyright_headers_lib", | ||
| srcs = ["main.go"], | ||
| importpath = "github.com/EngFlow/auth/infra/internal/check_copyright_headers", | ||
| visibility = ["//infra:__subpackages__"], | ||
| ) | ||
|
|
||
| go_binary( | ||
| name = "check_copyright_headers", | ||
| embed = [":check_copyright_headers_lib"], | ||
| visibility = ["//infra:__subpackages__"], | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,146 @@ | ||
| // Copyright 2026 EngFlow Inc. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package main | ||
|
|
||
| import ( | ||
| "errors" | ||
| "fmt" | ||
| "io" | ||
| "os" | ||
| "os/exec" | ||
| "path/filepath" | ||
| "regexp" | ||
| "sort" | ||
| "strings" | ||
| ) | ||
|
|
||
| var ( | ||
| skipRegexps = []*regexp.Regexp{ | ||
| regexp.MustCompile(`(^|/)LICENSE$`), | ||
| regexp.MustCompile(`(^|/)AUTHORS$`), | ||
| regexp.MustCompile(`^MODULE\.bazel\.lock$`), | ||
| regexp.MustCompile(`MODULE\.bazel$`), | ||
| regexp.MustCompile(`(/|^)BUILD$`), | ||
| regexp.MustCompile(`\.bazelrc$`), | ||
| regexp.MustCompile(`bazelrc.txt$`), | ||
| regexp.MustCompile(`^\.bazelversion$`), | ||
| regexp.MustCompile(`^\.gitignore$`), | ||
| regexp.MustCompile(`BUILD(?:\.bazel)$`), | ||
| regexp.MustCompile(`\.bzl$`), | ||
| regexp.MustCompile(`\.md$`), | ||
| regexp.MustCompile(`\.tsv$`), | ||
| regexp.MustCompile(`\.patch$`), | ||
| regexp.MustCompile(`\.json$`), | ||
| regexp.MustCompile(`\.yaml$`), | ||
| regexp.MustCompile(`\.yml$`), | ||
| } | ||
| copyrightHeaderRe = regexp.MustCompile( | ||
| `(#|//|::) Copyright [0-9-]+ EngFlow Inc\. | ||
| (#|//|::) | ||
| (#|//|::) Licensed under the Apache License, Version 2\.0 \(the "License"\); | ||
| (#|//|::) you may not use this file except in compliance with the License\. | ||
| (#|//|::) You may obtain a copy of the License at | ||
| (#|//|::) | ||
| (#|//|::) http://www\.apache\.org/licenses/LICENSE-2\.0 | ||
| (#|//|::) | ||
| (#|//|::) Unless required by applicable law or agreed to in writing, software | ||
| (#|//|::) distributed under the License is distributed on an "AS IS" BASIS, | ||
| (#|//|::) WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied\. | ||
| (#|//|::) See the License for the specific language governing permissions and | ||
| (#|//|::) limitations under the License\. | ||
| `) | ||
| ) | ||
|
|
||
| // listSourceFiles returns the list of files that git cares about in the current | ||
| // commit. | ||
| func listSourceFiles(repoRoot string) ([]string, error) { | ||
| cmd := exec.Command("git", "ls-tree", "-r", "--name-only", "HEAD") | ||
| cmd.Dir = repoRoot | ||
| output, err := cmd.Output() | ||
| if err != nil { | ||
| return nil, fmt.Errorf("`git ls-tree` failed: %w", err) | ||
| } | ||
| return strings.Split(strings.TrimSpace(string(output)), "\n"), nil | ||
| } | ||
|
|
||
| // filterStrings returns strings in `universe` that don't match any regexps in | ||
| // `remove`. | ||
| func filterStrings(universe []string, remove []*regexp.Regexp) []string { | ||
| var filtered []string | ||
| nextStr: | ||
| for _, s := range universe { | ||
| for _, r := range remove { | ||
| if r.MatchString(s) { | ||
| continue nextStr | ||
| } | ||
| } | ||
| filtered = append(filtered, s) | ||
| } | ||
| return filtered | ||
| } | ||
|
|
||
| // checkCopyright scans for a valid copyright header within a file, returning | ||
| // an error if no valid copyright header is found. | ||
| func checkCopyright(path string) error { | ||
| f, err := os.Open(path) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| defer f.Close() | ||
| r := io.LimitReader(f, 1000) | ||
| s, e := io.ReadAll(r) | ||
| if e != nil { | ||
| return e | ||
| } | ||
| if !copyrightHeaderRe.MatchString(string(s)) { | ||
| return fmt.Errorf("%s: missing copyright header", path) | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| func run() error { | ||
| workspaceRoot := os.Getenv("BUILD_WORKSPACE_DIRECTORY") | ||
| if workspaceRoot == "" { | ||
| return fmt.Errorf("$BUILD_WORKSPACE_DIRECTORY is not set; please run this script via `bazel run`") | ||
| } | ||
| srcFiles, err := listSourceFiles(workspaceRoot) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| srcFiles = filterStrings(srcFiles, skipRegexps) | ||
|
|
||
| var errs []error | ||
| for _, f := range srcFiles { | ||
| if err := checkCopyright(filepath.Join(workspaceRoot, f)); err != nil { | ||
| errs = append(errs, err) | ||
| continue | ||
| } | ||
| } | ||
|
|
||
| if len(errs) == 0 { | ||
| return nil | ||
| } | ||
|
|
||
| sort.Slice(errs, func(i, j int) bool { return errs[i].Error() < errs[j].Error() }) | ||
| return fmt.Errorf("copyright header check failed:\n%v", errors.Join(errs...)) | ||
| } | ||
|
|
||
| func main() { | ||
| if err := run(); err != nil { | ||
| fmt.Fprintf(os.Stderr, "ERROR: %v\n", err) | ||
| os.Exit(1) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.