diff --git a/.github/workflows/go_app_pull_requests.yml b/.github/workflows/go_app_pull_requests.yml index 1651b9b..1933a4f 100644 --- a/.github/workflows/go_app_pull_requests.yml +++ b/.github/workflows/go_app_pull_requests.yml @@ -26,6 +26,11 @@ on: description: "The duration before tests are stopped" type: string default: "10m" + EXTRA_JUNIT_REPORT: + description: "Path to an additional JUnit XML report (e.g., from Python integration tests). Relative to the module directory." + type: string + required: false + default: "" secrets: GH_CI_PAT: description: 'Token password for GitHub auth' @@ -151,11 +156,11 @@ jobs: run: | mkdir -p ${{ matrix.module }}/coverage/unit mkdir -p ${{ matrix.module }}/coverage/int - # Run unit tests for the module. + # Run unit tests with race detector and coverage - name: go test working-directory: ${{ matrix.module }} run: | - go test -cover --race -v ${{ inputs.GO_TEST_UNIT_TAGS }} ./... \ + go test -cover -race -v ${{ inputs.GO_TEST_UNIT_TAGS }} ./... \ -args -test.gocoverdir="${{ github.workspace }}/${{ matrix.module }}/coverage/unit" \ 2>&1 | tee unit_test_output.txt - name: Build Unit Test Junit report @@ -176,16 +181,22 @@ jobs: name: junit-report-${{ strategy.job-index }} token: ${{ secrets.CODECOV_TOKEN }} # Integration tests (conditional, per-module) + # Coverage is collected from two sources: + # 1. Go integration tests running in-process (via -cover and -test.gocoverdir) + # 2. Services running in Docker containers (via INTEGRATION_COVERAGE=true env var) - name: integration tests if: ${{ inputs.GO_TEST_INTEGRATION_ENABLED }} working-directory: ${{ matrix.module }} run: | - go test -v ${{ inputs.GO_TEST_INTEGRATION_TAGS }} -timeout ${{ inputs.GO_TEST_INTEGRATION_TIMEOUT }} ./... \ - | tee integration_test_output.txt + INTEGRATION_COVERAGE=true go test -cover -v ${{ inputs.GO_TEST_INTEGRATION_TAGS }} -timeout ${{ inputs.GO_TEST_INTEGRATION_TIMEOUT }} ./... \ + -args -test.gocoverdir="${{ github.workspace }}/${{ matrix.module }}/coverage/int" \ + > >(tee integration_test_output.txt) 2> >(tee integration_test_stderr.txt >&2) - name: Build Integration Test Junit report if: ${{ inputs.GO_TEST_INTEGRATION_ENABLED }} working-directory: ${{ matrix.module }} - run: go-junit-report -in integration_test_output.txt -set-exit-code > junit_integration_report.xml || true + run: | + grep -E '^(=== |--- |\s*(PASS|FAIL|ok\s|coverage:|SKIP|\?)\s)' integration_test_output.txt > integration_test_go_only.txt || true + go-junit-report -in integration_test_go_only.txt -set-exit-code > junit_integration_report.xml || true - name: Integration Test Report uses: dorny/test-reporter@v1 if: ${{ inputs.GO_TEST_INTEGRATION_ENABLED }} @@ -193,6 +204,7 @@ jobs: name: Integration Test Report (${{ matrix.module }}) path: ${{ matrix.module }}/junit_integration_report.xml reporter: java-junit + fail-on-error: 'false' - name: Upload integration test results to Codecov if: ${{ inputs.GO_TEST_INTEGRATION_ENABLED }} uses: codecov/test-results-action@v1 @@ -201,22 +213,61 @@ jobs: files: ${{ matrix.module }}/junit_integration_report.xml name: junit-integration-report-${{ strategy.job-index }} token: ${{ secrets.CODECOV_TOKEN }} - # Coverage handling - - name: build coverage.txt + # Extra JUnit report (e.g., from Python integration tests running inside Docker) + - name: Extra Test Report + if: ${{ (success() || failure()) && inputs.EXTRA_JUNIT_REPORT != '' && inputs.GO_TEST_INTEGRATION_ENABLED }} + uses: dorny/test-reporter@v1 + with: + name: Extra Test Report (${{ matrix.module }}) + path: ${{ matrix.module }}/${{ inputs.EXTRA_JUNIT_REPORT }} + reporter: java-junit + - name: Upload extra test results to Codecov + if: ${{ (success() || failure()) && inputs.EXTRA_JUNIT_REPORT != '' && inputs.GO_TEST_INTEGRATION_ENABLED }} + uses: codecov/test-results-action@v1 + with: + fail_ci_if_error: false + files: ${{ matrix.module }}/${{ inputs.EXTRA_JUNIT_REPORT }} + name: junit-extra-report-${{ strategy.job-index }} + token: ${{ secrets.CODECOV_TOKEN }} + # Coverage handling - upload unit and integration separately + # (they use different coverage modes: atomic vs set, so can't be combined locally) + # Codecov will merge them automatically + - name: build unit coverage working-directory: ${{ matrix.module }} run: | - if [ -d coverage/int ] && [ "$(ls -A coverage/int)" ]; then - go tool covdata textfmt -i=./coverage/int,./coverage/unit -o coverage.txt + if [ -d coverage/unit ] && [ "$(ls -A coverage/unit 2>/dev/null)" ]; then + echo "Converting unit coverage to text format" + go tool covdata textfmt -i=./coverage/unit -o coverage-unit.txt else - go tool covdata textfmt -i=./coverage/unit -o coverage.txt + echo "No unit coverage data found" fi - - name: Upload test coverage results to Codecov + - name: build integration coverage + working-directory: ${{ matrix.module }} + run: | + if [ -d coverage/int ] && [ "$(ls -A coverage/int 2>/dev/null)" ]; then + echo "Converting integration coverage to text format" + go tool covdata textfmt -i=./coverage/int -o coverage-int.txt + else + echo "No integration coverage data found" + fi + - name: Upload unit test coverage to Codecov + if: ${{ hashFiles(format('{0}/coverage-unit.txt', matrix.module)) != '' }} uses: codecov/codecov-action@v4 with: token: ${{ secrets.CODECOV_TOKEN }} - files: ${{ matrix.module }}/coverage.txt + files: ${{ matrix.module }}/coverage-unit.txt + flags: unit verbose: true - fail_ci_if_error: true # optional (default = false) + fail_ci_if_error: false + - name: Upload integration test coverage to Codecov + if: ${{ hashFiles(format('{0}/coverage-int.txt', matrix.module)) != '' }} + uses: codecov/codecov-action@v4 + with: + token: ${{ secrets.CODECOV_TOKEN }} + files: ${{ matrix.module }}/coverage-int.txt + flags: integration + verbose: true + fail_ci_if_error: false docker-build: # # ensures the docker image will build without pushing to the registry diff --git a/.github/workflows/go_app_push_main.yml b/.github/workflows/go_app_push_main.yml index b8081cf..4b39f17 100644 --- a/.github/workflows/go_app_push_main.yml +++ b/.github/workflows/go_app_push_main.yml @@ -27,6 +27,11 @@ on: description: "The duration before tests are stopped" type: string default: "10m" + EXTRA_JUNIT_REPORT: + description: "Path to an additional JUnit XML report (e.g., from Python integration tests). Relative to the module directory." + type: string + required: false + default: "" secrets: GH_CI_PAT: description: 'Token password for GitHub auth' @@ -136,18 +141,22 @@ jobs: if: ${{ inputs.GO_TEST_INTEGRATION_ENABLED }} working-directory: ${{ matrix.module }} run: | - go test -v ${{ inputs.GO_TEST_INTEGRATION_TAGS }} -timeout ${{ inputs.GO_TEST_INTEGRATION_TIMEOUT }} ./... \ - | tee integration_test_output.txt + INTEGRATION_COVERAGE=true go test -cover -v ${{ inputs.GO_TEST_INTEGRATION_TAGS }} -timeout ${{ inputs.GO_TEST_INTEGRATION_TIMEOUT }} ./... \ + -args -test.gocoverdir="${{ github.workspace }}/${{ matrix.module }}/coverage/int" \ + > >(tee integration_test_output.txt) 2> >(tee integration_test_stderr.txt >&2) - name: Build Integration Test Junit report if: ${{ inputs.GO_TEST_INTEGRATION_ENABLED }} working-directory: ${{ matrix.module }} - run: go-junit-report -in integration_test_output.txt -set-exit-code > junit_integration_report.xml || true + run: | + grep -E '^(=== |--- |\s*(PASS|FAIL|ok\s|coverage:|SKIP|\?)\s)' integration_test_output.txt > integration_test_go_only.txt || true + go-junit-report -in integration_test_go_only.txt -set-exit-code > junit_integration_report.xml || true - name: Integration Test Report uses: dorny/test-reporter@v1 if: ${{ inputs.GO_TEST_INTEGRATION_ENABLED }} with: name: Integration Test Report (${{ matrix.module }}) path: ${{ matrix.module }}/junit_integration_report.xml + fail-on-error: 'false' reporter: java-junit - name: Upload integration test results to Codecov if: ${{ inputs.GO_TEST_INTEGRATION_ENABLED }} @@ -157,6 +166,22 @@ jobs: files: ${{ matrix.module }}/junit_integration_report.xml name: junit-integration-report-${{ strategy.job-index }} token: ${{ secrets.CODECOV_TOKEN }} + # Extra JUnit report (e.g., from Python integration tests running inside Docker) + - name: Extra Test Report + if: ${{ (success() || failure()) && inputs.EXTRA_JUNIT_REPORT != '' && inputs.GO_TEST_INTEGRATION_ENABLED }} + uses: dorny/test-reporter@v1 + with: + name: Extra Test Report (${{ matrix.module }}) + path: ${{ matrix.module }}/${{ inputs.EXTRA_JUNIT_REPORT }} + reporter: java-junit + - name: Upload extra test results to Codecov + if: ${{ (success() || failure()) && inputs.EXTRA_JUNIT_REPORT != '' && inputs.GO_TEST_INTEGRATION_ENABLED }} + uses: codecov/test-results-action@v1 + with: + fail_ci_if_error: false + files: ${{ matrix.module }}/${{ inputs.EXTRA_JUNIT_REPORT }} + name: junit-extra-report-${{ strategy.job-index }} + token: ${{ secrets.CODECOV_TOKEN }} # Coverage handling - name: build coverage.txt working-directory: ${{ matrix.module }}