Skip to content

Commit 85ceb49

Browse files
committed
Use simple parser for summary markdown.
1 parent 5a83237 commit 85ceb49

File tree

2 files changed

+69
-15
lines changed

2 files changed

+69
-15
lines changed

.github/parse-tests.js

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
const readline = require("readline");
2+
3+
const rl = readline.createInterface({
4+
input: process.stdin,
5+
output: process.stdout,
6+
terminal: false,
7+
});
8+
9+
const summary = { fail: [], pass: [], skip: [] };
10+
11+
rl.on("line", (line) => {
12+
const output = JSON.parse(line);
13+
if (
14+
output.Action === "pass" ||
15+
output.Action === "skip" ||
16+
output.Action === "fail"
17+
) {
18+
if (output.Test) {
19+
summary[output.Action].push(output);
20+
}
21+
}
22+
});
23+
24+
function totalTime(entries) {
25+
return entries.reduce((total, l) => total + l.Elapsed, 0);
26+
}
27+
28+
rl.on("close", () => {
29+
console.log("## Summary");
30+
console.log("| | # of Tests | Total Time |");
31+
console.log("|--|--|--|");
32+
console.log(
33+
"| Passed | %d | %fs |",
34+
summary.pass.length,
35+
totalTime(summary.pass)
36+
);
37+
console.log(
38+
"| Failed | %d | %fs |",
39+
summary.fail.length,
40+
totalTime(summary.fail)
41+
);
42+
console.log(
43+
"| Skipped | %d | %fs |",
44+
summary.skip.length,
45+
totalTime(summary.skip)
46+
);
47+
48+
if (summary.fail.length > 0) {
49+
console.log("\n## Failures\n");
50+
}
51+
52+
summary.fail.forEach((test) => {
53+
console.log("* %s (%s) %fs", test.Test, test.Package, test.Elapsed);
54+
});
55+
});
56+

.github/workflows/go.yml

+13-15
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,25 @@ name: Go
22

33
on:
44
push:
5-
branches: [ main ]
5+
branches: [main]
66
pull_request:
7-
branches: [ main ]
7+
branches: [main]
88

99
jobs:
10-
1110
build-and-test:
1211
runs-on: ubuntu-latest
1312
steps:
14-
- uses: actions/checkout@v3
13+
- uses: actions/checkout@v3
1514

16-
- name: Set up Go
17-
uses: actions/setup-go@v3
18-
with:
19-
go-version: 1.18
15+
- name: Set up Go
16+
uses: actions/setup-go@v3
17+
with:
18+
go-version: 1.18
2019

21-
- name: Build
22-
run: go build -v ./...
20+
- name: Build
21+
run: go build -v ./...
2322

24-
- name: Test
25-
run: |
26-
go install github.com/mfridman/tparse@latest
27-
set -o pipefail && go test ./... -json | tparse -all >> $GITHUB_STEP_SUMMARY
28-
echo $GITHUB_STEP_SUMMARY
23+
- name: Test
24+
run: |
25+
set -o pipefail && go test ./... -json | node .github/parse-tests.js >> $GITHUB_STEP_SUMMARY
26+
echo $GITHUB_STEP_SUMMARY

0 commit comments

Comments
 (0)