Skip to content

Commit 932863b

Browse files
feat: step summary of test results (#1580)
* feat: step summary of test results * fix: indent style * fix: handle failed tests * fix upload / create a logs artifact * Update checks.yml * fix: always upload logs * fix: run success * Move steps into a composite action * use args and not the hardcoded ones * format composite action * format
1 parent 09e9f6a commit 932863b

File tree

2 files changed

+86
-3
lines changed

2 files changed

+86
-3
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
name: 'run-tests'
2+
description: 'Runs go test and upload a step summary'
3+
inputs:
4+
filter:
5+
description: 'The go test pattern for the tests to run'
6+
required: false
7+
default: ''
8+
upload-logs-name:
9+
description: 'Choose the name of the log artifact'
10+
required: false
11+
default: logs-${{ github.job }}-${{ strategy.job-index }}
12+
upload-logs:
13+
description: 'If true uploads logs of each tests as an artifact'
14+
required: false
15+
default: 'true'
16+
runs:
17+
using: composite
18+
steps:
19+
- uses: actions/github-script@v6
20+
with:
21+
github-token: none # No reason to grant access to the GITHUB_TOKEN
22+
script: |
23+
let myOutput = '';
24+
var fs = require('fs');
25+
var uploadLogs = process.env.UPLOAD_LOGS === 'true';
26+
if(uploadLogs) {
27+
await io.mkdirP('logs');
28+
}
29+
var filename = null;
30+
const options = {};
31+
options.ignoreReturnCode = true;
32+
options.env = Object.assign({}, process.env);
33+
delete options.env.ACTIONS_RUNTIME_URL;
34+
delete options.env.ACTIONS_RUNTIME_TOKEN;
35+
delete options.env.ACTIONS_CACHE_URL;
36+
options.listeners = {
37+
stdout: (data) => {
38+
for(line of data.toString().split('\n')) {
39+
if(/^\s*(===\s[^\s]+\s|---\s[^\s]+:\s)/.test(line)) {
40+
if(uploadLogs) {
41+
var runprefix = "=== RUN ";
42+
if(line.startsWith(runprefix)) {
43+
filename = "logs/" + line.substring(runprefix.length).replace(/[^A-Za-z0-9]/g, '-') + ".txt";
44+
fs.writeFileSync(filename, line + "\n");
45+
} else if(filename) {
46+
fs.appendFileSync(filename, line + "\n");
47+
filename = null;
48+
}
49+
}
50+
myOutput += line + "\n";
51+
} else if(filename) {
52+
fs.appendFileSync(filename, line + "\n");
53+
}
54+
}
55+
}
56+
};
57+
var args = ['test', '-v', '-cover', '-coverprofile=coverage.txt', '-covermode=atomic', '-timeout', '15m'];
58+
var filter = process.env.FILTER;
59+
if(filter) {
60+
args.push('-run');
61+
args.push(filter);
62+
}
63+
args.push('./...');
64+
var exitcode = await exec.exec('go', args, options);
65+
if(process.env.GITHUB_STEP_SUMMARY) {
66+
core.summary.addCodeBlock(myOutput);
67+
await core.summary.write();
68+
}
69+
process.exit(exitcode);
70+
env:
71+
FILTER: ${{ inputs.filter }}
72+
UPLOAD_LOGS: ${{ inputs.upload-logs }}
73+
- uses: actions/upload-artifact@v3
74+
if: always() && inputs.upload-logs == 'true' && !env.ACT
75+
with:
76+
name: ${{ inputs.upload-logs-name }}
77+
path: logs

.github/workflows/checks.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@ jobs:
5050
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
5151
restore-keys: |
5252
${{ runner.os }}-go-
53-
- run: go test -v -cover -coverprofile=coverage.txt -covermode=atomic -timeout 15m ./...
53+
- name: Run Tests
54+
uses: ./.github/actions/run-tests
55+
with:
56+
upload-logs-name: logs-linux
5457
- name: Upload Codecov report
5558
uses: codecov/[email protected]
5659
with:
@@ -73,8 +76,11 @@ jobs:
7376
with:
7477
go-version: ${{ env.GO_VERSION }}
7578
check-latest: true
76-
- run: go test -v -run ^TestRunEventHostEnvironment$ ./...
77-
# TODO merge coverage with test-linux
79+
- name: Run Tests
80+
uses: ./.github/actions/run-tests
81+
with:
82+
filter: '^TestRunEventHostEnvironment$'
83+
upload-logs-name: logs-${{ matrix.os }}
7884

7985
snapshot:
8086
name: snapshot

0 commit comments

Comments
 (0)