Skip to content

Commit

Permalink
multi: add omitSuccessfulPackages opt (#12)
Browse files Browse the repository at this point in the history
Co-authored-by: Rob Herley <robherley@github.com>
  • Loading branch information
torkelrogstad and robherley authored Apr 7, 2024
1 parent 6063fb3 commit 4c6caba
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Powered by [Job Summaries](https://github.blog/2022-05-09-supercharging-github-a
| moduleDirectory | `.` | relative path to the directory containing the `go.mod` of the module you wish to test |
| testArguments | `./...` | arguments to pass to `go test`, `-json` will be prepended automatically |
| omitUntestedPackages | `false` | omit any go packages that don't have any tests from the summary output |
| omitSuccessfulPackages | `false` | omit any go packages that didn't contain failed tests |
| omitPie | `false` | omit the pie chart from the summary output

## Demo
Expand Down
2 changes: 2 additions & 0 deletions __tests__/renderer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const getRenderer = async (): Promise<Renderer> => {
testEvents,
'', // stderr
false, // omitUntestedPackages
false, // omitSuccessfulPackages
false // omitPie
)
}
Expand Down Expand Up @@ -105,6 +106,7 @@ describe('renderer', () => {
[],
'',
false,
false,
false
)
await renderer.writeSummary()
Expand Down
11 changes: 8 additions & 3 deletions src/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class Renderer {
testEvents: TestEvent[]
stderr: string
omitUntestedPackages: boolean
omitSuccessfulPackages: boolean
omitPie: boolean
packageResults: PackageResult[]
headers: SummaryTableRow = [
Expand All @@ -36,12 +37,14 @@ class Renderer {
testEvents: TestEvent[],
stderr: string,
omitUntestedPackages: boolean,
omitSuccessfulPackages: boolean,
omitPie: boolean
) {
this.moduleName = moduleName
this.testEvents = testEvents
this.stderr = stderr
this.omitUntestedPackages = omitUntestedPackages
this.omitSuccessfulPackages = omitSuccessfulPackages
this.omitPie = omitPie
this.packageResults = this.calculatePackageResults()
}
Expand All @@ -51,9 +54,11 @@ class Renderer {
* https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#adding-a-job-summary
*/
async writeSummary() {
const resultsToRender = this.packageResults.filter(result =>
this.omitUntestedPackages ? result.hasTests() : true
)
const resultsToRender = this.packageResults
.filter(result => (this.omitUntestedPackages ? result.hasTests() : true))
.filter(result =>
this.omitSuccessfulPackages ? result.justSuccessfulTests() : true
)

if (resultsToRender.length === 0) {
core.debug('no packages with tests, skipping render')
Expand Down
4 changes: 4 additions & 0 deletions src/results.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ class PackageResult {
return this.testCount() !== 0
}

public justSuccessfulTests(): boolean {
return this.conclusions.pass === 0 && this.conclusions.fail === 0
}

public output(): string {
return this.events.map(e => e.output).join('')
}
Expand Down
10 changes: 10 additions & 0 deletions src/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class Runner {
moduleDirectory = '.'
testArguments = ['./...']
omitUntestedPackages = false
omitSuccessfulPackages = false
omitPie = false
fromJSONFile: string | null = null

Expand All @@ -34,6 +35,7 @@ class Runner {
testEvents,
'',
this.omitUntestedPackages,
this.omitSuccessfulPackages,
this.omitPie
)

Expand All @@ -53,6 +55,7 @@ class Runner {
testEvents,
stderr,
this.omitUntestedPackages,
this.omitSuccessfulPackages,
this.omitPie
)

Expand Down Expand Up @@ -139,6 +142,13 @@ class Runner {
this.omitUntestedPackages = core.getBooleanInput('omitUntestedPackages')
}

const omitSuccessfulPackages = core.getInput('omitSuccessfulPackages')
if (omitSuccessfulPackages) {
this.omitSuccessfulPackages = core.getBooleanInput(
'omitSuccessfulPackages'
)
}

const omitPie = core.getInput('omitPie')
if (omitPie) {
this.omitPie = core.getBooleanInput('omitPie')
Expand Down

0 comments on commit 4c6caba

Please sign in to comment.