diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..3938344 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,6 @@ +version: 2 +updates: + - package-ecosystem: "gomod" + directory: "/" + schedule: + interval: "daily" diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml new file mode 100644 index 0000000..dee4d0b --- /dev/null +++ b/.github/workflows/go.yml @@ -0,0 +1,51 @@ +name: Go + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + test: + name: Test + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-go@v3 + with: + go-version: "1.19" + check-latest: true + cache: true + - run: go test -race -failfast ./... + build: + name: Build + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest, macos-latest, windows-latest] + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-go@v3 + with: + go-version: "1.19" + check-latest: true + cache: true + - run: go build ./cmd/gofimports + golangci-lint: + name: golangci-lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - uses: actions/setup-go@v3 + with: + go-version: "1.19" + check-latest: true + cache: true + - uses: golangci/golangci-lint-action@v3 + with: + version: latest diff --git a/.github/workflows/goreleaser.yml b/.github/workflows/goreleaser.yml new file mode 100644 index 0000000..635282e --- /dev/null +++ b/.github/workflows/goreleaser.yml @@ -0,0 +1,29 @@ +name: goreleaser + +on: + push: + tags: + - "*" + +permissions: + contents: write + +jobs: + goreleaser: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - uses: actions/setup-go@v3 + with: + go-version: "1.19" + check-latest: true + cache: true + - uses: goreleaser/goreleaser-action@v3 + with: + distribution: goreleaser + version: latest + args: release --rm-dist + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..4e03a03 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,75 @@ +run: + tests: false + skip-dirs: + - ".*test.*" + - ".*mock.*" + - ".*generated.*" + - ".*example.*" + skip-files: + - ".*Mock.*" + - ".*_mock.*" + - ".*_generated.*" + +output: + sort-results: true + +linters: + disable-all: true + enable: + - errcheck + - gosimple + - govet + - ineffassign + - staticcheck + - typecheck + - unused + - errchkjson + - errname + - errorlint + - execinquery + - gocritic + - goerr113 + - gofumpt + - gosec + - importas + - makezero + - nilnil + - prealloc + - unconvert + fast: true + +linters-settings: + gosec: + excludes: + - G101 + - G112 + - G402 + - G404 + - G501 + - G505 + exclude-generated: true + govet: + check-shadowing: false + disable-all: true + enable: + - assign + - atomic + - bools + - buildtag + - composites + - copylocks + - fieldalignment + - httpresponse + - loopclosure + - lostcancel + - nilfunc + - printf + - unmarshal + - unreachable + - unusedresult + staticcheck: + checks: ["all", "-SA1019"] + gocritic: + enabled-tags: + - style + - performance diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 0000000..c0769d5 --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,21 @@ +before: + hooks: + - go mod tidy +builds: + - main: ./cmd/gofimports + goos: + - linux + - windows + - darwin + goarch: + - amd64 + - arm64 +universal_binaries: + - replace: true +archives: + - format_overrides: + - goos: windows + format: zip +changelog: + skip: false + use: github diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..e07d6d4 --- /dev/null +++ b/Makefile @@ -0,0 +1,27 @@ +.PHONY: all test test-color coverage coverage-cli coverate-html lint format + +all: test-color lint format + go mod tidy + +test: + go test -race -failfast ./... + +test-color: + go install github.com/haunt98/go-test-color@latest + go-test-color -race -failfast ./... + +coverage: + go test -coverprofile=coverage.out ./... + +coverage-cli: coverage + go tool cover -func=coverage.out + +coverage-html: coverage + go tool cover -html=coverage.out + +lint: + golangci-lint run ./... + +format: + go install mvdan.cc/gofumpt@latest + gofumpt -l -w -extra .