Skip to content

Commit

Permalink
setup golangci-lint and fix the suggestions (#852)
Browse files Browse the repository at this point in the history
  • Loading branch information
defbin authored Jul 28, 2023
1 parent fbc9d63 commit 5e2b9cc
Show file tree
Hide file tree
Showing 101 changed files with 2,107 additions and 1,381 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/bin/
/dev/
e2e-tests/docker/backups/pbm/
48 changes: 24 additions & 24 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ on:
branches:
- main
paths-ignore:
- 'e2e-tests/**'
- 'packaging/**'
- 'version/**'
- "e2e-tests/**"
- "packaging/**"
- "version/**"

jobs:
test:
Expand All @@ -35,30 +35,30 @@ jobs:
test: [logical, physical, incremental, external]
env:
PBM_BRANCH: ${{ github.event.inputs.pbm_branch || 'main' }}
GO_VER: ${{ github.event.inputs.go_ver || 'bullseye' }}
GO_VER: ${{ github.event.inputs.go_ver || '1.19-bullseye' }}
PR_NUMBER: ${{ github.event.number|| github.event.inputs.pr_ver }}

steps:
- name: Checkout testing repo
uses: actions/checkout@v3
with:
repository: Percona-QA/psmdb-testing
ref: ${{ github.event.inputs.tests_ver || 'main'}}
path: psmdb-testing
- name: Checkout testing repo
uses: actions/checkout@v3
with:
repository: Percona-QA/psmdb-testing
ref: ${{ github.event.inputs.tests_ver || 'main'}}
path: psmdb-testing

- name: Setup environment with PSMDB ${{ matrix.psmdb }} for PBM PR/branch ${{ github.event.pull_request.title || env.PR_NUMBER || env.PBM_BRANCH }}
run: |
PSMDB=percona/percona-server-mongodb:${{ matrix.psmdb }} docker-compose build
docker-compose up -d
working-directory: psmdb-testing/pbm-functional/pytest
- name: Setup environment with PSMDB ${{ matrix.psmdb }} for PBM PR/branch ${{ github.event.pull_request.title || env.PR_NUMBER || env.PBM_BRANCH }}
run: |
PSMDB=percona/percona-server-mongodb:${{ matrix.psmdb }} docker-compose build
docker-compose up -d
working-directory: psmdb-testing/pbm-functional/pytest

- name: Test ${{ matrix.test }} backup/restore on PSMDB ${{ matrix.psmdb }} for PBM PR/branch ${{ github.event.pull_request.title || env.PR_NUMBER || env.PBM_BRANCH }}
run: |
docker-compose run test pytest -s --junitxml=junit.xml -k ${{ matrix.test }}
working-directory: psmdb-testing/pbm-functional/pytest
- name: Test ${{ matrix.test }} backup/restore on PSMDB ${{ matrix.psmdb }} for PBM PR/branch ${{ github.event.pull_request.title || env.PR_NUMBER || env.PBM_BRANCH }}
run: |
docker-compose run test pytest -s --junitxml=junit.xml -k ${{ matrix.test }}
working-directory: psmdb-testing/pbm-functional/pytest

- name: Publish Test Report
uses: mikepenz/action-junit-report@v3
if: success() || failure()
with:
report_paths: '**/junit.xml'
- name: Publish Test Report
uses: mikepenz/action-junit-report@v3
if: success() || failure()
with:
report_paths: "**/junit.xml"
28 changes: 15 additions & 13 deletions .github/workflows/reviewdog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
- uses: actions/setup-go@v4
with:
go-version: '1.19'
go-version: "1.19"
- name: test
run: go test -v ./...

Expand All @@ -20,7 +20,6 @@ jobs:
- name: spellcheck
uses: reviewdog/action-shellcheck@v1
with:
github_token: ${{ secrets.github_token }}
reporter: github-pr-review
exclude: |
*/.git/*
Expand All @@ -36,7 +35,6 @@ jobs:
- name: misspell
uses: reviewdog/action-misspell@v1
with:
github_token: ${{ secrets.github_token }}
reporter: github-pr-review
locale: "US"
exclude: |
Expand All @@ -52,30 +50,34 @@ jobs:
- name: alex
uses: reviewdog/action-alex@v1
with:
github_token: ${{ secrets.github_token }}
reporter: github-pr-review

golangci-lint:
name: runner / golangci-lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
- uses: actions/setup-go@v4
with:
go-version: '1.19'
go-version: "1.19"
- name: golangci-lint
uses: reviewdog/action-golangci-lint@v2
with:
reporter: github-pr-check
reporter: github-pr-review
level: error

gofmt:
name: runner / gofmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
- uses: actions/setup-go@v4
with:
go-version: '1.19'
- run: gofmt -w -s $(find . -not -path "*/vendor/*" -name "*.go")
go-version: "1.19"
- run: go install golang.org/x/tools/cmd/goimports@latest
- run: go install mvdan.cc/gofumpt@latest
- run: goimports -w -local "github.com/percona" $(find . -not -path "*/vendor/*" -name "*.go")
- run: gofumpt -w -extra $(find . -not -path "*/vendor/*" -name "*.go")
- uses: reviewdog/action-suggester@v1
with:
tool_name: gofmt
Expand All @@ -85,9 +87,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
- uses: actions/setup-go@v4
with:
go-version: '1.19'
go-version: "1.19"
- run: go install mvdan.cc/sh/v3/cmd/shfmt@latest
- run: shfmt -f . | grep -v 'vendor' | xargs shfmt -w -s
- name: suggester / shfmt
Expand Down
14 changes: 7 additions & 7 deletions .github/workflows/trivy.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: Scan
on:
push:
branches: [ "main" ]
branches: ["main"]
pull_request:
branches: [ "main" ]
branches: ["main"]
jobs:
scan:
name: Trivy
Expand All @@ -15,13 +15,13 @@ jobs:
- name: Run Trivy vulnerability scanner in repo mode
uses: aquasecurity/trivy-action@master
with:
scan-type: 'fs'
scan-type: "fs"
ignore-unfixed: true
format: 'sarif'
output: 'trivy-results.sarif'
severity: 'CRITICAL,HIGH'
format: "sarif"
output: "trivy-results.sarif"
severity: "CRITICAL,HIGH"

- name: Upload Trivy scan results to GitHub Security tab
uses: github/codeql-action/upload-sarif@v2
with:
sarif_file: 'trivy-results.sarif'
sarif_file: "trivy-results.sarif"
9 changes: 3 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
*.000
*.upx
.env
.vscode
.vscode/*
!.vscode/settings.json
.idea/
test-out
/dist
/bin
/bin/
/dev/
e2e-tests/docker/keyFile
e2e-tests/docker/backups/pbm
Expand Down
33 changes: 33 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
linters:
presets:
- bugs
- error
- unused
enable:
- errname
- predeclared
- stylecheck
# - ireturn
# - gomnd
- misspell
- nilerr
- nilnil
- lll
# - gocritic
- typecheck
# - goconst
- gochecknoinits
# - forbidigo
- nonamedreturns
disable:
- contextcheck
- exhaustive
- gosec
- wrapcheck

linters-settings:
govet:
disable:
- composites
misspell:
locale: "US"
32 changes: 32 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"[go]": {
"editor.defaultFormatter": "golang.go",
"editor.insertSpaces": false,
"editor.tabSize": 4,
},
"[json][jsonc][yaml]": {
"editor.insertSpaces": true,
"editor.tabSize": 2,
},
"[shellscript]": {
"editor.insertSpaces": false,
"editor.tabSize": 4,
},
"files.eol": "\n",
"files.insertFinalNewline": true,
"files.trimFinalNewlines": true,
"files.trimTrailingWhitespace": true,
"go.formatTool": "gofumpt",
"go.lintTool": "golangci-lint",
"go.useLanguageServer": true,
"gopls": {
"analyses": {
"composites": false,
"deepequalerrors": false
},
"formatting.gofumpt": true,
"formatting.local": "github.com/percona"
},
"groupImports.onSave": true,
"shellformat.flag": "-bn -ci -s"
}
Loading

0 comments on commit 5e2b9cc

Please sign in to comment.