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 9e1dba7
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 9 deletions.
45 changes: 45 additions & 0 deletions .github/.golangci.yml
@@ -0,0 +1,45 @@
run:
timeout: 10m

output:
print-issued-lines: true
print-linter-name: true

issues:
max-same-issues: 0
max-issues-per-linter: 0

linters:
enable:
- containedctx # structs contain a context
# - cyclop # function and package cyclomatic dependencies
- deadcode
- dupl # code clone
- errcheck # unchecked errors
- errname # erorrs are named correctly
- errorlint # errors not wrapped for 1.13
- goconst # strings that should be constants
- gofmt
- gosec # security
- govet
- misspell
- nestif # deeply nested ifs
- nilnil # returns nil error and invalid value
- prealloc
- predeclared # shadows Go predeclared identifier
- revive # golint replacement
- staticcheck # better go vet
- structcheck # unused struct fields
- stylecheck
- thelper # test helpers are annotated as such
- unconvert # unnecessary conversions
- unparam # unused function params
- wastedassign
- whitespace # leading and trailing whitespace

linters-settings:
stylecheck:
checks:
- "all"
govet:
check-shadowing: true
87 changes: 78 additions & 9 deletions .github/workflows/ci.yml
Expand Up @@ -3,27 +3,96 @@ on:
- push
- pull_request

env:
GO_VERSIONS: ''

jobs:
setenv:
name: Set Outputs for Matrix Strategies
runs-on: ubuntu-latest
outputs:
go_version: ${{ steps.set-versions.outputs.matrix }}
steps:
- id: set-versions
run: echo "::set-output name=matrix::[\"1.17\",\"1.18\",\"1.19\"]"

job2:
runs-on: ubuntu-latest
needs: setenv
steps:
- run: echo ${{needs.setenv.outputs.go_versions}}

lint:
name: Lint
needs: setenv
runs-on: windows-2019
strategy:
matrix:
go_version: ${{ fromJSON(needs.setenv.outputs.go_versions) }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go_version }}
- name: Run golangci-lint
uses: golangci/golangci-lint-action@v3
with:
args: --config .github/.golangci.yml --verbose
continue-on-error: true # remove when lint issues are fixed

go-generate:
name: Validate Go Generate
needs: setenv
runs-on: "windows-2019"
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: ${{ env.GO_SETUP_VERSION }}
- name: Verify generated filest
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 $LASTEXITCODEu
}
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_SETUP_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_SETUP_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/

0 comments on commit 9e1dba7

Please sign in to comment.