From 6557272280be7f2dbb738819044b19f98d08b532 Mon Sep 17 00:00:00 2001 From: Hamza El-Saawy Date: Wed, 10 Aug 2022 13:53:17 -0400 Subject: [PATCH] add lint and go gen to CI 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 --- .github/.golangci.yml | 45 +++++++++++++++++++++ .github/workflows/ci.yml | 87 +++++++++++++++++++++++++++++++++++----- 2 files changed, 123 insertions(+), 9 deletions(-) create mode 100644 .github/.golangci.yml diff --git a/.github/.golangci.yml b/.github/.golangci.yml new file mode 100644 index 00000000..58715d25 --- /dev/null +++ b/.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 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 63a15efe..c29c71ec 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,27 +3,96 @@ on: - push - pull_request +env: + GO_VERSIONS: '' + jobs: + setenv: + name: Set Outputs for Matrix Strategies + runs-on: "windows-2019" + 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/ \ No newline at end of file + - run: go build ./tools/mkwinsyscall/ + - run: go build ./wim/validate/