Skip to content

Commit 2444234

Browse files
committed
Added the action's code
1 parent e658a84 commit 2444234

35 files changed

+7128
-0
lines changed

README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,48 @@
11
# golang-test-annoations
22
A github action which annotates failed tests.
3+
4+
![GitHub Annotations](./static/example.png)
5+
6+
## How to use
7+
8+
Add to your workflow the following contents:
9+
10+
```yaml
11+
name: workflow
12+
13+
on:
14+
push:
15+
branches: [ '**' ]
16+
pull_request:
17+
branches: [ '**' ]
18+
19+
jobs:
20+
full_ci:
21+
runs-on: ubuntu-18.04
22+
23+
steps:
24+
- name : checkout
25+
uses: actions/checkout@v2
26+
27+
- uses: actions/setup-go@v2
28+
with:
29+
go-version: '1.14'
30+
31+
- name: run tests
32+
run: go test -json ./... > test.json
33+
34+
- name: annotate tests
35+
if: always()
36+
uses: guyarb/[email protected]
37+
with:
38+
test-results: test.json
39+
```
40+
41+
## Development of this action
42+
43+
1. Fork this repo.
44+
2. Create a branch with your feature/bugfix.
45+
3. Open a PR to me.
46+
47+
## Issues
48+
Please open issues for any bug or suggestion you have.

action.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: 'Golang Test Annotations'
2+
description: 'Given a test output of go test, the failed tests will be annotated.'
3+
inputs:
4+
test-results: # Path of the test results
5+
description: 'The path of the go test results'
6+
required: true
7+
default: 'test.json'
8+
runs:
9+
using: 'node12'
10+
main: 'index.js'
11+
branding:
12+
icon: "check"
13+
color: "green"

index.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
const core = require('@actions/core');
2+
const lineReader = require('line-by-line');
3+
4+
try {
5+
const testResultsPath = core.getInput('test-results');
6+
7+
var obj = new Object();
8+
var lr = new lineReader(testResultsPath);
9+
lr.on('line', function(line) {
10+
const currentLine = JSON.parse(line);
11+
var testName = currentLine.Test;
12+
if (typeof testName === "undefined") {
13+
return;
14+
}
15+
16+
var output = currentLine.Output;
17+
if (typeof output === "undefined") {
18+
return;
19+
}
20+
output = output.replace("\n", "%0A").replace("\r", "%0D")
21+
// Removing the github.com/owner/reponame
22+
var packageName = currentLine.Package.split("/").slice(3).join("/");
23+
var newEntry = packageName + "/" + testName;
24+
if (!obj.hasOwnProperty(newEntry)) {
25+
obj[newEntry] = output;
26+
} else {
27+
obj[newEntry] += output;
28+
}
29+
});
30+
lr.on('end', function() {
31+
for (const [key, value] of Object.entries(obj)) {
32+
if (value.includes("FAIL") && value.includes("_test.go")) {
33+
const parts = value.split("%0A")[1].trim().split(":");
34+
const file = key.split("/").slice(0, -1).join("/") + "/" + parts[0];
35+
const lineNumber = parts[1];
36+
core.info(`::error file=${file},line=${lineNumber}::${value}`)
37+
}
38+
}
39+
});
40+
} catch (error) {
41+
core.setFailed(error.message);
42+
}

node_modules/@actions/core/LICENSE.md

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/@actions/core/README.md

Lines changed: 147 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/@actions/core/lib/command.d.ts

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/@actions/core/lib/command.js

Lines changed: 92 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/@actions/core/lib/command.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)