diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index efd782f..667d855 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -1,5 +1,15 @@ name: build -on: [push, pull_request] + +on: + push: + branches: + - master + - main + tags: + - 'v*' + pull_request: + + jobs: test-build: @@ -7,10 +17,10 @@ jobs: runs-on: ubuntu-latest steps: - - name: Set up Go 1.13 + - name: Set up Go uses: actions/setup-go@v1 with: - go-version: 1.13 + go-version: 1.16 id: go - name: Check out code into the Go module directory @@ -23,3 +33,13 @@ jobs: - name: Build run: go build ./... + + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v2 + # only release on tags + if: success() && startsWith(github.ref, 'refs/tags/') + with: + version: v0.156.1 + args: release --rm-dist + env: + GITHUB_TOKEN: ${{ secrets.FAILLINT_ACTIONS_BOT_TOKEN }} diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 0000000..5d6945a --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,37 @@ +project_name: faillint +release: + prerelease: auto # don't publish release with -rc1,-pre, etc suffixes +builds: + - env: + - CGO_ENABLED=0 + goos: + - linux + - windows + - darwin + ldflags: + - -s -w -X main.version={{.Version}} -X main.date={{.Date}} + binary: "faillint" +nfpms: + - maintainer: Fatih Arslan + description: Report unwanted Go import path and declaration usages + homepage: https://github.com/fatih/faillint + license: BSD 3-Clause + formats: + - deb + - rpm + replacements: + darwin: macOS +archives: + - replacements: + darwin: macOS + format_overrides: + - goos: windows + format: zip +snapshot: + name_template: "{{ .Tag }}-next" +changelog: + sort: asc + filters: + exclude: + - '^docs:' + - '^test:' diff --git a/README.md b/README.md index 32d9ca3..4a653a6 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,30 @@ you can configure to fail on such single function of `fmt` as well. ## Install ```bash -go get github.com/fatih/faillint +go install github.com/fatih/faillint@latest +``` + +## Example + +Assume we have the following file: + +```go +package a + +import ( + "errors" +) + +func foo() error { + return errors.New("bar!") +} +``` + +Let's run `faillint` to check if `errors` import is used and report it: + +``` +$ faillint -paths "errors=github.com/pkg/errors" a.go +a.go:4:2: package "errors" shouldn't be imported, suggested: "github.com/pkg/errors" ``` ## Usage @@ -121,29 +144,6 @@ func foo() error { } ``` -## Example - -Assume we have the following file: - -```go -package a - -import ( - "errors" -) - -func foo() error { - return errors.New("bar!") -} -``` - -Let's run `faillint` to check if `errors` import is used and report it: - -``` -$ faillint -paths "errors=github.com/pkg/errors" a.go -a.go:4:2: package "errors" shouldn't be imported, suggested: "github.com/pkg/errors" -``` - ## The need for this tool? Most of these checks should be probably detected during the review cycle. But diff --git a/main.go b/main.go index 780dec5..54bf45b 100644 --- a/main.go +++ b/main.go @@ -1,10 +1,31 @@ package main import ( + "flag" + "fmt" + "os" + "github.com/fatih/faillint/faillint" "golang.org/x/tools/go/analysis/singlechecker" ) +var ( + version string + date string +) + func main() { + // this is a small hack to implement the -V flag that is part of + // go/analysis framework. It'll allow us to print the version with -V, but + // the --help message will print the flags of the analyzer + ff := flag.NewFlagSet("faillint", flag.ContinueOnError) + v := ff.Bool("V", false, "print version and exit") + ff.Usage = func() {} + ff.Parse(os.Args[1:]) + if *v { + fmt.Printf("faillint version %s (%s)\n", version, date) + os.Exit(0) + } + singlechecker.Main(faillint.NewAnalyzer()) }