From e6b0ed5b3b7d7daf9ef3ab344db0826aa343d929 Mon Sep 17 00:00:00 2001 From: Stefan Benz <46600784+stebenz@users.noreply.github.com> Date: Mon, 7 Jul 2025 17:53:33 +0200 Subject: [PATCH] chore: combine test coverage for core tests --- .github/workflows/build.yml | 9 +++-- .github/workflows/core-coverage.yml | 38 +++++++++++++++++++++ .github/workflows/core-integration-test.yml | 21 ++++++------ .github/workflows/core-unit-test.yml | 19 +++++------ Makefile | 24 +++++++++---- 5 files changed, 81 insertions(+), 30 deletions(-) create mode 100644 .github/workflows/core-coverage.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 81f3104065..1a708e6a21 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -57,8 +57,6 @@ jobs: with: core_cache_key: ${{ needs.core.outputs.cache_key }} core_cache_path: ${{ needs.core.outputs.cache_path }} - secrets: - CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} core-integration-test: needs: core @@ -66,6 +64,13 @@ jobs: with: core_cache_key: ${{ needs.core.outputs.cache_key }} core_cache_path: ${{ needs.core.outputs.cache_path }} + + core-coverage: + needs: [ core-unit-test, core-integration-test ] + uses: ./.github/workflows/core-coverage.yml + with: + unit_test_report: ${{ needs.core-unit-test.outputs.unit_test_report }} + integration_test_report: ${{ needs.core-integration-test.outputs.integration_test_report }} secrets: CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} diff --git a/.github/workflows/core-coverage.yml b/.github/workflows/core-coverage.yml new file mode 100644 index 0000000000..2925980e52 --- /dev/null +++ b/.github/workflows/core-coverage.yml @@ -0,0 +1,38 @@ +name: Upload coverage + +on: + workflow_call: + inputs: + unit_test_report: + required: true + type: boolean + integration_test_report: + required: true + type: boolean + secrets: + CODECOV_TOKEN: + required: true + + +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/download-artifact@v4 + with: + path: tmp/coverage/unit + name: unit-coverage + - uses: actions/download-artifact@v4 + with: + path: tmp/coverage/integration + name: integration-coverage + - name: merge coverages + if: ${{ unit_test_report == 'true' && integration_test_report == 'true' }} + run: make core_coverage_reports + - name: publish coverage + if: ${{ unit_test_report == 'true' && integration_test_report == 'true' }} + uses: codecov/codecov-action@v5.4.0 + with: + file: full-profile.cov + name: core-integration-tests-postgres + token: ${{ secrets.CODECOV_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/core-integration-test.yml b/.github/workflows/core-integration-test.yml index e33ffec3d5..200c2e692b 100644 --- a/.github/workflows/core-integration-test.yml +++ b/.github/workflows/core-integration-test.yml @@ -9,9 +9,10 @@ on: core_cache_path: required: true type: string - secrets: - CODECOV_TOKEN: - required: true + outputs: + integration_test_report: + value: ${{ steps.cache.outputs.cache-hit != 'true' }} + type: boolean jobs: postgres: @@ -74,6 +75,12 @@ jobs: env: ZITADEL_MASTERKEY: MasterkeyNeedsToHave32Characters run: make core_integration_test + - + uses: actions/upload-artifact@v4 + if: ${{ steps.cache.outputs.cache-hit != 'true' }} + with: + name: integration-coverage + path: tmp/coverage/integration - name: upload server logs if: always() @@ -83,14 +90,6 @@ jobs: path: | tmp/zitadel.log tmp/race.log.* - - - name: publish coverage - uses: codecov/codecov-action@v4.3.0 - with: - file: profile.cov - name: core-integration-tests-postgres - flags: core-integration-tests-postgres - token: ${{ secrets.CODECOV_TOKEN }} - uses: actions/cache/save@v4 name: cache results diff --git a/.github/workflows/core-unit-test.yml b/.github/workflows/core-unit-test.yml index 715a08eb19..f878cd056c 100644 --- a/.github/workflows/core-unit-test.yml +++ b/.github/workflows/core-unit-test.yml @@ -12,9 +12,10 @@ on: crdb_version: required: false type: string - secrets: - CODECOV_TOKEN: - required: true + outputs: + unit_test_report: + value: ${{ steps.cache.outputs.cache-hit != 'true' }} + type: boolean jobs: test: @@ -54,14 +55,12 @@ jobs: name: test if: ${{ steps.cache.outputs.cache-hit != 'true' }} run: make core_unit_test - - - name: publish coverage - uses: codecov/codecov-action@v4.3.0 + - + uses: actions/upload-artifact@v4 + if: ${{ steps.cache.outputs.cache-hit != 'true' }} with: - file: profile.cov - name: core-unit-tests - flags: core-unit-tests - token: ${{ secrets.CODECOV_TOKEN }} + name: unit-coverage + path: tmp/coverage/unit - uses: actions/cache/save@v4 name: cache results diff --git a/Makefile b/Makefile index 3bad5aa1c6..4fa19dbb95 100644 --- a/Makefile +++ b/Makefile @@ -7,10 +7,11 @@ VERSION ?= development-$(now) COMMIT_SHA ?= $(shell git rev-parse HEAD) ZITADEL_IMAGE ?= zitadel:local -GOCOVERDIR = tmp/coverage +GOCOVERDIR_INTEGRATION = tmp/coverage/integration +GOCOVERDIR_UNIT = tmp/coverage/unit ZITADEL_MASTERKEY ?= MasterkeyNeedsToHave32Characters -export GOCOVERDIR ZITADEL_MASTERKEY +export GOCOVERDIR_INTEGRATION GOCOVERDIR_UNIT ZITADEL_MASTERKEY LOGIN_REMOTE_NAME := login LOGIN_REMOTE_URL ?= https://github.com/zitadel/typescript.git @@ -119,7 +120,12 @@ clean: .PHONY: core_unit_test core_unit_test: - go test -race -coverprofile=profile.cov -coverpkg=./internal/... ./... + mkdir -p $${GOCOVERDIR_UNIT} + go test -cover -race -coverprofile=profile.cov -coverpkg=./internal/... ./... -args -test.gocoverdir="${GOCOVERDIR_UNIT}" + +.PHONY: core_unit_reports +core_unit_reports: + go tool covdata textfmt -i=${GOCOVERDIR_UNIT} -pkg=github.com/zitadel/zitadel/internal/...,github.com/zitadel/zitadel/cmd/... -o unit-profile.cov .PHONY: core_integration_db_up core_integration_db_up: @@ -132,7 +138,6 @@ core_integration_db_down: .PHONY: core_integration_setup core_integration_setup: go build -cover -race -tags integration -o zitadel.test main.go - mkdir -p $${GOCOVERDIR} GORACE="halt_on_error=1" ./zitadel.test init --config internal/integration/config/zitadel.yaml --config internal/integration/config/postgres.yaml GORACE="halt_on_error=1" ./zitadel.test setup --masterkeyFromEnv --init-projections --config internal/integration/config/zitadel.yaml --config internal/integration/config/postgres.yaml --steps internal/integration/config/steps.yaml @@ -145,7 +150,8 @@ core_integration_server_start: core_integration_setup .PHONY: core_integration_test_packages core_integration_test_packages: - go test -race -count 1 -tags integration -timeout 30m $$(go list -tags integration ./... | grep "integration_test") + mkdir -p $${GOCOVERDIR_INTEGRATION} + GOCOVERDIR=${GOCOVERDIR_INTEGRATION} go test -race -count 1 -tags integration -timeout 30m $$(go list -tags integration ./... | grep "integration_test") .PHONY: core_integration_server_stop core_integration_server_stop: @@ -159,10 +165,14 @@ core_integration_server_stop: .PHONY: core_integration_reports core_integration_reports: - go tool covdata textfmt -i=tmp/coverage -pkg=github.com/zitadel/zitadel/internal/...,github.com/zitadel/zitadel/cmd/... -o profile.cov + go tool covdata textfmt -i=${GOCOVERDIR_INTEGRATION} -pkg=github.com/zitadel/zitadel/internal/...,github.com/zitadel/zitadel/cmd/... -o integration-profile.cov .PHONY: core_integration_test -core_integration_test: core_integration_server_start core_integration_test_packages core_integration_server_stop core_integration_reports +core_integration_test: core_integration_server_start core_integration_test_packages core_integration_server_stop + +.PHONY: core_coverage_reports +core_coverage_reports: + go tool covdata textfmt -i=${GOCOVERDIR_INTEGRATION},${GOCOVERDIR_UNIT} -pkg=github.com/zitadel/zitadel/internal/...,github.com/zitadel/zitadel/cmd/... -o full-profile.cov .PHONY: console_lint console_lint: