Skip to content

Commit 9aa3f75

Browse files
committed
feat(ci): support consolidated reports from nested workflows
1 parent eb4e63d commit 9aa3f75

8 files changed

Lines changed: 151 additions & 12 deletions

File tree

‎.github/workflows/__test-action-lint.yml‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ jobs:
5959
fs.writeFileSync('lint-fixture/lint.cjs', `
6060
require('node:fs').writeFileSync('command-ran.txt', 'lint ran');
6161
if (process.env.WRITE_REPORT === 'true') {
62-
require('node:fs').writeFileSync('eslint-report.json', '[]');
62+
require('node:fs').writeFileSync('eslint-report.json', JSON.stringify([
63+
{ filePath: 'src/index.js', messages: [], errorCount: 0, warningCount: 0 },
64+
]));
6365
}
6466
process.exit(process.env.EXPECT_FAILURE === 'true' ? 1 : 0);
6567
`);

‎.github/workflows/__test-action-test.yml‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ jobs:
4343
reports: true
4444
report-file: ".reports/junit.xml,.reports/missing.xml"
4545
expected: failure
46-
artifact: false
46+
artifact: true
47+
artifact-files: '["junit.xml"]'
4748
- scenario: no automatic reports
4849
failure: false
4950
reports: false
@@ -101,6 +102,7 @@ jobs:
101102
EXPECT_REPORTS: ${{ matrix.reports }}
102103
EXPECT_FAILURE: ${{ matrix.failure }}
103104
ARTIFACT_ID: ${{ steps.test.outputs.report-artifact-id }}
105+
ARTIFACT_FILES: ${{ matrix.artifact-files || '["junit.xml","lcov.info"]' }}
104106
with:
105107
script: |
106108
const assert = require('node:assert/strict');
@@ -116,7 +118,10 @@ jobs:
116118
assert.match(process.env.ARTIFACT_ID, /^\d+$/);
117119
const globber = await glob.create('downloaded-reports/**/*', { matchDirectories: false });
118120
const files = await globber.glob();
119-
assert.equal(files.length, 2);
121+
const expectedFiles = JSON.parse(process.env.ARTIFACT_FILES);
122+
assert.deepEqual(files.map(file => require('node:path').basename(file)).sort(), expectedFiles.sort());
120123
const junit = fs.readFileSync(files.find(file => file.endsWith('junit.xml')), 'utf8');
121124
assert.equal(junit.includes('<failure'), process.env.EXPECT_FAILURE === 'true');
122-
assert.match(fs.readFileSync(files.find(file => file.endsWith('lcov.info')), 'utf8'), /SF:/);
125+
if (expectedFiles.includes('lcov.info')) {
126+
assert.match(fs.readFileSync(files.find(file => file.endsWith('lcov.info')), 'utf8'), /SF:/);
127+
}

‎.github/workflows/__test-workflow-continuous-integration.yml‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ jobs:
290290
"artifact": "dist"
291291
}
292292
test: |
293-
{"coverage": "github"}
293+
{"comment": false, "report-group": "act-without-container-and-github-reports"}
294294
# jscpd:ignore-end
295295

296296
assert-package-disabled:
@@ -302,6 +302,19 @@ jobs:
302302
- env:
303303
PACKAGE_ARTIFACT_ID: ${{ needs.act-without-container-and-github-reports.outputs.package-tarball-artifact-id }}
304304
run: test -z "$PACKAGE_ARTIFACT_ID"
305+
- name: Retrieve coverage by the outer calling job ID
306+
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
307+
with:
308+
pattern: ci-reports-${{ github.run_attempt }}-act-without-container-and-github-reports-*
309+
path: native-reports
310+
- name: Check that consolidated reporting can find the native coverage
311+
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
312+
with:
313+
script: |
314+
const assert = require('node:assert/strict');
315+
const files = await (await glob.create('native-reports/**/lcov.info')).glob();
316+
assert.equal(files.length, 1);
317+
assert.match(require('node:fs').readFileSync(files[0], 'utf8'), /SF:/);
305318
306319
arrange-with-container:
307320
name: Arrange - Build container image for CI workflow

‎.github/workflows/continuous-integration.md‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# GitHub Reusable Workflow: Node.js Continuous Integration
44

55
<div align="center">
6-
<img src="https://opengraph.githubassets.com/798861777139bae96adc7ee652339a4713d1b50ce3b11cfb3ce6c363f2339b53/hoverkraft-tech/ci-github-nodejs" width="60px" align="center" alt="Node.js Continuous Integration" />
6+
<img src="https://opengraph.githubassets.com/7e9813f9e19bd5adf686a5ff854c41da9068e2fb45a0d01f3d74b94a77ffe027/hoverkraft-tech/ci-github-nodejs" width="60px" align="center" alt="Node.js Continuous Integration" />
77
</div>
88

99
---
@@ -16,7 +16,6 @@
1616
[![License](https://img.shields.io/github/license/hoverkraft-tech/ci-github-nodejs)](http://choosealicense.com/licenses/mit/)
1717
[![Stars](https://img.shields.io/github/stars/hoverkraft-tech/ci-github-nodejs?style=social)](https://img.shields.io/github/stars/hoverkraft-tech/ci-github-nodejs?style=social)
1818
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/hoverkraft-tech/ci-github-nodejs/blob/main/CONTRIBUTING.md)
19-
![GitHub Verified Creator](https://img.shields.io/badge/GitHub-Verified%20Creator-4493F8?logo=data:image/svg%2bxml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxNiAxNiIgd2lkdGg9IjE2IiBoZWlnaHQ9IjE2IiBmaWxsPSJyZ2IoNjgsIDE0NywgMjQ4KSI+CiAgPHBhdGggZD0ibTkuNTg1LjUyLjkyOS42OGMuMTUzLjExMi4zMzEuMTg2LjUxOC4yMTVsMS4xMzguMTc1YTIuNjc4IDIuNjc4IDAgMCAxIDIuMjQgMi4yNGwuMTc0IDEuMTM5Yy4wMjkuMTg3LjEwMy4zNjUuMjE1LjUxOGwuNjguOTI4YTIuNjc3IDIuNjc3IDAgMCAxIDAgMy4xN2wtLjY4LjkyOGExLjE3NCAxLjE3NCAwIDAgMC0uMjE1LjUxOGwtLjE3NSAxLjEzOGEyLjY3OCAyLjY3OCAwIDAgMS0yLjI0MSAyLjI0MWwtMS4xMzguMTc1YTEuMTcgMS4xNyAwIDAgMC0uNTE4LjIxNWwtLjkyOC42OGEyLjY3NyAyLjY3NyA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4xOGwtLjE3NC0xLjEzN2ExLjE3OSAxLjE3OSAwIDAgMC0uOTg3LS45ODdsLTEuMTM2LS4xNzRhMi42NzcgMi42NzcgMCAwIDEtMS4xOC0uNDg5bC0uOTI4LS42OGExLjE3NiAxLjE3NiAwIDAgMC0xLjM5NCAwWk0xMS4yOCA2Ljc4bC0zLjc1IDMuNzVhLjc1Ljc1IDAgMCAxLTEuMDYgMEw0LjcyIDguNzhhLjc1MS43NTEgMCAwIDEgLjAxOC0xLjA0Mi43NTEuNzUxIDAgMCAxIDEuMDQyLS4wMThMNyA4Ljk0bDMuMjItMy4yMmEuNzUxLjc1MSAwIDAgMSAxLjA0Mi4wMTguNzUxLjc1MSAwIDAgMSAuMDE4IDEuMDQyWiI+PC9wYXRoPgo8L3N2Zz4K)
2019

2120
<!-- badges:end -->
2221

@@ -193,6 +192,8 @@ jobs:
193192
# Set to `null` or empty to disable.
194193
# Accepts a JSON object for test options. See [test action](../../actions/test/README.md).
195194
# If coverage is enabled, it should generate test and coverage reports in standard formats.
195+
# For consolidated reports, set `comment` to false and `report-group` to the calling job ID
196+
# used in the common `ci-reports` workflow's `job-results`.
196197
#
197198
# Example:
198199
#
@@ -326,6 +327,8 @@ jobs:
326327
| | Set to `null` or empty to disable. | | | |
327328
| | Accepts a JSON object for test options. See [test action](../../actions/test/README.md). | | | |
328329
| | If coverage is enabled, it should generate test and coverage reports in standard formats. | | | |
330+
| | For consolidated reports, set `comment` to false and `report-group` to the calling job ID | | | |
331+
| | used in the common `ci-reports` workflow's `job-results`. | | | |
329332
| | | | | |
330333
| | Example: | | | |
331334
| | | | | |

‎.github/workflows/continuous-integration.yml‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ on:
128128
Set to `null` or empty to disable.
129129
Accepts a JSON object for test options. See [test action](../../actions/test/README.md).
130130
If coverage is enabled, it should generate test and coverage reports in standard formats.
131+
For consolidated reports, set `comment` to false and `report-group` to the calling job ID
132+
used in the common `ci-reports` workflow's `job-results`.
131133
132134
Example:
133135
@@ -680,7 +682,16 @@ jobs:
680682
if (testOptions.coverage === undefined) {
681683
testOptions.coverage = 'github';
682684
}
685+
if (testOptions.comment !== undefined && typeof testOptions.comment !== 'boolean') {
686+
throw new Error('test.comment must be a boolean.');
687+
}
688+
if (testOptions['report-group'] !== undefined &&
689+
(typeof testOptions['report-group'] !== 'string' || !/^[\w-]+$/.test(testOptions['report-group']))) {
690+
throw new Error('test.report-group must be a job ID containing letters, numbers, underscores or hyphens.');
691+
}
683692
core.setOutput('coverage', testOptions.coverage );
693+
core.setOutput('comment', testOptions.comment ?? true);
694+
core.setOutput('report-group', testOptions['report-group'] || '');
684695
core.setOutput('report-file', testOptions['report-file'] || '');
685696
core.setOutput('command', testOptions.command || 'test:ci');
686697
@@ -692,6 +703,8 @@ jobs:
692703
container: ${{ inputs.container != '' && 'true' || 'false' }}
693704
command: ${{ steps.prepare-test-options.outputs.command }}
694705
coverage: ${{ steps.prepare-test-options.outputs.coverage }}
706+
comment: ${{ steps.prepare-test-options.outputs.comment }}
707+
report-group: ${{ steps.prepare-test-options.outputs.report-group }}
695708
report-file: ${{ steps.prepare-test-options.outputs.report-file }}
696709
path-mapping: ${{ needs.prepare.outputs.path-mapping || '' }}
697710
github-token: ${{ secrets.github-token || github.token }}

‎actions/test/README.md‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# ![Icon](data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0IiBmaWxsPSJub25lIiBzdHJva2U9ImN1cnJlbnRDb2xvciIgc3Ryb2tlLXdpZHRoPSIyIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiIGNsYXNzPSJmZWF0aGVyIGZlYXRoZXItY2hlY2stc3F1YXJlIiBjb2xvcj0iYmx1ZSI+PHBvbHlsaW5lIHBvaW50cz0iOSAxMSAxMiAxNCAyMiA0Ij48L3BvbHlsaW5lPjxwYXRoIGQ9Ik0yMSAxMnY3YTIgMiAwIDAgMS0yIDJINWEyIDIgMCAwIDEtMi0yVjVhMiAyIDAgMCAxIDItMmgxMSI+PC9wYXRoPjwvc3ZnPg==) GitHub Action: Test
44

55
<div align="center">
6-
<img src="https://opengraph.githubassets.com/798861777139bae96adc7ee652339a4713d1b50ce3b11cfb3ce6c363f2339b53/hoverkraft-tech/ci-github-nodejs" width="60px" align="center" alt="Test" />
6+
<img src="https://opengraph.githubassets.com/7e9813f9e19bd5adf686a5ff854c41da9068e2fb45a0d01f3d74b94a77ffe027/hoverkraft-tech/ci-github-nodejs" width="60px" align="center" alt="Test" />
77
</div>
88

99
---
@@ -16,7 +16,6 @@
1616
[![License](https://img.shields.io/github/license/hoverkraft-tech/ci-github-nodejs)](http://choosealicense.com/licenses/mit/)
1717
[![Stars](https://img.shields.io/github/stars/hoverkraft-tech/ci-github-nodejs?style=social)](https://img.shields.io/github/stars/hoverkraft-tech/ci-github-nodejs?style=social)
1818
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/hoverkraft-tech/ci-github-nodejs/blob/main/CONTRIBUTING.md)
19-
![GitHub Verified Creator](https://img.shields.io/badge/GitHub-Verified%20Creator-4493F8?logo=data:image/svg%2bxml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxNiAxNiIgd2lkdGg9IjE2IiBoZWlnaHQ9IjE2IiBmaWxsPSJyZ2IoNjgsIDE0NywgMjQ4KSI+CiAgPHBhdGggZD0ibTkuNTg1LjUyLjkyOS42OGMuMTUzLjExMi4zMzEuMTg2LjUxOC4yMTVsMS4xMzguMTc1YTIuNjc4IDIuNjc4IDAgMCAxIDIuMjQgMi4yNGwuMTc0I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DE0LjMwNS45NzkuMzA1IDEuMzk0IDBsLjkyNy0uNjhhMi42NyAyLjY3IDAgMCAxIDEuMTgtLjQ4OWwxLjEzNy0uMTc0YTEuMTggMS4xOCAwIDAgMCAuOTg3LS45ODdsLjE3NC0xLjEzNmEyLjY3IDIuNjcgMCAwIDEgLjQ4OS0xLjE4bC42OC0uOTI4YTEuMTc2IDEuMTc2IDAgMCAwIDAtMS4zOTRsLS42OC0uOTI3YTIuNjg2IDIuNjg2IDAgMCAxLS40ODktMS4xOGwtLjE3NC0xLjEzN2ExLjE3OSAxLjE3OSAwIDAgMC0uOTg3LS45ODdsLTEuMTM2LS4xNzRhMi42NzcgMi42NzcgMCAwIDEtMS4xOC0uNDg5bC0uOTI4LS42OGExLjE3NiAxLjE3NiAwIDAgMC0xLjM5NCAwWk0xMS4yOCA2Ljc4bC0zLjc1IDMuNzVhLjc1Ljc1IDAgMCAxLTEuMDYgMEw0LjcyIDguNzhhLjc1MS43NTEgMCAwIDEgLjAxOC0xLjA0Mi43NTEuNzUxIDAgMCAxIDEuMDQyLS4wMThMNyA4Ljk0bDMuMjItMy4yMmEuNzUxLjc1MSAwIDAgMSAxLjA0Mi4wMTguNzUxLjc1MSAwIDAgMSAuMDE4IDEuMDQyWiI+PC9wYXRoPgo8L3N2Zz4K)
2019

2120
<!-- badges:end -->
2221

@@ -46,7 +45,7 @@ permissions:
4645
## Usage
4746
4847
```yaml
49-
- uses: hoverkraft-tech/ci-github-nodejs/actions/test@0340fba99303d160fd476ff1e7766125b632dcf9 # ci/adopt-common-3
48+
- uses: hoverkraft-tech/ci-github-nodejs/actions/test@02a04ad25ceaacdf3b7200e45fb7fec07fadf4fa # 2.1.0
5049
with:
5150
# Disable project and dependency lifecycle scripts during installation.
5251
# Set false to allow installation hooks, subject to the package manager's script approval settings.
@@ -100,6 +99,11 @@ permissions:
10099
# Default: `true`
101100
comment: "true"
102101

102+
# Job ID used to associate native reports with the common ci-reports workflow's job-results.
103+
# Defaults to the current job ID. Set the outer calling job ID for nested reusable workflows.
104+
# Matrix runs keep separate artifacts labeled with their working directory.
105+
report-group: ""
106+
103107
# GitHub token for coverage PR comments.
104108
# Required when coverage is `github` and individual comments are enabled.
105109
# Requires permissions to create and update PR comments:
@@ -142,6 +146,9 @@ permissions:
142146
| **`path-mapping`** | Optional path mapping to adjust file paths in test and coverage reports. | **false** | - |
143147
| | See the [parse-ci-reports documentation](https://github.com/hoverkraft-tech/ci-github-common/tree/main/actions/quality/parse-ci-reports) for details. | | |
144148
| **`comment`** | Publish an individual coverage PR comment. Set false when using the common ci-reports workflow; GitHub summaries and report artifacts remain enabled. | **false** | `true` |
149+
| **`report-group`** | Job ID used to associate native reports with the common ci-reports workflow's job-results. | **false** | - |
150+
| | Defaults to the current job ID. Set the outer calling job ID for nested reusable workflows. | | |
151+
| | Matrix runs keep separate artifacts labeled with their working directory. | | |
145152
| **`github-token`** | GitHub token for coverage PR comments. | **false** | - |
146153
| | Required when coverage is `github` and individual comments are enabled. | | |
147154
| | Requires permissions to create and update PR comments: | | |

0 commit comments

Comments
 (0)