mirror of
https://github.com/grafana/grafana.git
synced 2025-07-30 16:02:31 +08:00
CI: Track backend code coverage (#100856)
* CI: Track backend code coverage This is a super rudimentary way to track this coverage. The important bit for me is the ability to extract the coverage files. * CI: Allow tests to fail * Codeowners: Assign ownership of coverage tracking * CI: Join coverage info in the job * CI: Attempt to parallellise tests * CI: Upload despite failures * CI: Pattern is not regex * CI: Set up repository and Go before merging * CI: Generate go before checking coverage * CI: Multi-line string * CI: Backticks execute commands; avoid them * CI: Make the output a bit prettier Tabs are absurdly large. * CI: Remove comment on retention
This commit is contained in:

committed by
GitHub

parent
46a537aa02
commit
6f9fc8fa0c
1
.github/CODEOWNERS
vendored
1
.github/CODEOWNERS
vendored
@ -760,6 +760,7 @@ embed.go @grafana/grafana-as-code
|
|||||||
/.github/workflows/auto-milestone.yml @grafana/grafana-developer-enablement-squad
|
/.github/workflows/auto-milestone.yml @grafana/grafana-developer-enablement-squad
|
||||||
/.github/workflows/backport.yml @grafana/grafana-developer-enablement-squad
|
/.github/workflows/backport.yml @grafana/grafana-developer-enablement-squad
|
||||||
/.github/workflows/bump-version.yml @grafana/grafana-developer-enablement-squad
|
/.github/workflows/bump-version.yml @grafana/grafana-developer-enablement-squad
|
||||||
|
/.github/workflows/backend-coverage.yml @Proximyst
|
||||||
/.github/workflows/close-milestone.yml @grafana/grafana-developer-enablement-squad
|
/.github/workflows/close-milestone.yml @grafana/grafana-developer-enablement-squad
|
||||||
/.github/workflows/release-pr.yml @grafana/grafana-developer-enablement-squad
|
/.github/workflows/release-pr.yml @grafana/grafana-developer-enablement-squad
|
||||||
/.github/workflows/release-comms.yml @grafana/grafana-developer-enablement-squad
|
/.github/workflows/release-comms.yml @grafana/grafana-developer-enablement-squad
|
||||||
|
96
.github/workflows/backend-coverage.yml
vendored
Normal file
96
.github/workflows/backend-coverage.yml
vendored
Normal file
@ -0,0 +1,96 @@
|
|||||||
|
name: Backend Coverage (OSS)
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
paths:
|
||||||
|
- pkg/**
|
||||||
|
- .github/workflows/backend-coverage.yml
|
||||||
|
- go.*
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
pull_request:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
unit-tests:
|
||||||
|
name: Run unit tests (OSS)
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
if: github.repository == 'grafana/grafana'
|
||||||
|
steps:
|
||||||
|
- name: Check out repository
|
||||||
|
uses: actions/checkout@v4.2.2
|
||||||
|
- name: Setup Go environment
|
||||||
|
uses: actions/setup-go@v5.3.0
|
||||||
|
with:
|
||||||
|
go-version-file: go.work
|
||||||
|
- name: Run tests
|
||||||
|
run: make gen-go test-go-unit
|
||||||
|
- name: Upload coverage file
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
if: success() || failure()
|
||||||
|
with:
|
||||||
|
name: unit-cov
|
||||||
|
path: unit.cov
|
||||||
|
retention-days: 1
|
||||||
|
compression-level: 9 # this is raw text, and includes a _lot_ of repetition. compressing it should yield pretty good results.
|
||||||
|
integration-tests:
|
||||||
|
name: Run integration tests (OSS)
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
if: github.repository == 'grafana/grafana'
|
||||||
|
steps:
|
||||||
|
- name: Check out repository
|
||||||
|
uses: actions/checkout@v4.2.2
|
||||||
|
- name: Setup Go environment
|
||||||
|
uses: actions/setup-go@v5.3.0
|
||||||
|
with:
|
||||||
|
go-version-file: go.work
|
||||||
|
- name: Run tests
|
||||||
|
run: make gen-go test-go-integration
|
||||||
|
- name: Upload coverage file
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
if: success() || failure()
|
||||||
|
with:
|
||||||
|
name: integration-cov
|
||||||
|
path: integration.cov
|
||||||
|
retention-days: 1
|
||||||
|
compression-level: 9 # this is raw text, and includes a _lot_ of repetition. compressing it should yield pretty good results.
|
||||||
|
report-coverage:
|
||||||
|
name: Report coverage from unit and integration tests (OSS)
|
||||||
|
needs: [unit-tests, integration-tests]
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
# we don't do always() so as to not run even if the workflow is cancelled
|
||||||
|
if: github.repository == 'grafana/grafana' && (success() || failure())
|
||||||
|
steps:
|
||||||
|
- name: Check out repository
|
||||||
|
uses: actions/checkout@v4.2.2
|
||||||
|
- name: Setup Go environment
|
||||||
|
uses: actions/setup-go@v5.3.0
|
||||||
|
with:
|
||||||
|
go-version-file: go.work
|
||||||
|
- name: Generate Go
|
||||||
|
run: make gen-go
|
||||||
|
- uses: actions/download-artifact@v4
|
||||||
|
with:
|
||||||
|
pattern: '*-cov'
|
||||||
|
path: .
|
||||||
|
merge-multiple: true
|
||||||
|
- name: Join coverage outputs
|
||||||
|
run: |
|
||||||
|
cp unit.cov backend.cov
|
||||||
|
tail -n+2 integration.cov >> backend.cov
|
||||||
|
- name: Convert coverage info to per-func stats
|
||||||
|
run: go tool cover -func backend.cov > backend-funcs.log
|
||||||
|
- name: Upload coverage file
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: backend-cov
|
||||||
|
path: |
|
||||||
|
backend.cov
|
||||||
|
backend-funcs.log
|
||||||
|
retention-days: 30
|
||||||
|
compression-level: 9 # this is raw text, and includes a _lot_ of repetition. compressing it should yield pretty good results.
|
||||||
|
- name: Set summary to total coverage
|
||||||
|
# We use single quotes here to disable the bash backtick behaviour of executing commands.
|
||||||
|
run: |
|
||||||
|
echo '# Coverage' >> $GITHUB_STEP_SUMMARY
|
||||||
|
echo '```' >> $GITHUB_STEP_SUMMARY
|
||||||
|
grep 'total:' backend-funcs.log | tr '\t' ' ' >> $GITHUB_STEP_SUMMARY
|
||||||
|
echo '```' >> $GITHUB_STEP_SUMMARY
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -16,6 +16,7 @@ vendor/
|
|||||||
/requests
|
/requests
|
||||||
tsconfig.tsbuildinfo
|
tsconfig.tsbuildinfo
|
||||||
__debug_bin*
|
__debug_bin*
|
||||||
|
*.cov
|
||||||
|
|
||||||
# yarn
|
# yarn
|
||||||
.yarn/cache
|
.yarn/cache
|
||||||
|
5
Makefile
5
Makefile
@ -248,8 +248,7 @@ test-go: test-go-unit test-go-integration
|
|||||||
.PHONY: test-go-unit
|
.PHONY: test-go-unit
|
||||||
test-go-unit: ## Run unit tests for backend with flags.
|
test-go-unit: ## Run unit tests for backend with flags.
|
||||||
@echo "test backend unit tests"
|
@echo "test backend unit tests"
|
||||||
printf '$(GO_TEST_FILES)' | xargs \
|
$(GO) test $(GO_RACE_FLAG) -short -covermode=atomic -coverprofile=unit.cov -timeout=30m $(GO_TEST_FILES)
|
||||||
$(GO) test $(GO_RACE_FLAG) -short -covermode=atomic -timeout=30m
|
|
||||||
|
|
||||||
.PHONY: test-go-unit-pretty
|
.PHONY: test-go-unit-pretty
|
||||||
test-go-unit-pretty: check-tparse
|
test-go-unit-pretty: check-tparse
|
||||||
@ -262,7 +261,7 @@ test-go-unit-pretty: check-tparse
|
|||||||
.PHONY: test-go-integration
|
.PHONY: test-go-integration
|
||||||
test-go-integration: ## Run integration tests for backend with flags.
|
test-go-integration: ## Run integration tests for backend with flags.
|
||||||
@echo "test backend integration tests"
|
@echo "test backend integration tests"
|
||||||
$(GO) test $(GO_RACE_FLAG) -count=1 -run "^TestIntegration" -covermode=atomic -timeout=5m $(GO_INTEGRATION_TESTS)
|
$(GO) test $(GO_RACE_FLAG) -count=1 -run "^TestIntegration" -covermode=atomic -coverprofile=integration.cov -timeout=5m $(GO_INTEGRATION_TESTS)
|
||||||
|
|
||||||
.PHONY: test-go-integration-alertmanager
|
.PHONY: test-go-integration-alertmanager
|
||||||
test-go-integration-alertmanager: ## Run integration tests for the remote alertmanager (config taken from the mimir_backend block).
|
test-go-integration-alertmanager: ## Run integration tests for the remote alertmanager (config taken from the mimir_backend block).
|
||||||
|
Reference in New Issue
Block a user