Skip to content

Commit

Permalink
Added the action's code
Browse files Browse the repository at this point in the history
  • Loading branch information
guyarb committed Sep 17, 2020
1 parent e658a84 commit 2444234
Show file tree
Hide file tree
Showing 35 changed files with 7,128 additions and 0 deletions.
46 changes: 46 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,48 @@
# golang-test-annoations
A github action which annotates failed tests.

![GitHub Annotations](./static/example.png)

## How to use

Add to your workflow the following contents:

```yaml
name: workflow

on:
push:
branches: [ '**' ]
pull_request:
branches: [ '**' ]

jobs:
full_ci:
runs-on: ubuntu-18.04

steps:
- name : checkout
uses: actions/checkout@v2

- uses: actions/setup-go@v2
with:
go-version: '1.14'

- name: run tests
run: go test -json ./... > test.json

- name: annotate tests
if: always()
uses: guyarb/golang-test-annoations@v0.1
with:
test-results: test.json
```
## Development of this action
1. Fork this repo.
2. Create a branch with your feature/bugfix.
3. Open a PR to me.
## Issues
Please open issues for any bug or suggestion you have.
13 changes: 13 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: 'Golang Test Annotations'
description: 'Given a test output of go test, the failed tests will be annotated.'
inputs:
test-results: # Path of the test results
description: 'The path of the go test results'
required: true
default: 'test.json'
runs:
using: 'node12'
main: 'index.js'
branding:
icon: "check"
color: "green"
42 changes: 42 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
const core = require('@actions/core');
const lineReader = require('line-by-line');

try {
const testResultsPath = core.getInput('test-results');

var obj = new Object();
var lr = new lineReader(testResultsPath);
lr.on('line', function(line) {
const currentLine = JSON.parse(line);
var testName = currentLine.Test;
if (typeof testName === "undefined") {
return;
}

var output = currentLine.Output;
if (typeof output === "undefined") {
return;
}
output = output.replace("\n", "%0A").replace("\r", "%0D")
// Removing the github.com/owner/reponame
var packageName = currentLine.Package.split("/").slice(3).join("/");
var newEntry = packageName + "/" + testName;
if (!obj.hasOwnProperty(newEntry)) {
obj[newEntry] = output;
} else {
obj[newEntry] += output;
}
});
lr.on('end', function() {
for (const [key, value] of Object.entries(obj)) {
if (value.includes("FAIL") && value.includes("_test.go")) {
const parts = value.split("%0A")[1].trim().split(":");
const file = key.split("/").slice(0, -1).join("/") + "/" + parts[0];
const lineNumber = parts[1];
core.info(`::error file=${file},line=${lineNumber}::${value}`)
}
}
});
} catch (error) {
core.setFailed(error.message);
}
9 changes: 9 additions & 0 deletions node_modules/@actions/core/LICENSE.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

147 changes: 147 additions & 0 deletions node_modules/@actions/core/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions node_modules/@actions/core/lib/command.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

92 changes: 92 additions & 0 deletions node_modules/@actions/core/lib/command.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/@actions/core/lib/command.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 2444234

Please sign in to comment.