-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Initial Commit
- Loading branch information
Showing
17 changed files
with
891 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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,24 @@ | ||
name: Build | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- c4t | ||
- dev | ||
workflow_dispatch: | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v5 | ||
with: | ||
go-version: 1.22 | ||
cache: false | ||
- name: run build | ||
run: go build | ||
|
This file contains 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,27 @@ | ||
name: Lint | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- c4t | ||
- dev | ||
workflow_dispatch: | ||
|
||
jobs: | ||
lint: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v5 | ||
with: | ||
go-version: 1.22 | ||
cache: false | ||
- name: golangci-lint | ||
uses: golangci/golangci-lint-action@v6 | ||
with: | ||
version: v1.55 | ||
- name: run lint | ||
run: golangci-lint run --config .golangci.yml |
This file contains 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,23 @@ | ||
name: Test | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- c4t | ||
- dev | ||
workflow_dispatch: | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v5 | ||
with: | ||
go-version: 1.22 | ||
cache: false | ||
- name: run test | ||
run: go test ./... |
This file contains 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 |
---|---|---|
|
@@ -20,3 +20,8 @@ | |
# Go workspace file | ||
go.work | ||
go.work.sum | ||
|
||
_test-files | ||
.vscode | ||
|
||
camino-license |
This file contains 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,181 @@ | ||
# https://golangci-lint.run/usage/configuration/ | ||
run: | ||
timeout: 10m | ||
|
||
# Enables skipping of directories: | ||
# - vendor$, third_party$, testdata$, examples$, Godeps$, builtin$ | ||
# Default: true | ||
#deprecated | ||
#skip-dirs-use-default: false | ||
|
||
# If set we pass it to "go list -mod={option}". From "go help modules": | ||
# If invoked with -mod=readonly, the go command is disallowed from the implicit | ||
# automatic updating of go.mod described above. Instead, it fails when any changes | ||
# to go.mod are needed. This setting is most useful to check that go.mod does | ||
# not need updates, such as in a continuous integration and testing system. | ||
# If invoked with -mod=vendor, the go command assumes that the vendor | ||
# directory holds the correct copies of dependencies and ignores | ||
# the dependency descriptions in go.mod. | ||
# | ||
# Allowed values: readonly|vendor|mod | ||
# By default, it isn't set. | ||
modules-download-mode: readonly | ||
|
||
output: | ||
# Make issues output unique by line. | ||
# Default: true | ||
uniq-by-line: false | ||
|
||
issues: | ||
# Maximum issues count per one linter. | ||
# Set to 0 to disable. | ||
# Default: 50 | ||
max-issues-per-linter: 0 | ||
|
||
# Enables skipping of directories: | ||
# - vendor$, third_party$, testdata$, examples$, Godeps$, builtin$ | ||
# Default: true | ||
exclude-dirs-use-default: false | ||
|
||
# Maximum count of issues with the same text. | ||
# Set to 0 to disable. | ||
# Default: 3 | ||
max-same-issues: 0 | ||
|
||
linters: | ||
disable-all: true | ||
enable: | ||
- asciicheck | ||
- bodyclose | ||
- depguard | ||
- dupword | ||
- errcheck | ||
- errorlint | ||
- exportloopref | ||
- forbidigo | ||
- goconst | ||
- gocritic | ||
# - goerr113 | ||
- gofmt | ||
- gofumpt | ||
- goimports | ||
# - gomnd | ||
- goprintffuncname | ||
- gosec | ||
- gosimple | ||
- govet | ||
- importas | ||
- ineffassign | ||
# - lll | ||
- misspell | ||
- nakedret | ||
- noctx | ||
- nolintlint | ||
- perfsprint | ||
- prealloc | ||
- predeclared | ||
- revive | ||
- staticcheck | ||
- stylecheck | ||
- tagalign | ||
- typecheck | ||
- unconvert | ||
- unparam | ||
- unused | ||
- usestdlibvars | ||
- whitespace | ||
|
||
linters-settings: | ||
depguard: | ||
rules: | ||
packages: | ||
deny: | ||
- pkg: "io/ioutil" | ||
desc: io/ioutil is deprecated. Use package io or os instead. | ||
- pkg: "github.com/stretchr/testify/assert" | ||
desc: github.com/stretchr/testify/require should be used instead. | ||
- pkg: "github.com/golang/mock/gomock" | ||
desc: go.uber.org/mock/gomock should be used instead. | ||
errorlint: | ||
# Check for plain type assertions and type switches. | ||
asserts: false | ||
# Check for plain error comparisons. | ||
comparison: false | ||
forbidigo: | ||
# Forbid the following identifiers (list of regexp). | ||
forbid: | ||
- 'require\.Error$(# ErrorIs should be used instead)?' | ||
- 'require\.ErrorContains$(# ErrorIs should be used instead)?' | ||
- 'require\.EqualValues$(# Equal should be used instead)?' | ||
- 'require\.NotEqualValues$(# NotEqual should be used instead)?' | ||
- '^(t|b|tb|f)\.(Fatal|Fatalf|Error|Errorf)$(# the require library should be used instead)?' | ||
# Exclude godoc examples from forbidigo checks. | ||
exclude_godoc_examples: false | ||
goimports: | ||
local-prefixes: github.com/ava-labs/avalanchego | ||
gosec: | ||
excludes: | ||
- G107 # Url provided to HTTP request as taint input https://securego.io/docs/rules/g107 | ||
importas: | ||
# Do not allow unaliased imports of aliased packages. | ||
no-unaliased: false | ||
# Do not allow non-required aliases. | ||
no-extra-aliases: false | ||
# List of aliases | ||
alias: | ||
- pkg: github.com/ava-labs/avalanchego/utils/math | ||
alias: safemath | ||
revive: | ||
rules: | ||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#bool-literal-in-expr | ||
- name: bool-literal-in-expr | ||
disabled: false | ||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#early-return | ||
- name: early-return | ||
disabled: false | ||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#empty-lines | ||
- name: empty-lines | ||
disabled: false | ||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#string-format | ||
- name: string-format | ||
disabled: false | ||
arguments: | ||
- ["fmt.Errorf[0]", "/.*%.*/", "no format directive, use errors.New instead"] | ||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#struct-tag | ||
- name: struct-tag | ||
disabled: false | ||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unexported-naming | ||
- name: unexported-naming | ||
disabled: false | ||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unhandled-error | ||
- name: unhandled-error | ||
disabled: false | ||
arguments: | ||
- "fmt\\.Fprint" | ||
- "fmt\\.Fprintf" | ||
- "fmt\\.Print" | ||
- "fmt\\.Printf" | ||
- "fmt\\.Println" | ||
- "math/rand\\.Read" | ||
- "strings\\.Builder\\.WriteString" | ||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unused-parameter | ||
- name: unused-parameter | ||
disabled: false | ||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unused-receiver | ||
- name: unused-receiver | ||
disabled: false | ||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#useless-break | ||
- name: useless-break | ||
disabled: false | ||
staticcheck: | ||
# https://staticcheck.io/docs/options#checks | ||
checks: | ||
- "all" | ||
- "-SA6002" # Storing non-pointer values in sync.Pool allocates memory | ||
- "-SA1019" # Using a deprecated function, variable, constant or field | ||
tagalign: | ||
align: true | ||
sort: true | ||
strict: true | ||
order: | ||
- serialize |
This file contains 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 |
---|---|---|
@@ -1,2 +1,63 @@ | ||
# camino-license | ||
A go package to check license headers and update current year in licence header. | ||
A go package to check license headers. | ||
|
||
|
||
# Usage | ||
`camino-license check --config=config.yaml FILES/DIRS` | ||
It checks license headers in the specified files or directories according to the given configuration file. `FILES/DIRS` are space-separated strings of the path (absolute or relative). | ||
Example: | ||
`camino-license check --config=config.yaml camino-license/cmd camino-license/pkg/camino-license/config.go ` | ||
|
||
|
||
# Configuration | ||
This is an example of a configuration file: | ||
|
||
```yml | ||
default-headers: | ||
- name: avax | ||
header: | | ||
// Copyright (C) 2019-{YEAR}, Ava Labs, Inc. All rights reserved. | ||
// See the file LICENSE for licensing terms. | ||
- name: avax-c4t | ||
header: | | ||
// Copyright (C) 2022-{YEAR}, Chain4Travel AG. All rights reserved. | ||
// | ||
// This file is a derived work, based on ava-labs code whose | ||
// original notices appear below. | ||
// | ||
// It is distributed under the same license conditions as the | ||
// original code from which it is derived. | ||
// | ||
// Much love to the original authors for their work. | ||
// ********************************************************** | ||
// Copyright (C) 2019-{YEAR}, Ava Labs, Inc. All rights reserved. | ||
// See the file LICENSE for licensing terms. | ||
custom-headers: | ||
- name: c4t | ||
header: | | ||
// Copyright (C) 2022-{YEAR}, Chain4Travel AG. All rights reserved. | ||
// See the file LICENSE for licensing terms. | ||
include-paths: | ||
- "./**/camino*.go" | ||
- "./test" | ||
|
||
exclude-paths: | ||
- "./**/camino_visitor2.go" | ||
|
||
``` | ||
`default-headers`: If the file is not specified in the custom-headers paths, then it should contain one of the default headers | ||
|
||
`name`: Name to the header object. It must be unique. **(Required)** | ||
|
||
`header`: License header to be used. **(Required)** | ||
|
||
`custom-headers`: Headers to be used in certain files according to the `include-paths` and `exclude-paths`. | ||
|
||
`include-paths`: list of path pattern to identify files which should contain that custom license header. Use `**`to include all sub directories. Use `*` to include all matching pattern in the same directory. **(Required if custom-headers is specified)** | ||
|
||
`exclude-paths`: list of path pattern to identify files which will be excluded from `include-paths`. Use `**`to include all sub directories. Use `*` to include all matching pattern in the same directory. | ||
|
||
`{YEAR}`: It will be automatically replaced with current year when the check runs. |
This file contains 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,48 @@ | ||
// Copyright (C) 2022-2024, Chain4Travel AG. All rights reserved. | ||
// See the file LICENSE for licensing terms. | ||
|
||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
caminolicense "github.com/chain4travel/camino-license/pkg/camino-license" | ||
config "github.com/chain4travel/camino-license/pkg/config" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// checkCmd represents the check command | ||
var checkCmd = &cobra.Command{ | ||
Use: "check [FLAGS] FILES/DIRS", | ||
Short: "camino-license to check license headers", | ||
Long: `camino-license to check license headers if they are compatible with the templates definded in the configuration file`, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
configFile, _ := cmd.Flags().GetString("config") | ||
headersConfig, err := config.GetHeadersConfig(configFile) | ||
if err != nil { | ||
return err | ||
} | ||
h := caminolicense.CaminoLicenseHeader{Config: headersConfig} | ||
wrongFiles, err := h.CheckLicense(args) | ||
if err != nil { | ||
filesNumber := len(wrongFiles) | ||
if filesNumber == 1 { | ||
fmt.Println("1 file has wrong License Headers:") | ||
} else { | ||
fmt.Println(filesNumber, "files have wrong License Headers:") | ||
} | ||
for _, f := range wrongFiles { | ||
fmt.Println(f.File, " - Reason:", f.Reason) | ||
} | ||
return err | ||
} | ||
fmt.Println("Check has finished successfully. All files have correct License Headers.") | ||
return nil | ||
}, | ||
} | ||
|
||
// adding flags and check to camino-license command | ||
func init() { | ||
checkCmd.Flags().StringP("config", "c", "config.yaml", "configuration yaml file path") | ||
rootCmd.AddCommand(checkCmd) | ||
} |
Oops, something went wrong.