Skip to content

Commit 5c5f1c5

Browse files
Copilotneilime
andcommitted
Rename action to parse-ci-reports and refactor to use GitHub Actions script
Co-authored-by: neilime <314088+neilime@users.noreply.github.com>
1 parent 758bfe1 commit 5c5f1c5

563 files changed

Lines changed: 249 additions & 54158 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/dependabot.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,18 @@ updates:
2626
patterns:
2727
- "*"
2828

29+
- package-ecosystem: npm
30+
open-pull-requests-limit: 20
31+
directory: "/actions/parse-ci-reports"
32+
schedule:
33+
interval: weekly
34+
day: friday
35+
time: "04:00"
36+
groups:
37+
npm-dependencies:
38+
patterns:
39+
- "*"
40+
2941
- package-ecosystem: "devcontainers"
3042
open-pull-requests-limit: 20
3143
directory: "/"

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules/

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Opinionated GitHub Actions and reusable workflows for foundational continuous-in
3232

3333
### Repository insights & utilities
3434

35-
- [Parse test reports](actions/parse-test-reports/README.md) — parses check, lint, test reports, and coverage into GitHub summaries and Markdown for PR comments.
35+
- [Parse CI reports](actions/parse-ci-reports/README.md) — parses CI reports (tests, linting, coverage) into GitHub summaries and Markdown for PR comments.
3636
- [Repository owner is organization](actions/repository-owner-is-organization/README.md) — checks whether the repository owner is an organization.
3737
- [Slugify](actions/slugify/README.md) — converts free-form strings into GitHub-friendly slugs.
3838

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Parse Test Reports
1+
# Parse CI Reports
22

3-
Parse check, lint, test reports, and coverage into GitHub summary and Markdown for PR comments.
3+
Parse CI reports (tests, linting, coverage) into GitHub summary and Markdown for PR comments.
44

55
## Description
66

@@ -34,7 +34,7 @@ It supports multiple common report standards out of the box.
3434

3535
```yaml
3636
- name: Parse test reports
37-
uses: hoverkraft-tech/ci-github-common/actions/parse-test-reports@v1
37+
uses: hoverkraft-tech/ci-github-common/actions/parse-ci-reports@v1
3838
with:
3939
report-paths: |
4040
**/junit.xml
@@ -48,7 +48,7 @@ It supports multiple common report standards out of the box.
4848
```yaml
4949
- name: Parse test reports
5050
id: parse-reports
51-
uses: hoverkraft-tech/ci-github-common/actions/parse-test-reports@v1
51+
uses: hoverkraft-tech/ci-github-common/actions/parse-ci-reports@v1
5252
with:
5353
report-paths: "**/test-results/*.xml"
5454
report-name: "Test Results"
@@ -65,7 +65,7 @@ It supports multiple common report standards out of the box.
6565
6666
```yaml
6767
- name: Parse coverage
68-
uses: hoverkraft-tech/ci-github-common/actions/parse-test-reports@v1
68+
uses: hoverkraft-tech/ci-github-common/actions/parse-ci-reports@v1
6969
with:
7070
report-paths: "coverage/cobertura-coverage.xml"
7171
report-name: "Coverage Report"
@@ -76,7 +76,7 @@ It supports multiple common report standards out of the box.
7676
7777
```yaml
7878
- name: Parse test reports
79-
uses: hoverkraft-tech/ci-github-common/actions/parse-test-reports@v1
79+
uses: hoverkraft-tech/ci-github-common/actions/parse-ci-reports@v1
8080
with:
8181
report-paths: "**/junit.xml"
8282
report-name: "Test Results"
@@ -120,7 +120,7 @@ Parse test results, coverage, and linting in one action:
120120
run: npm run lint -- --format json --output-file eslint-report.json
121121
122122
- name: Parse all reports
123-
uses: hoverkraft-tech/ci-github-common/actions/parse-test-reports@v1
123+
uses: hoverkraft-tech/ci-github-common/actions/parse-ci-reports@v1
124124
with:
125125
report-paths: |
126126
test-results/junit.xml
@@ -136,7 +136,7 @@ Only comment on PRs if there are failures:
136136
```yaml
137137
- name: Parse test reports
138138
id: parse-reports
139-
uses: hoverkraft-tech/ci-github-common/actions/parse-test-reports@v1
139+
uses: hoverkraft-tech/ci-github-common/actions/parse-ci-reports@v1
140140
with:
141141
report-paths: "**/test-results/*.xml"
142142
report-name: "Test Results"
@@ -162,7 +162,7 @@ Only comment on PRs if there are failures:
162162
run: mvn test
163163
164164
- name: Parse all test reports
165-
uses: hoverkraft-tech/ci-github-common/actions/parse-test-reports@v1
165+
uses: hoverkraft-tech/ci-github-common/actions/parse-ci-reports@v1
166166
with:
167167
report-paths: |
168168
pytest-results.xml
@@ -197,7 +197,7 @@ src/
197197
### Running Tests
198198

199199
```bash
200-
cd actions/parse-test-reports
200+
cd actions/parse-ci-reports
201201
npm install
202202
npm test
203203
```
Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
name: "Parse Test Reports"
2-
description: "Parse check, lint, test reports and coverage into GitHub summary and markdown for PR comments"
1+
name: "Parse CI Reports"
2+
description: "Parse CI reports (tests, linting, coverage) into GitHub summary and Markdown for PR comments"
33
author: hoverkraft
44
branding:
55
icon: check-circle
@@ -57,27 +57,47 @@ outputs:
5757
runs:
5858
using: "composite"
5959
steps:
60-
- name: Parse reports
61-
id: parse-reports
62-
shell: bash
63-
run: |
64-
node ${{ github.action_path }}/src/index.js \
65-
"${{ inputs.report-paths }}" \
66-
"${{ inputs.report-name }}" \
67-
"${{ inputs.include-passed }}" \
68-
"${{ inputs.output-format }}"
60+
- name: Setup Node.js
61+
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
62+
with:
63+
node-version: "18"
6964

70-
- name: Write to GitHub Step Summary
71-
if: inputs.output-format == 'summary' || inputs.output-format == 'both'
65+
- name: Install dependencies
7266
shell: bash
7367
run: |
74-
if [ -f /tmp/test-report-summary.md ]; then
75-
cat /tmp/test-report-summary.md >> $GITHUB_STEP_SUMMARY
76-
fi
68+
cd ${{ github.action_path }}
69+
npm ci --omit=dev
70+
71+
- name: Parse reports
72+
id: parse-reports
73+
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
74+
env:
75+
REPORT_PATHS: ${{ inputs.report-paths }}
76+
REPORT_NAME: ${{ inputs.report-name }}
77+
INCLUDE_PASSED: ${{ inputs.include-passed }}
78+
OUTPUT_FORMAT: ${{ inputs.output-format }}
79+
ACTION_PATH: ${{ github.action_path }}
80+
with:
81+
script: |
82+
const fs = require('fs');
83+
const path = require('path');
84+
85+
// Import the action runner
86+
const actionPath = process.env.ACTION_PATH;
87+
const { runAction } = require(path.join(actionPath, 'src', 'index-action.js'));
88+
89+
const inputs = {
90+
reportPaths: process.env.REPORT_PATHS,
91+
reportName: process.env.REPORT_NAME,
92+
includePassed: process.env.INCLUDE_PASSED === 'true',
93+
outputFormat: process.env.OUTPUT_FORMAT
94+
};
95+
96+
await runAction({ core, glob, inputs });
7797
7898
- name: Fail if errors detected
7999
if: inputs.fail-on-error == 'true' && steps.parse-reports.outputs.has-errors == 'true'
80-
shell: bash
81-
run: |
82-
echo "::error::Test failures or errors detected in reports"
83-
exit 1
100+
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
101+
with:
102+
script: |
103+
core.setFailed('Test failures or errors detected in reports');
File renamed without changes.
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
2-
"name": "parse-test-reports",
2+
"name": "parse-ci-reports",
33
"version": "1.0.0",
4-
"description": "Parse test, lint, and coverage reports into GitHub summaries and markdown",
4+
"description": "Parse CI reports (tests, linting, coverage) into GitHub summaries and Markdown",
55
"main": "src/index.js",
66
"type": "module",
77
"scripts": {
@@ -10,12 +10,16 @@
1010
},
1111
"keywords": [
1212
"github-action",
13+
"ci-reports",
1314
"test-reports",
1415
"coverage",
16+
"linting",
1517
"junit",
1618
"tap",
1719
"lcov",
18-
"cobertura"
20+
"cobertura",
21+
"eslint",
22+
"checkstyle"
1923
],
2024
"author": "hoverkraft",
2125
"license": "MIT",
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import { readFileSync } from "fs";
2+
import { ParserFactory } from "./parsers/ParserFactory.js";
3+
import { SummaryFormatter } from "./formatters/SummaryFormatter.js";
4+
import { MarkdownFormatter } from "./formatters/MarkdownFormatter.js";
5+
import { ReportData } from "./models/ReportData.js";
6+
7+
/**
8+
* Core report parsing logic shared between CLI and Action
9+
*/
10+
export class ReportParserCore {
11+
constructor() {
12+
this.parserFactory = new ParserFactory();
13+
this.summaryFormatter = new SummaryFormatter();
14+
this.markdownFormatter = new MarkdownFormatter();
15+
}
16+
17+
/**
18+
* Parse all report files
19+
* @param {string[]} files - Array of file paths
20+
* @param {Function} logger - Logging function (info)
21+
* @param {Function} errorLogger - Error logging function
22+
* @returns {ReportData} Aggregated report data
23+
*/
24+
parseReports(files, logger = console.log, errorLogger = console.error) {
25+
const aggregatedData = new ReportData();
26+
27+
for (const file of files) {
28+
try {
29+
logger(`Parsing ${file}...`);
30+
const content = readFileSync(file, "utf-8");
31+
const reportData = this.parserFactory.parse(file, content);
32+
33+
// Merge data
34+
aggregatedData.tests.push(...reportData.tests);
35+
aggregatedData.lintIssues.push(...reportData.lintIssues);
36+
37+
if (reportData.coverage) {
38+
aggregatedData.setCoverage(reportData.coverage);
39+
}
40+
} catch (error) {
41+
errorLogger(`Error parsing ${file}: ${error.message}`);
42+
// Continue with other files
43+
}
44+
}
45+
46+
return aggregatedData;
47+
}
48+
49+
/**
50+
* Generate formatted output
51+
* @param {ReportData} reportData - The parsed report data
52+
* @param {string} reportName - Name of the report
53+
* @param {boolean} includePassed - Include passed tests
54+
* @param {string} outputFormat - Output format (summary, markdown, both)
55+
* @returns {Object} Object with markdown and summary strings
56+
*/
57+
generateOutput(reportData, reportName, includePassed, outputFormat) {
58+
let markdown = "";
59+
let summary = "";
60+
61+
if (outputFormat === "markdown" || outputFormat === "both") {
62+
markdown = this.markdownFormatter.format(reportData, reportName);
63+
}
64+
65+
if (outputFormat === "summary" || outputFormat === "both") {
66+
summary = this.summaryFormatter.format(
67+
reportData,
68+
reportName,
69+
includePassed,
70+
);
71+
}
72+
73+
return { markdown, summary };
74+
}
75+
}

actions/parse-test-reports/src/formatters/BaseFormatter.js renamed to actions/parse-ci-reports/src/formatters/BaseFormatter.js

File renamed without changes.

0 commit comments

Comments
 (0)