chore: add test coverage in PRs as comment (#884)
* generate test coverage in CI pipeline * add pipeline which adds comments in PR with test coverage
This commit is contained in:
parent
f435d5dda8
commit
8dafa4bfe8
2 changed files with 35 additions and 2 deletions
35
.github/workflows/ci.yaml
vendored
35
.github/workflows/ci.yaml
vendored
|
|
@ -1,9 +1,16 @@
|
||||||
name: CI Workflow
|
name: CI Workflow
|
||||||
|
|
||||||
on: [pull_request, workflow_dispatch]
|
on:
|
||||||
|
pull_request:
|
||||||
|
workflow_dispatch:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
|
||||||
env:
|
env:
|
||||||
GO_VERSION: "1.24"
|
GO_VERSION: "1.24"
|
||||||
|
CODE_COVERAGE_FILE_NAME: "coverage.out" # must be the same as in Makefile
|
||||||
|
CODE_COVERAGE_ARTIFACT_NAME: "code-coverage"
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
main:
|
main:
|
||||||
|
|
@ -33,8 +40,17 @@ jobs:
|
||||||
- name: Test
|
- name: Test
|
||||||
run: make test
|
run: make test
|
||||||
|
|
||||||
|
|
||||||
|
- name: Archive code coverage results
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: ${{ env.CODE_COVERAGE_ARTIFACT_NAME }}
|
||||||
|
path: "stackit/${{ env.CODE_COVERAGE_FILE_NAME }}"
|
||||||
|
|
||||||
|
|
||||||
config:
|
config:
|
||||||
name: Check GoReleaser config
|
name: Check GoReleaser config
|
||||||
|
if: github.event_name == 'pull_request'
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
|
|
@ -44,3 +60,20 @@ jobs:
|
||||||
uses: goreleaser/goreleaser-action@v6
|
uses: goreleaser/goreleaser-action@v6
|
||||||
with:
|
with:
|
||||||
args: check
|
args: check
|
||||||
|
|
||||||
|
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: main
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
actions: read # to download code coverage results from "main" job
|
||||||
|
pull-requests: write # write permission needed to comment on PR
|
||||||
|
steps:
|
||||||
|
- name: Check new code coverage
|
||||||
|
uses: fgrosse/go-coverage-report@v1.2.0
|
||||||
|
with:
|
||||||
|
coverage-artifact-name: ${{ env.CODE_COVERAGE_ARTIFACT_NAME }}
|
||||||
|
coverage-file-name: ${{ env.CODE_COVERAGE_FILE_NAME }}
|
||||||
|
root-package: 'github.com/stackitcloud/terraform-provider-stackit'
|
||||||
2
Makefile
2
Makefile
|
|
@ -35,7 +35,7 @@ fmt:
|
||||||
# TEST
|
# TEST
|
||||||
test:
|
test:
|
||||||
@echo "Running tests for the terraform provider"
|
@echo "Running tests for the terraform provider"
|
||||||
@cd $(ROOT_DIR)/stackit && go test ./... -count=1 && cd $(ROOT_DIR)
|
@cd $(ROOT_DIR)/stackit && go test ./... -count=1 -coverprofile=coverage.out && cd $(ROOT_DIR)
|
||||||
|
|
||||||
# Test coverage
|
# Test coverage
|
||||||
coverage:
|
coverage:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue