Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ jobs:
steps:
- checkout
- run: go test -mod=readonly ./...
- run: find -name '*.go' -not -name '*.pb.go' | xargs go run utils/license.go --
62 changes: 62 additions & 0 deletions utils/license.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Copyright 2018 Google LLC
//
// 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
//
// https://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.

// +build ignore

package main

import (
"bytes"
"flag"
"io"
"log"
"os"
)

var sentinels = [][]byte{
[]byte("Copyright"),
[]byte("Google LLC"),
[]byte("Apache License"),
[]byte("limitations under the License."),
}

func main() {
flag.Parse()

var buf [600]byte
exitCode := 0

for _, fname := range flag.Args() {
f, err := os.Open(fname)
if err != nil {
log.Fatal(err)
}

n, err := io.ReadFull(f, buf[:])
if err != nil && err != io.EOF && err != io.ErrUnexpectedEOF {
log.Fatal(err)
}

f.Close()

for _, s := range sentinels {
if bytes.Index(buf[:n], s) < 0 {
log.Printf("file doesn't have license header, can't find %q: %s", s, fname)
exitCode = 1
}
}
}

os.Exit(exitCode)
}