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 11, 2022
1 parent d68e55c commit 01a6ff2
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 9 deletions.
67 changes: 58 additions & 9 deletions .github/workflows/ci.yml
Expand Up @@ -3,27 +3,76 @@ 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 }}
- name: Run golangci-lint
uses: golangci/golangci-lint-action@v3
with:
args: --verbose --timeout 8m --max-issues-per-linter 0 --max-same-issues 0
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 }}
- 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:
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 }}
- run: go test -gcflags=all=-d=checkptr -v ./...

build:
runs-on: 'windows-2019'
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 }}
- 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/
38 changes: 38 additions & 0 deletions .golangci.yml
@@ -0,0 +1,38 @@
run:
timeout: 2m

output:
print-issued-lines: false

issues:
max-same-issues: 5

linters:
enable:
- containedctx # struct contain a context
- contextcheck # function uses a non-inherited context
- dupl # code clone
- errname # erorrs are named correctly
- errorlint # errors not wrapped for 1.13
- goconst # strings that should be constants
- gofmt
- gosec # security
- misspell
- nestif # deeply nested ifs
- nilnil # returns nil error and invalid value
- prealloc
- predeclared # shadows Go predeclared identifier
- revive # go-lint replacement
- structcheck # unused struct fields
- stylecheck
- unconvert # unnecessary conversions
- unparam # unused function params
- wastedassign
- whitespace # leading and trailing whitespace

linters-settings:
stylecheck:
checks:
- "all"
govet:
enable-all: true

0 comments on commit 01a6ff2

Please sign in to comment.