Improved Code Coverage for utils/errors, awsapi , persistent store #543
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: checks | |
| env: | |
| GO_VERSION: '1.24' | |
| on: | |
| pull_request: | |
| branches: | |
| - master | |
| - stable/** | |
| push: | |
| branches: | |
| - master | |
| - stable/** | |
| permissions: | |
| pull-requests: write | |
| contents: read | |
| # Optional: allow read access to pull request. Use with `only-new-issues` option. | |
| # pull-requests: read | |
| jobs: | |
| base-ref: | |
| name: base-ref | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ github.event.pull_request.base.ref }} | |
| - name: Check base ref | |
| # Case-insensitive matches for: | |
| # 1. Jira references (trid-12345) | |
| # 2. PR numbers (#1234) | |
| # 3. Squashed commit messages (* message) | |
| run: | | |
| git log --format=%B -n 1 | \ | |
| perl -ne 'die "Base ref has invalid commit message" if (/(?:trid|astractl)(?: |-)\d+/ig || /#\d+/ig || /\* \w/ig)' | |
| golangci: | |
| name: linters | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/setup-go@v5 | |
| with: | |
| go-version: ${{ env.GO_VERSION }} | |
| check-latest: true | |
| - uses: actions/checkout@v4 | |
| - name: golangci-lint | |
| # Switch back to the official action after this bug is fixed: https://github.com/golangci/golangci-lint/issues/3107 | |
| run: | | |
| curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v2.1.6 | |
| $(go env GOPATH)/bin/golangci-lint run --output.text.path=github-actions --timeout=15m --verbose | |
| go-mod-tidy: | |
| name: go mod tidy | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-go@v5 | |
| with: | |
| go-version: ${{ env.GO_VERSION }} | |
| check-latest: true | |
| - name: Run go mod tidy | |
| run: | | |
| go mod tidy -compat=$GO_VERSION | |
| git diff --exit-code go.mod go.sum | |
| unit: | |
| strategy: | |
| matrix: | |
| os: [ ubuntu-latest, windows-latest, macos-latest ] | |
| runs-on: ${{matrix.os}} | |
| name: unit tests ${{ matrix.os }} | |
| steps: | |
| - uses: actions/setup-go@v5 | |
| with: | |
| go-version: ${{ env.GO_VERSION }} | |
| check-latest: true | |
| - uses: actions/checkout@v4 | |
| - uses: actions/cache@v4 | |
| with: | |
| # In order: | |
| # * Module download cache | |
| # * Build cache (Linux) | |
| # * Build cache (Mac) | |
| # * Build cache (Windows) | |
| path: | | |
| ~/go/pkg/mod | |
| ~/.cache/go-build | |
| ~/Library/Caches/go-build | |
| ~\AppData\Local\go-build | |
| key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} | |
| restore-keys: | | |
| ${{ runner.os }}-go- | |
| - if: runner.os == 'Windows' | |
| name: Run the tests (on Windows) | |
| run: | | |
| Set-PSDebug -Trace 2 | |
| go version | |
| mkdir ${{ runner.temp }}\${{ runner.os }}-coverage-binary.out | |
| go test -v ./... -covermode=count -- -test.gocoverdir=${{ runner.temp }}\${{ runner.os }}-coverage-binary.out | |
| go tool covdata textfmt -i=${{ runner.temp }}\${{ runner.os }}-coverage-binary.out -o ${{ runner.os }}-coverage.out | |
| - if: runner.os != 'Windows' | |
| name: Run the tests (not on Windows) | |
| run: | | |
| set -x | |
| go version | |
| echo mkdir ${{ runner.temp }}/${{ runner.os }}-coverage-binary.out | |
| mkdir ${{ runner.temp }}/${{ runner.os }}-coverage-binary.out | |
| go test -v ./... -covermode=count -test.gocoverdir=${{ runner.temp }}/${{ runner.os }}-coverage-binary.out | |
| go tool covdata textfmt -i=${{ runner.temp }}/${{ runner.os }}-coverage-binary.out -o ${{ runner.os }}-coverage.out | |
| - if: runner.os != 'Windows' | |
| name: Prepare the artifact | |
| run: | | |
| go tool cover -html=${{ runner.os }}-coverage.out -o ${{ runner.os }}-coverage.html | |
| - name: Get run details | |
| env: | |
| PR_TITLE: ${{ github.event.pull_request.title }} | |
| run: | | |
| echo "PR_Title=$PR_TITLE" | |
| echo "Run_Number=${{ github.run_number }}" | |
| echo "PR_Number=${{ github.event.pull_request.number }}" | |
| - if: runner.os != 'Windows' | |
| name: Upload the artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: "coverage-report-${{ runner.os }}-${{ github.run_number }}.html" | |
| path: ${{ runner.os }}-coverage.html | |
| coveragecomment: | |
| name: UT Code Coverage Report | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Check out code | |
| uses: actions/checkout@v4 | |
| - name: Setup Golang for unit test | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version-file: "${{ github.workspace }}/go.mod" | |
| cache: false | |
| - name: Install dependencies | |
| run: | | |
| go install github.com/t-yuki/gocover-cobertura@latest | |
| # ToDo: run tests in /cmd directory | |
| - name: Run the tests (not on Windows) | |
| run: | | |
| set -x | |
| go version | |
| # Define packages to exclude | |
| EXCLUDE_PACKAGES=( | |
| "client/clientset" # Auto-generated client code | |
| "client/informers" # Auto-generated informer code | |
| "client/listers" # Auto-generated lister code | |
| "storage/external_test" # Test code, excluded from production | |
| "ontap/api/azgo" # Auto-generated code for ONTAP API (AZGO) | |
| "ontap/api/rest" # Auto-generated code for ONTAP REST API | |
| "fake" # Mock code for testing purposes | |
| "github.com/netapp/trident/mocks/" # Mock code for unit tests | |
| "github.com/netapp/trident/operator/controllers/provisioner" # Auto-generated operator code | |
| "github.com/netapp/trident/operator/controllers/provisioner/apis/netapp/v1" # Auto-generated API definitions | |
| ) | |
| # Build regex pattern from exclusion list | |
| EXCLUDE_REGEX=$(IFS="|"; echo "${EXCLUDE_PACKAGES[*]}") | |
| # Run tests excluding the specified packages | |
| echo mkdir ${{ runner.temp }}/${{ runner.os }}-coverage-binary.out | |
| mkdir ${{ runner.temp }}/${{ runner.os }}-coverage-binary.out | |
| go test $(go list ./... | grep -v -E "$EXCLUDE_REGEX") -covermode=count -test.gocoverdir=${{ runner.temp }}/${{ runner.os }}-coverage-binary.out | |
| go tool covdata textfmt -i=${{ runner.temp }}/${{ runner.os }}-coverage-binary.out -o ${{ runner.os }}-coverage.out | |
| - name: Convert Go coverage to Cobertura XML | |
| run: | | |
| gocover-cobertura < ${{ runner.os }}-coverage.out > cobertura-coverage.xml | |
| - name: Summarize code coverage | |
| uses: irongut/[email protected] | |
| with: | |
| filename: cobertura-coverage.xml | |
| badge: true | |
| fail_below_min: true | |
| format: markdown | |
| hide_complexity: true | |
| indicators: false | |
| output: both | |
| thresholds: '62 80' | |
| - name: Add coverage PR comment | |
| uses: marocchino/sticky-pull-request-comment@v2 | |
| if: github.event_name == 'pull_request' | |
| with: | |
| recreate: true | |
| path: code-coverage-results.md | |
| - name: Upload coverage as artifacts | |
| uses: actions/upload-artifact@v4 | |
| if: always() | |
| with: | |
| name: code-coverage | |
| path: | | |
| ${{ runner.os }}-coverage.out | |
| cobertura-coverage.xml | |
| code-coverage-results.md | |
| retention-days: 5 |