diff --git a/.github/actions/parse-ci-reports/README.md b/.github/actions/parse-ci-reports/README.md index 23f2bb1..0400d8f 100644 --- a/.github/actions/parse-ci-reports/README.md +++ b/.github/actions/parse-ci-reports/README.md @@ -29,7 +29,7 @@ ## Overview -Parse native reports, publish summaries and retain selected files in one artifact. Internal helper for lint and test. +Parse native reports and retain parsed files for consolidated reporting. Keep native Go coverage in a separate artifact because the common parser does not support its format. Internal helper for lint and test. @@ -41,7 +41,7 @@ Parse native reports, publish summaries and retain selected files in one artifac ## Usage ```yaml -- uses: hoverkraft-tech/ci-github-go/.github/actions/parse-ci-reports@fad246d709b737d8277bd10e01a474d6e6651ab8 # dependabot/github_actions/github-actions-dependencies-970c98ee9d +- uses: hoverkraft-tech/ci-github-go/.github/actions/parse-ci-reports@eac34b0e29b78265265a2021a9099f73ab699e0c # fix/consolidated-go-coverage with: # Validated absolute project directory. # This input is required. @@ -55,7 +55,7 @@ Parse native reports, publish summaries and retain selected files in one artifac # This input is required. group: "" - # Include the project's coverage.out when present. + # Retain the project's coverage.out in a separate artifact when present. # Default: `false` native-coverage: "false" @@ -70,13 +70,13 @@ Parse native reports, publish summaries and retain selected files in one artifac ## Inputs -| **Input** | **Description** | **Required** | **Default** | -| --------------------- | ----------------------------------------------------------- | ------------ | ------------ | -| **`directory`** | Validated absolute project directory. | **true** | - | -| **`report-paths`** | Report paths or auto selectors passed to the common parser. | **false** | `auto:test` | -| **`group`** | Calling job ID used to group reports. | **true** | - | -| **`native-coverage`** | Include the project's coverage.out when present. | **false** | `false` | -| **`report-name`** | Title of the GitHub report summary. | **false** | `CI reports` | +| **Input** | **Description** | **Required** | **Default** | +| --------------------- | ---------------------------------------------------------------------- | ------------ | ------------ | +| **`directory`** | Validated absolute project directory. | **true** | - | +| **`report-paths`** | Report paths or auto selectors passed to the common parser. | **false** | `auto:test` | +| **`group`** | Calling job ID used to group reports. | **true** | - | +| **`native-coverage`** | Retain the project's coverage.out in a separate artifact when present. | **false** | `false` | +| **`report-name`** | Title of the GitHub report summary. | **false** | `CI reports` | @@ -87,9 +87,10 @@ Parse native reports, publish summaries and retain selected files in one artifac ## Outputs -| **Output** | **Description** | -| ----------------- | ---------------------------------------------------------- | -| **`artifact-id`** | Uploaded artifact ID, or empty when no report files exist. | +| **Output** | **Description** | +| -------------------------- | ----------------------------------------------------------------------- | +| **`artifact-id`** | Uploaded artifact ID, or empty when no report files exist. | +| **`coverage-artifact-id`** | Native Go coverage artifact ID, or empty when no coverage was retained. | diff --git a/.github/actions/parse-ci-reports/action.test.cjs b/.github/actions/parse-ci-reports/action.test.cjs index 0c61e87..9efd740 100644 --- a/.github/actions/parse-ci-reports/action.test.cjs +++ b/.github/actions/parse-ci-reports/action.test.cjs @@ -52,9 +52,17 @@ test("report artifacts contain only parsed reports and use unique names", async await assert.rejects(() => outputs([report], "../bad-group"), /report-group/); const coverage = path.join(directory, "coverage.out"); fs.writeFileSync(coverage, "mode: atomic\n"); + const retained = await outputs([report], "outer-job", true); + assert.equal(retained.files, report); + assert.equal(retained["coverage-file"], coverage); + assert.match(retained["coverage-name"], /^go-coverage-2-outer-job-/); assert.equal( - (await outputs([report], "outer-job", true)).files, - `${report}\n${coverage}`, + retained.name.replace("ci-reports-", "go-coverage-"), + retained["coverage-name"], ); + const coverageOnly = await outputs([], "outer-job", true); + assert.equal(coverageOnly.files, undefined); + assert.equal(coverageOnly["coverage-file"], coverage); + await assert.rejects(() => outputs([], "../bad-group", true), /report-group/); assert.equal((await outputs([report])).files, report); }); diff --git a/.github/actions/parse-ci-reports/action.yml b/.github/actions/parse-ci-reports/action.yml index 25f5c61..afde3b3 100644 --- a/.github/actions/parse-ci-reports/action.yml +++ b/.github/actions/parse-ci-reports/action.yml @@ -1,8 +1,9 @@ --- name: Parse CI reports description: - Parse native reports, publish summaries and retain selected files in one artifact. Internal helper for lint and - test. + Parse native reports and retain parsed files for consolidated reporting. + Keep native Go coverage in a separate artifact because the common parser does not support its format. + Internal helper for lint and test. inputs: directory: description: Validated absolute project directory. @@ -14,7 +15,7 @@ inputs: description: Calling job ID used to group reports. required: true native-coverage: - description: Include the project's coverage.out when present. + description: Retain the project's coverage.out in a separate artifact when present. default: "false" report-name: description: Title of the GitHub report summary. @@ -23,6 +24,9 @@ outputs: artifact-id: description: Uploaded artifact ID, or empty when no report files exist. value: ${{ steps.upload.outputs.artifact-id }} + coverage-artifact-id: + description: Native Go coverage artifact ID, or empty when no coverage was retained. + value: ${{ steps.upload-coverage.outputs.artifact-id }} runs: using: composite steps: @@ -51,15 +55,20 @@ runs: const fs = require('node:fs'); const path = require('node:path'); const files = JSON.parse(process.env.REPORT_FILES || '[]'); - if (process.env.NATIVE_COVERAGE === 'true') { - const coverage = path.join(process.env.DIRECTORY, 'coverage.out'); - if (fs.existsSync(coverage)) files.push(coverage); - } - if (!files.length) return; + const coverage = path.join(process.env.DIRECTORY, 'coverage.out'); + const retainCoverage = process.env.NATIVE_COVERAGE === 'true' && fs.existsSync(coverage); + if (!files.length && !retainCoverage) return; const group = process.env.REPORT_GROUP; if (!/^[\w-]+$/.test(group)) throw new Error('report-group must be a job ID.'); - core.setOutput('files', files.join('\n')); - core.setOutput('name', `ci-reports-${process.env.GITHUB_RUN_ATTEMPT}-${group}-${require('node:crypto').randomUUID()}`); + const suffix = `${process.env.GITHUB_RUN_ATTEMPT}-${group}-${require('node:crypto').randomUUID()}`; + if (files.length) { + core.setOutput('files', files.join('\n')); + core.setOutput('name', `ci-reports-${suffix}`); + } + if (retainCoverage) { + core.setOutput('coverage-file', coverage); + core.setOutput('coverage-name', `go-coverage-${suffix}`); + } if: ${{ !cancelled() }} - id: upload if: ${{ !cancelled() && steps.prepare.outputs.files != '' }} @@ -70,3 +79,11 @@ runs: include-hidden-files: true if-no-files-found: error retention-days: 7 + - id: upload-coverage + if: ${{ !cancelled() && steps.prepare.outputs.coverage-file != '' }} + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + with: + name: ${{ steps.prepare.outputs.coverage-name }} + path: ${{ steps.prepare.outputs.coverage-file }} + if-no-files-found: error + retention-days: 7 diff --git a/.github/workflows/__test-action-test.yml b/.github/workflows/__test-action-test.yml index 7c95937..86e3e34 100644 --- a/.github/workflows/__test-action-test.yml +++ b/.github/workflows/__test-action-test.yml @@ -11,6 +11,8 @@ jobs: contents: read outputs: artifact-id: ${{ steps.failed-test.outputs.report-artifact-id }} + success-artifact-id: ${{ steps.test.outputs.report-artifact-id }} + coverage-artifact-id: ${{ steps.test.outputs.coverage-artifact-id }} steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: @@ -47,6 +49,7 @@ jobs: env: SUCCESS_ARTIFACT: ${{ steps.test.outputs.report-artifact-id }} FAILURE_ARTIFACT: ${{ steps.failed-test.outputs.report-artifact-id }} + COVERAGE_ARTIFACT: ${{ steps.test.outputs.coverage-artifact-id }} TEST_OUTCOME: ${{ steps.failed-test.outcome }} with: script: | @@ -55,6 +58,8 @@ jobs: assert.ok(process.env.SUCCESS_ARTIFACT, 'Successful tests retain reports'); assert.ok(process.env.FAILURE_ARTIFACT, 'Failed tests retain reports'); assert.notEqual(process.env.SUCCESS_ARTIFACT, process.env.FAILURE_ARTIFACT); + assert.ok(process.env.COVERAGE_ARTIFACT, 'Native coverage is retained separately'); + assert.notEqual(process.env.SUCCESS_ARTIFACT, process.env.COVERAGE_ARTIFACT); verify: needs: test runs-on: ubuntu-latest @@ -75,3 +80,27 @@ jobs: run: | test -f "$REPORT_DIRECTORY/junit.xml" grep -q 'message="expected"' "$REPORT_DIRECTORY/junit.xml" + - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 + with: + github-token: ${{ github.token }} + artifact-ids: ${{ needs.test.outputs.success-artifact-id }} + path: ${{ runner.temp }}/successful-reports + - name: Verify consolidated reports parse every retained file + uses: hoverkraft-tech/ci-github-common/actions/quality/parse-ci-reports@33462c06bcbbd9144d7f661929e61953604b444d # 4.3.2 + with: + working-directory: ${{ runner.temp }}/successful-reports + report-paths: "**/*" + output-format: summary + - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 + with: + github-token: ${{ github.token }} + artifact-ids: ${{ needs.test.outputs.coverage-artifact-id }} + path: ${{ runner.temp }}/native-coverage + - name: Verify native coverage stays available outside consolidated artifacts + shell: bash + env: + REPORT_DIRECTORY: ${{ runner.temp }}/successful-reports + COVERAGE_DIRECTORY: ${{ runner.temp }}/native-coverage + run: | + test ! -e "$REPORT_DIRECTORY/coverage.out" + grep -q '^mode: atomic$' "$COVERAGE_DIRECTORY/coverage.out" diff --git a/.github/workflows/continuous-integration.md b/.github/workflows/continuous-integration.md index 9c969a5..802fe3d 100644 --- a/.github/workflows/continuous-integration.md +++ b/.github/workflows/continuous-integration.md @@ -106,7 +106,8 @@ Use the common [ci-reports workflow](https://github.com/hoverkraft-tech/ci-github-common/blob/main/.github/workflows/ci-reports.yml) for consolidated comments after standalone producer jobs; set `report-group` to the outer calling job ID when required. Go coverage uses native `go tool cover` summaries and retains -`coverage.out`; the common parser handles JUnit, not native Go coverage. +`coverage.out` in separate `go-coverage-*` artifacts; the common parser handles +JUnit, not native Go coverage. Coverage details remain in each test job summary. `test: '{"coverage":"codecov"}'` enables OIDC upload. The expected coverage file is `coverage.out`. A custom command must produce @@ -143,7 +144,7 @@ on: permissions: {} jobs: continuous-integration: - uses: hoverkraft-tech/ci-github-go/.github/workflows/continuous-integration.yml@1170dea4804c7e6ce61d6900e57b42a20b2e6689 # main + uses: hoverkraft-tech/ci-github-go/.github/workflows/continuous-integration.yml@eac34b0e29b78265265a2021a9099f73ab699e0c # fix/consolidated-go-coverage permissions: contents: read id-token: write diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 4e25e7e..9539d4f 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -76,7 +76,8 @@ # [ci-reports workflow](https://github.com/hoverkraft-tech/ci-github-common/blob/main/.github/workflows/ci-reports.yml) # for consolidated comments after standalone producer jobs; set `report-group` to # the outer calling job ID when required. Go coverage uses native `go tool cover` summaries and retains -# `coverage.out`; the common parser handles JUnit, not native Go coverage. +# `coverage.out` in separate `go-coverage-*` artifacts; the common parser handles +# JUnit, not native Go coverage. Coverage details remain in each test job summary. # # `test: '{"coverage":"codecov"}'` enables OIDC upload. The expected coverage file is # `coverage.out`. A custom command must produce diff --git a/actions/audit/README.md b/actions/audit/README.md index e3f4a71..b678f08 100644 --- a/actions/audit/README.md +++ b/actions/audit/README.md @@ -54,7 +54,7 @@ See the [continuous integration workflow](../../.github/workflows/continuous-int ## Usage ```yaml -- uses: hoverkraft-tech/ci-github-go/actions/audit@1170dea4804c7e6ce61d6900e57b42a20b2e6689 # main +- uses: hoverkraft-tech/ci-github-go/actions/audit@eac34b0e29b78265265a2021a9099f73ab699e0c # fix/consolidated-go-coverage with: # Go module directory. # Default: `.` diff --git a/actions/build/README.md b/actions/build/README.md index 7fc38f9..cd42878 100644 --- a/actions/build/README.md +++ b/actions/build/README.md @@ -56,7 +56,7 @@ See the [continuous integration workflow](../../.github/workflows/continuous-int ## Usage ```yaml -- uses: hoverkraft-tech/ci-github-go/actions/build@1170dea4804c7e6ce61d6900e57b42a20b2e6689 # main +- uses: hoverkraft-tech/ci-github-go/actions/build@eac34b0e29b78265265a2021a9099f73ab699e0c # fix/consolidated-go-coverage with: # Go module directory. # Default: `.` diff --git a/actions/lint/README.md b/actions/lint/README.md index 3195ec5..d5398f5 100644 --- a/actions/lint/README.md +++ b/actions/lint/README.md @@ -56,7 +56,7 @@ See the [continuous integration workflow](../../.github/workflows/continuous-int ## Usage ```yaml -- uses: hoverkraft-tech/ci-github-go/actions/lint@1170dea4804c7e6ce61d6900e57b42a20b2e6689 # main +- uses: hoverkraft-tech/ci-github-go/actions/lint@eac34b0e29b78265265a2021a9099f73ab699e0c # fix/consolidated-go-coverage with: # Go module directory. # Default: `.` diff --git a/actions/setup-go/README.md b/actions/setup-go/README.md index 1309857..938f343 100644 --- a/actions/setup-go/README.md +++ b/actions/setup-go/README.md @@ -77,7 +77,7 @@ See the [continuous integration workflow](../../.github/workflows/continuous-int ## Usage ```yaml -- uses: hoverkraft-tech/ci-github-go/actions/setup-go@1170dea4804c7e6ce61d6900e57b42a20b2e6689 # main +- uses: hoverkraft-tech/ci-github-go/actions/setup-go@eac34b0e29b78265265a2021a9099f73ab699e0c # fix/consolidated-go-coverage with: # Go module directory inside the checkout. # Default: `.` diff --git a/actions/test/README.md b/actions/test/README.md index 5ed5ac9..22f19b2 100644 --- a/actions/test/README.md +++ b/actions/test/README.md @@ -37,6 +37,8 @@ set `race: "false"` when unavailable. A trusted Bash `command` replaces defaults and must produce JUnit for test reporting and `coverage.out` for coverage. GitHub coverage uses native `go tool cover` summaries and retains `coverage.out`; the common report parser handles JUnit, not the native Go coverage format. +Native coverage is retained in a separate `go-coverage-*` artifact, so consolidated +CI reports receive only supported files. Coverage details remain in the test job summary. @@ -68,7 +70,7 @@ See the [continuous integration workflow](../../.github/workflows/continuous-int ## Usage ```yaml -- uses: hoverkraft-tech/ci-github-go/actions/test@1170dea4804c7e6ce61d6900e57b42a20b2e6689 # main +- uses: hoverkraft-tech/ci-github-go/actions/test@eac34b0e29b78265265a2021a9099f73ab699e0c # fix/consolidated-go-coverage with: # Go module directory. # Default: `.` @@ -112,9 +114,10 @@ See the [continuous integration workflow](../../.github/workflows/continuous-int ## Outputs -| **Output** | **Description** | -| ------------------------ | --------------------------------------------------------------- | -| **`report-artifact-id`** | Native report artifact ID. Empty when no reports were produced. | +| **Output** | **Description** | +| -------------------------- | ------------------------------------------------------------------------------- | +| **`report-artifact-id`** | Native report artifact ID. Empty when no reports were produced. | +| **`coverage-artifact-id`** | Native coverage.out artifact ID for GitHub coverage, or empty when unavailable. | diff --git a/actions/test/action.yml b/actions/test/action.yml index 516faf7..26de574 100644 --- a/actions/test/action.yml +++ b/actions/test/action.yml @@ -9,6 +9,8 @@ description: | and must produce JUnit for test reporting and `coverage.out` for coverage. GitHub coverage uses native `go tool cover` summaries and retains `coverage.out`; the common report parser handles JUnit, not the native Go coverage format. + Native coverage is retained in a separate `go-coverage-*` artifact, so consolidated + CI reports receive only supported files. Coverage details remain in the test job summary. @@ -53,6 +55,9 @@ outputs: report-artifact-id: description: Native report artifact ID. Empty when no reports were produced. value: ${{ steps.report-artifact.outputs.artifact-id }} + coverage-artifact-id: + description: Native coverage.out artifact ID for GitHub coverage, or empty when unavailable. + value: ${{ steps.report-artifact.outputs.coverage-artifact-id }} runs: using: composite steps: