-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
35 changed files
with
7,128 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.