Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions .github/actions/parse-ci-reports/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

<!-- overview:end -->

Expand All @@ -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.
Expand All @@ -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"

Expand All @@ -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` |

<!-- inputs:end -->

Expand All @@ -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. |

<!-- outputs:end -->

Expand Down
12 changes: 10 additions & 2 deletions .github/actions/parse-ci-reports/action.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
37 changes: 27 additions & 10 deletions .github/actions/parse-ci-reports/action.yml
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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.
Expand All @@ -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:
Expand Down Expand Up @@ -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 != '' }}
Expand All @@ -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
29 changes: 29 additions & 0 deletions .github/workflows/__test-action-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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: |
Expand All @@ -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
Expand All @@ -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"
5 changes: 3 additions & 2 deletions .github/workflows/continuous-integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion actions/audit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: `.`
Expand Down
2 changes: 1 addition & 1 deletion actions/build/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: `.`
Expand Down
2 changes: 1 addition & 1 deletion actions/lint/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: `.`
Expand Down
2 changes: 1 addition & 1 deletion actions/setup-go/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: `.`
Expand Down
11 changes: 7 additions & 4 deletions actions/test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

<!-- jscpd:ignore-start -->
<!-- Shared setup and reporting guidance for standalone actions. -->
Expand Down Expand Up @@ -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: `.`
Expand Down Expand Up @@ -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. |

<!-- outputs:end -->

Expand Down
5 changes: 5 additions & 0 deletions actions/test/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.

<!-- jscpd:ignore-start -->
<!-- Shared setup and reporting guidance for standalone actions. -->
Expand Down Expand Up @@ -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:
Expand Down
Loading