WIP: Add unit test code coverage #561
This file contains 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: Linter and Unit Tests | |
on: | |
push: | |
branches: [ "main" ] | |
paths: | |
- '.github/workflows/**' | |
- 'pkg/**' | |
- 'cmd/**' | |
- 'api/**' | |
- 'go.mod' | |
- 'go.sum' | |
- '.golangci.yml' | |
pull_request: | |
branches: [ "main" ] | |
paths: | |
- '.github/workflows/**' | |
- 'pkg/**' | |
- 'cmd/**' | |
- 'api/**' | |
- 'go.mod' | |
- 'go.sum' | |
- '.golangci.yml' | |
jobs: | |
lint: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out code | |
uses: actions/checkout@v4 | |
- name: Set up Go | |
uses: actions/setup-go@v4 | |
with: | |
go-version: '1.22' | |
- name: Lint | |
run: make lint-all | |
verify: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out code | |
uses: actions/checkout@v4 | |
- name: Set up Go | |
uses: actions/setup-go@v4 | |
with: | |
go-version: '1.22' | |
- name: Verify Codegen | |
run: bash ${GITHUB_WORKSPACE}/hack/verify-codegen.sh | |
test: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out code | |
uses: actions/checkout@v4 | |
- name: Set up Go | |
uses: actions/setup-go@v4 | |
with: | |
go-version: '1.22' | |
- name: Cache Go modules | |
uses: actions/cache@v3 | |
with: | |
path: | | |
~/.cache/go-build | |
~/go/pkg/mod | |
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} | |
restore-keys: | | |
${{ runner.os }}-go- | |
- name: Run Unit Tests | |
run: make test | |
- name: Archive code coverage results | |
uses: actions/upload-artifact@v4 | |
with: | |
name: code-coverage | |
path: cover.out # Make sure to use the same file name you chose for the "-coverprofile" in the "Test" step | |
code_coverage: | |
name: "Code coverage report" | |
if: github.event_name == 'pull_request' # Do not run when workflow is triggered by push to main branch | |
runs-on: ubuntu-latest | |
needs: test # Depends on the artifact uploaded by the "unit_tests" job | |
permissions: | |
contents: read | |
actions: read # to download code coverage results from "test" job | |
pull-requests: write # write permission needed to comment on PR | |
steps: | |
- uses: fgrosse/[email protected] # Consider using a Git revision for maximum security | |
with: | |
coverage-artifact-name: "code-coverage" # can be omitted if you used this default value | |
coverage-file-name: "cover.out" # can be omitted if you used this default value |