From 577083639c0106b2d4d953513c1c6f05d621801a Mon Sep 17 00:00:00 2001 From: "Bo-Yi.Wu" Date: Sun, 18 Dec 2022 09:51:31 +0800 Subject: [PATCH] chore(CI/CD): add golangci-lint for github actions https://github.com/appleboy/gorush/issues/704 Signed-off-by: Bo-Yi.Wu --- .github/FUNDING.yml | 2 +- .github/dependabot.yml | 10 +++++ .github/workflows/{codeql.yml => codeql.yaml} | 11 ++++-- .github/workflows/go.yml | 37 ++++++++++++++++++ .github/workflows/goreleaser.yml | 34 ++++++++++++++++ .golangci.yml | 39 +++++++++++++++++++ .revive.toml | 25 ------------ Makefile | 6 --- 8 files changed, 129 insertions(+), 35 deletions(-) create mode 100644 .github/dependabot.yml rename .github/workflows/{codeql.yml => codeql.yaml} (78%) create mode 100644 .github/workflows/go.yml create mode 100644 .github/workflows/goreleaser.yml create mode 100644 .golangci.yml delete mode 100644 .revive.toml diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index 20feafd..ebda473 100644 --- a/.github/FUNDING.yml +++ b/.github/FUNDING.yml @@ -1,6 +1,6 @@ # These are supported funding model platforms -github: # appleboy +github: appleboy patreon: # Replace with a single Patreon username open_collective: gorush ko_fi: # Replace with a single Ko-fi username diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..632e8eb --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,10 @@ +version: 2 +updates: + - package-ecosystem: github-actions + directory: / + schedule: + interval: weekly + - package-ecosystem: gomod + directory: / + schedule: + interval: weekly diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yaml similarity index 78% rename from .github/workflows/codeql.yml rename to .github/workflows/codeql.yaml index bc1780d..00c7345 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yaml @@ -1,3 +1,8 @@ +# For most projects, this workflow file will not need changing; you simply need +# to commit it to your repository. +# +# You may wish to alter this file to override the set of languages analyzed, +# or to provide custom queries or build logic. name: "CodeQL" on: @@ -32,11 +37,11 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v2 + uses: actions/checkout@v3 # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL - uses: github/codeql-action/init@v1 + uses: github/codeql-action/init@v2 with: languages: ${{ matrix.language }} # If you wish to specify custom queries, you can do so here or in a config file. @@ -45,4 +50,4 @@ jobs: # queries: ./path/to/local/query, your-org/your-repo/queries@main - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v1 + uses: github/codeql-action/analyze@v2 diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml new file mode 100644 index 0000000..75b4cac --- /dev/null +++ b/.github/workflows/go.yml @@ -0,0 +1,37 @@ +name: Run Tests + +on: + push: + branches: + - master + pull_request: + branches: + - master + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - name: Setup go + uses: actions/setup-go@v3 + with: + go-version: '^1' + - name: Checkout repository + uses: actions/checkout@v3 + - name: Setup golangci-lint + uses: golangci/golangci-lint-action@v3 + with: + version: latest + args: --verbose + - uses: hadolint/hadolint-action@v2.1.0 + name: hadolint for Dockerfile.linux.amd64 + with: + dockerfile: docker/Dockerfile.linux.amd64 + - uses: hadolint/hadolint-action@v2.1.0 + name: hadolint for Dockerfile.linux.arm64 + with: + dockerfile: docker/Dockerfile.linux.arm64 + - uses: hadolint/hadolint-action@v2.1.0 + name: hadolint for Dockerfile.linux.arm + with: + dockerfile: docker/Dockerfile.linux.arm diff --git a/.github/workflows/goreleaser.yml b/.github/workflows/goreleaser.yml new file mode 100644 index 0000000..654585b --- /dev/null +++ b/.github/workflows/goreleaser.yml @@ -0,0 +1,34 @@ +name: Goreleaser + +on: + push: + tags: + - '*' + +permissions: + contents: write + +jobs: + goreleaser: + runs-on: ubuntu-latest + steps: + - + name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + - + name: Set up Go + uses: actions/setup-go@v3 + with: + go-version: 1.17 + - + name: Run GoReleaser + uses: goreleaser/goreleaser-action@v3 + with: + # either 'goreleaser' (default) or 'goreleaser-pro' + 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..3e40d74 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,39 @@ +linters: + enable-all: false + disable-all: true + fast: false + enable: + - bodyclose + - depguard + - dogsled + - dupl + - errcheck + - exportloopref + - exhaustive + - gochecknoinits + - goconst + - gocritic + - gocyclo + - gofmt + - goimports + - goprintffuncname + - gosec + - gosimple + - govet + - ineffassign + - lll + - misspell + - nakedret + - noctx + - nolintlint + - staticcheck + - stylecheck + - typecheck + - unconvert + - unparam + - unused + - whitespace + - gofumpt + +run: + timeout: 3m diff --git a/.revive.toml b/.revive.toml deleted file mode 100644 index 74743d5..0000000 --- a/.revive.toml +++ /dev/null @@ -1,25 +0,0 @@ -ignoreGeneratedHeader = false -severity = "warning" -confidence = 0.8 -errorCode = 1 -warningCode = 1 - -[rule.blank-imports] -[rule.context-as-argument] -[rule.context-keys-type] -[rule.dot-imports] -[rule.error-return] -[rule.error-strings] -[rule.error-naming] -[rule.exported] -[rule.if-return] -[rule.increment-decrement] -[rule.var-naming] -[rule.var-declaration] -[rule.package-comments] -[rule.range] -[rule.receiver-naming] -[rule.time-naming] -[rule.unexported-return] -[rule.indent-error-flow] -[rule.errorf] diff --git a/Makefile b/Makefile index 8ef3827..9836e2f 100644 --- a/Makefile +++ b/Makefile @@ -69,12 +69,6 @@ embedmd: fi embedmd -d *.md -lint: - @hash revive > /dev/null 2>&1; if [ $$? -ne 0 ]; then \ - $(GO) install github.com/mgechev/revive@v1.0.5; \ - fi - revive -config .revive.toml ./... || exit 1 - .PHONY: install install: $(GOFILES) $(GO) install -v -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)'