Skip to content

Commit

Permalink
add lint and go gen to CI
Browse files Browse the repository at this point in the history
Add linter to CI (allow CI to continue of fail, since currently a lot of
errors and warnings arise)
Added separate linter YAML setting for CI.

Add CI step to check `go generate` are up to date.

Added sequence ordering to make sure lint and go gen run before tests,
which runs before build.

Signed-off-by: Hamza El-Saawy <hamzaelsaawy@microsoft.com>
  • Loading branch information
helsaawy committed Aug 13, 2022
1 parent d68e55c commit 6e077ef
Show file tree
Hide file tree
Showing 3 changed files with 187 additions and 9 deletions.
79 changes: 70 additions & 9 deletions .github/workflows/ci.yml
Expand Up @@ -3,27 +3,88 @@ on:
- push
- pull_request

env:
GO_VERSION: "1.17"

jobs:
lint:
name: Lint
runs-on: "windows-2019"
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: ${{ env.GO_VERSION }}
cache: true
- name: Run golangci-lint
uses: golangci/golangci-lint-action@v3
with:
args: >-
--verbose
--timeout=8m
--max-issues-per-linter=0
--max-same-issues=0
--modules-download-mode=readonly
continue-on-error: true # remove when lint issues are fixed

go-generate:
name: Validate Go Generate
runs-on: "windows-2019"
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: ${{ env.GO_VERSION }}
cache: true
- name: Verify generated files
shell: powershell
run: |
Write-Output "::group::go generate"
go generate -x .\...
Write-Output "::endgroup::"
if ($LASTEXITCODE -ne 0) {
Write-Output "::error title=Go Generate::Error running go generate."
exit $LASTEXITCODE
}
git add -N .
Write-Output "::group::git diff"
git diff --stat --exit-code
Write-Output "::endgroup::"
if ($LASTEXITCODE -ne 0) {
Write-Output "::error ::Generated files are not up to date. Please run ``go generate .\...``."
exit $LASTEXITCODE
}
test:
name: Run Tests
needs:
- lint
- go-generate
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [windows-2019, windows-2022, ubuntu-latest]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: '^1.17.0'
go-version: ${{ env.GO_VERSION }}
cache: true
- run: go test -gcflags=all=-d=checkptr -v ./...

build:
runs-on: 'windows-2019'
name: Build Repo
needs:
- test
runs-on: "windows-2019"
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: '^1.17.0'

go-version: ${{ env.GO_VERSION }}
cache: true
- run: go build ./pkg/etw/sample/
- run: go build ./tools/etw-provider-gen/
- run: go build ./wim/validate/
- run: go build ./tools/mkwinsyscall/
- run: go build ./wim/validate/
109 changes: 109 additions & 0 deletions .golangci.yml
@@ -0,0 +1,109 @@
run:
timeout: 2m

issues:
max-same-issues: 5
max-issues-per-linter: 100

linters:
enable:
# style
- containedctx # struct contains a context
- goconst # strings that should be constants
- misspell
- predeclared # shadows predeclared Go identifier
- stylecheck
- unconvert # unnecessary conversions

# bugs and others...
- contextcheck # function uses a non-inherited context
- dupl # code clone
- errname # erorrs are named correctly
- errorlint # errors not wrapped for 1.13
- exhaustive # check exhaustiveness of enum switch statements
- exportloopref # using loop variable pointer
- gofmt
- gosec # security
- nestif # deeply nested ifs
- nilerr # returns nil even with non-nil error
- prealloc # slices that can be pre-allocated
- revive # golint replacement
- structcheck # unused struct fields
- unparam # unused function params

linters-settings:
govet:
enable-all: true
check-shadowing: true
settings:
shadow:
strict: false
stylecheck:
checks:
- all
initialisms:
# defaults (https://staticcheck.io/docs/configuration/options/#initialisms)
- ACL
- API
- ASCII
- CPU
- CSS
- DNS
- EOF
- GUID
- HTML
- HTTP
- HTTPS
- ID
- IP
- JSON
- QPS
- RAM
- RPC
- SLA
- SMTP
- SQL
- SSH
- TCP
- TLS
- TTL
- UDP
- UI
- GID
- UID
- UUID
- URI
- URL
- UTF8
- VM
- XML
- XMPP
- XSRF
- XSS
- SIP
- RTP
- AMQP
- DB
- TS

# specific
- CID
- CRI
- CTRD
- ETW
- GCS
- GMSA
- HCS
- IO
- LCOW
- LPAC
- LTSC
- MMIO
- OCI
- RX
- TX
- VHD
- VHDX
- VMID
- VPCI
- WCOW
8 changes: 8 additions & 0 deletions .vscode/settings.json
@@ -0,0 +1,8 @@
{
"go.lintTool": "golangci-lint",
"go.lintOnSave": "package",
"go.lintFlags": [
"--fix",
"--verbose",
],
}

0 comments on commit 6e077ef

Please sign in to comment.