Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ Powered by [Job Summaries](https://github.blog/2022-05-09-supercharging-github-a
# Optional. No default
fromJSONFile:

# Parse multiple [test2json](https://pkg.go.dev/cmd/test2json) files (newline-separated) and generate a combined summary.
# Will always exit(0) on successful test file parse.
# Optional. No default
fromJSONFiles:

# Whitespace separated list of renderable items to omit.
# Valid options to omit are:
# untested: packages that have no tests
Expand Down
15 changes: 15 additions & 0 deletions __tests__/inputs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ describe('renderer', () => {
moduleDirectory: '.',
testArguments: ['./...'],
fromJSONFile: null,
fromJSONFiles: null,
omit: new Set(),
})
})
Expand All @@ -50,6 +51,20 @@ describe('renderer', () => {
expect(inputs.fromJSONFile).toEqual('foo.json')
})

it('parses fromJSONFiles', () => {
mockInput('fromJSONFiles', 'foo.json\nbar.json')
const inputs = getInputs()

expect(inputs.fromJSONFiles).toEqual(['foo.json', 'bar.json'])
})

it('trims whitespace and filters empty lines in fromJSONFiles', () => {
mockInput('fromJSONFiles', ' foo.json \n\n bar.json\n')
const inputs = getInputs()

expect(inputs.fromJSONFiles).toEqual(['foo.json', 'bar.json'])
})

it('parses omit', () => {
mockInput(
'omit',
Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ inputs:
fromJSONFile:
description: 'Parse the specified JSON file, instead of executing go test'
required: false
fromJSONFiles:
description: 'Parse multiple JSON files (newline-separated) and generate a combined summary'
required: false
omit:
description: 'Whitespace separated list of renderable items to omit. See README.md for details.'
required: false
Expand Down
6 changes: 3 additions & 3 deletions dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "go-test-action",
"version": "0.5.0",
"version": "0.5.1",
"description": "GitHub Action to run go tests with rich summary output and annotations.",
"main": "dist/index.js",
"scripts": {
Expand Down
10 changes: 10 additions & 0 deletions src/inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export interface Inputs {
moduleDirectory: string
testArguments: string[]
fromJSONFile: string | null
fromJSONFiles: string[] | null
omit: Set<OmitOption>
}

Expand All @@ -26,6 +27,7 @@ export const defaultInputs = (): Inputs => ({
moduleDirectory: '.',
testArguments: ['./...'],
fromJSONFile: null,
fromJSONFiles: null,
omit: new Set(),
})

Expand Down Expand Up @@ -55,6 +57,14 @@ export function getInputs(): Inputs {
inputs.fromJSONFile = fromJSONFile
}

const fromJSONFiles = core.getInput('fromJSONFiles')
if (fromJSONFiles) {
inputs.fromJSONFiles = fromJSONFiles
.split('\n')
.map(f => f.trim())
.filter(f => f.length > 0)
}

const omit = core.getInput('omit')
if (omit) {
omit
Expand Down
18 changes: 17 additions & 1 deletion src/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,23 @@ class Runner {
async run() {
const moduleName = await this.findModuleName()

if (this.inputs.fromJSONFile) {
if (this.inputs.fromJSONFiles) {
const contents = await Promise.all(
this.inputs.fromJSONFiles.map(file => readFile(file))
)
const stdout = contents.map(c => c.toString()).join('\n')
const testEvents = parseTestEvents(stdout)

const renderer = new Renderer(
moduleName,
testEvents,
'',
this.inputs.omit
)

await renderer.writeSummary()
process.exit(0)
} else if (this.inputs.fromJSONFile) {
const stdout = await readFile(this.inputs.fromJSONFile)
const testEvents = parseTestEvents(stdout.toString())

Expand Down