mirror of
https://github.com/arangodb/kube-arangodb.git
synced 2024-12-14 11:57:37 +00:00
[Maintenace] Add license range rewrite command (#1248)
This commit is contained in:
parent
09a28f0056
commit
78c33e608e
3 changed files with 86 additions and 2 deletions
|
@ -9,6 +9,7 @@
|
||||||
- (Improvement) Update arangosync-client package for new API capabilities and better HTTP handling
|
- (Improvement) Update arangosync-client package for new API capabilities and better HTTP handling
|
||||||
- (Maintenance) Fix generated license dates
|
- (Maintenance) Fix generated license dates
|
||||||
- (Improvement) Reduce CI on Commit Travis runs
|
- (Improvement) Reduce CI on Commit Travis runs
|
||||||
|
- (Maintenance) Add license range rewrite command
|
||||||
|
|
||||||
## [1.2.24](https://github.com/arangodb/kube-arangodb/tree/1.2.24) (2023-01-25)
|
## [1.2.24](https://github.com/arangodb/kube-arangodb/tree/1.2.24) (2023-01-25)
|
||||||
- (Bugfix) Fix deployment creation on ARM64
|
- (Bugfix) Fix deployment creation on ARM64
|
||||||
|
|
11
Makefile
11
Makefile
|
@ -232,6 +232,10 @@ license-verify:
|
||||||
license-range-verify:
|
license-range-verify:
|
||||||
@GOBIN=$(GOPATH)/bin go run "$(ROOT)/tools/license/" $(SOURCES)
|
@GOBIN=$(GOPATH)/bin go run "$(ROOT)/tools/license/" $(SOURCES)
|
||||||
|
|
||||||
|
.PHONY: license-range
|
||||||
|
license-range:
|
||||||
|
@GOBIN=$(GOPATH)/bin go run "$(ROOT)/tools/license/" -w $(SOURCES)
|
||||||
|
|
||||||
.PHONY: fmt
|
.PHONY: fmt
|
||||||
fmt:
|
fmt:
|
||||||
@echo ">> Ensuring style of files"
|
@echo ">> Ensuring style of files"
|
||||||
|
@ -250,11 +254,11 @@ fmt-verify: license-verify
|
||||||
|
|
||||||
.PHONY: linter
|
.PHONY: linter
|
||||||
linter:
|
linter:
|
||||||
$(GOPATH)/bin/golangci-lint run --build-tags "$(RELEASE_MODE)" $(foreach LINT_EXCLUDE,$(LINT_EXCLUDES),--exclude '$(LINT_EXCLUDE)') ./...
|
@$(GOPATH)/bin/golangci-lint run --build-tags "$(RELEASE_MODE)" $(foreach LINT_EXCLUDE,$(LINT_EXCLUDES),--exclude '$(LINT_EXCLUDE)') ./...
|
||||||
|
|
||||||
.PHONY: linter-fix
|
.PHONY: linter-fix
|
||||||
linter-fix:
|
linter-fix:
|
||||||
$(GOPATH)/bin/golangci-lint run --fix --build-tags "$(RELEASE_MODE)" $(foreach LINT_EXCLUDE,$(LINT_EXCLUDES),--exclude '$(LINT_EXCLUDE)') ./...
|
@$(GOPATH)/bin/golangci-lint run --fix --build-tags "$(RELEASE_MODE)" $(foreach LINT_EXCLUDE,$(LINT_EXCLUDES),--exclude '$(LINT_EXCLUDE)') ./...
|
||||||
|
|
||||||
.PHONY: build
|
.PHONY: build
|
||||||
build: docker manifests
|
build: docker manifests
|
||||||
|
@ -607,3 +611,6 @@ generate-proto:
|
||||||
--go_out=. --go_opt=paths=source_relative \
|
--go_out=. --go_opt=paths=source_relative \
|
||||||
--go-grpc_out=. --go-grpc_opt=paths=source_relative \
|
--go-grpc_out=. --go-grpc_opt=paths=source_relative \
|
||||||
$(PROTOSOURCES)
|
$(PROTOSOURCES)
|
||||||
|
|
||||||
|
.PHONY: fix
|
||||||
|
fix: license-range fmt license
|
|
@ -29,12 +29,24 @@ type dateRange struct {
|
||||||
func mainE() error {
|
func mainE() error {
|
||||||
// Ensure that all files have proper license dates
|
// Ensure that all files have proper license dates
|
||||||
|
|
||||||
|
rewrite := false
|
||||||
|
|
||||||
|
for _, a := range os.Args[1:] {
|
||||||
|
if a == "-w" {
|
||||||
|
rewrite = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
files := map[string]int{}
|
files := map[string]int{}
|
||||||
|
|
||||||
currentHeaders := map[string]dateRange{}
|
currentHeaders := map[string]dateRange{}
|
||||||
|
|
||||||
// Extract current dates
|
// Extract current dates
|
||||||
for _, file := range os.Args[1:] {
|
for _, file := range os.Args[1:] {
|
||||||
|
if file == "-w" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
var out bytes.Buffer
|
var out bytes.Buffer
|
||||||
|
|
||||||
cmd := exec.Command("git", "log", "-n", "1", "--pretty=format:%cd", file)
|
cmd := exec.Command("git", "log", "-n", "1", "--pretty=format:%cd", file)
|
||||||
|
@ -79,6 +91,21 @@ func mainE() error {
|
||||||
valid = false
|
valid = false
|
||||||
} else if date < c.from || date > c.to {
|
} else if date < c.from || date > c.to {
|
||||||
println(fmt.Sprintf("Date %d not in range %d-%d for %s. File has beed modified", date, c.from, c.to, file))
|
println(fmt.Sprintf("Date %d not in range %d-%d for %s. File has beed modified", date, c.from, c.to, file))
|
||||||
|
if rewrite {
|
||||||
|
println("Rewrite file")
|
||||||
|
|
||||||
|
q := fmt.Sprintf("// Copyright %d-%d ArangoDB GmbH, Cologne, Germany", c.from, c.to)
|
||||||
|
if c.from == c.to {
|
||||||
|
q = fmt.Sprintf("// Copyright %d ArangoDB GmbH, Cologne, Germany", c.to)
|
||||||
|
}
|
||||||
|
|
||||||
|
changed, err := rewriteLicenseDates(file, q, fmt.Sprintf("// Copyright %d-%d ArangoDB GmbH, Cologne, Germany", c.from, date))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
} else if changed {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
valid = false
|
valid = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -90,6 +117,55 @@ func mainE() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func rewriteLicenseDates(file string, from, to string) (bool, error) {
|
||||||
|
data, changed, err := readNewLicenseDates(file, from, to)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if !changed {
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := os.WriteFile(file, data, 0644); err != nil {
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func readNewLicenseDates(file string, from, to string) ([]byte, bool, error) {
|
||||||
|
readFile, err := os.Open(file)
|
||||||
|
if err != nil {
|
||||||
|
return nil, false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
defer readFile.Close()
|
||||||
|
|
||||||
|
fileScanner := bufio.NewScanner(readFile)
|
||||||
|
|
||||||
|
fileScanner.Split(bufio.ScanLines)
|
||||||
|
|
||||||
|
q := bytes.NewBuffer(nil)
|
||||||
|
|
||||||
|
got := false
|
||||||
|
|
||||||
|
for fileScanner.Scan() {
|
||||||
|
t := fileScanner.Text()
|
||||||
|
if t == from {
|
||||||
|
got = true
|
||||||
|
q.WriteString(to)
|
||||||
|
} else {
|
||||||
|
q.WriteString(t)
|
||||||
|
}
|
||||||
|
q.WriteString("\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
return q.Bytes(), got, nil
|
||||||
|
}
|
||||||
|
|
||||||
func extractFileLicenseData(file string) (int, int, error) {
|
func extractFileLicenseData(file string) (int, int, error) {
|
||||||
readFile, err := os.Open(file)
|
readFile, err := os.Open(file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in a new issue