-
Notifications
You must be signed in to change notification settings - Fork 2k
/
copyright.go
71 lines (61 loc) · 1.41 KB
/
copyright.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Copyright (c) The Thanos Authors.
// Licensed under the Apache License 2.0.
package main
import (
"bytes"
"io/ioutil"
"log"
"os"
"path/filepath"
"strings"
)
var (
// license compatible for Go and Proto files.
license = []byte(`// Copyright (c) The Thanos Authors.
// Licensed under the Apache License 2.0.
`)
)
func applyLicenseToProtoAndGo() error {
return filepath.Walk(".", func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
// Filter out stuff that does not need copyright.
if info.IsDir() {
switch path {
case "vendor":
return filepath.SkipDir
}
return nil
}
if strings.HasSuffix(path, ".pb.go") {
return nil
}
if (filepath.Ext(path) != ".proto" && filepath.Ext(path) != ".go") ||
// We copied this file and we want maintain its license (MIT).
path == "pkg/testutil/testutil.go" ||
// Generated file.
path == "pkg/ui/bindata.go" {
return nil
}
b, err := ioutil.ReadFile(filepath.Clean(path))
if err != nil {
return err
}
if !strings.HasPrefix(string(b), string(license)) {
log.Println("file", path, "is missing Copyright header. Adding.")
var bb bytes.Buffer
_, _ = bb.Write(license)
_, _ = bb.Write(b)
if err = ioutil.WriteFile(path, bb.Bytes(), 0600); err != nil {
return err
}
}
return nil
})
}
func main() {
if err := applyLicenseToProtoAndGo(); err != nil {
log.Fatal(err)
}
}