diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index efd782f..33c6dfa 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: @@ -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/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()) }