Skip to content
This repository has been archived by the owner on Dec 12, 2024. It is now read-only.

Commit

Permalink
Add package name to summary for supporting monorepos (#23)
Browse files Browse the repository at this point in the history
* Add package in comment to support monorepos

* Fix action input definition

* fix test

* rename commentPackage ->
packageName

* cleanup
  • Loading branch information
leordev authored Oct 1, 2024
1 parent dac6f9c commit 9f2ebf8
Show file tree
Hide file tree
Showing 9 changed files with 117 additions and 12 deletions.
3 changes: 2 additions & 1 deletion .github/actions/specs-report/__tests__/spec-release.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ describe('handleSdkRelease', () => {
commentOnPr: false,
failOnMissingVectors: false,
failOnFailedTestCases: false,
releaseMode: 'sdk'
releaseMode: 'sdk',
packageName: ''
}

const mockOctokit = {
Expand Down
88 changes: 86 additions & 2 deletions .github/actions/specs-report/__tests__/summary-report.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,93 @@ import { TestVector, TestVectorReport } from '../src/test-vectors'
import { generateSummary } from '../src/summary-report'

describe('summary-report', () => {
it('should display the error message in the markdown table properly', () => {
beforeEach(() => {
jest.clearAllMocks()
jest.spyOn(core.summary, 'write').mockImplementation()
})

it('should generate summary with package name', () => {
const mockReport: TestVectorReport = {
totalJunitFiles: 1,
totalTestVectors: 10,
totalJunitTestCases: 20,
specTestCases: 15,
specFailedTestCases: 2,
specPassedTestCases: 12,
specSkippedTestCases: 1,
missingVectors: [],
failedVectors: [],
skippedVectors: [],
successVectors: []
}

const summary = generateSummary(mockReport, 'test-package')
expect(summary).toContain('TBD Spec Test Vectors Report (test-package)')
})

it('should generate summary without package name', () => {
const mockReport: TestVectorReport = {
totalJunitFiles: 1,
totalTestVectors: 5,
totalJunitTestCases: 10,
specTestCases: 8,
specFailedTestCases: 1,
specPassedTestCases: 6,
specSkippedTestCases: 1,
missingVectors: [],
failedVectors: [],
skippedVectors: [],
successVectors: []
}

const summary = generateSummary(mockReport, '')
expect(summary).toContain('TBD Spec Test Vectors Report')
})

it('should add success message when all vectors pass', () => {
const mockReport: TestVectorReport = {
totalJunitFiles: 1,
totalTestVectors: 2,
totalJunitTestCases: 10,
specTestCases: 2,
specFailedTestCases: 0,
specPassedTestCases: 2,
specSkippedTestCases: 0,
missingVectors: [],
failedVectors: [],
skippedVectors: [],
successVectors: [
{ feature: 'Test', name: 'Vector', file: 'test.json', testCases: [] },
{ feature: 'Test', name: 'Vector2', file: 'test2.json', testCases: [] }
]
}

const summary = generateSummary(mockReport, '')
expect(summary).toContain('✅ All test vectors passed')
})

it('should add info message when not all vectors pass', () => {
const mockReport: TestVectorReport = {
totalJunitFiles: 1,
totalTestVectors: 5,
totalJunitTestCases: 10,
specTestCases: 10,
specFailedTestCases: 1,
specPassedTestCases: 9,
specSkippedTestCases: 0,
missingVectors: [],
failedVectors: [
{ feature: 'Test', name: 'Vector', file: 'test.json', testCases: [] }
],
skippedVectors: [],
successVectors: []
}

const summary = generateSummary(mockReport, '')
expect(summary).toContain('ℹ️ 0 out of 5 test vectors passed successfully.')
})

it('should display the error message in the markdown table properly', () => {
const tbdexKtErrorSample: TestVector = {
feature: 'Protocol',
name: 'parse_rfq',
Expand Down Expand Up @@ -45,7 +129,7 @@ describe('summary-report', () => {
successVectors: []
}

const summary = generateSummary(report)
const summary = generateSummary(report, '')

expect(summary).toContain('Failed to resolve kid.')
})
Expand Down
3 changes: 3 additions & 0 deletions .github/actions/specs-report/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ inputs:
comment-on-pr:
description: 'Whether to comment the summary report on the PR'
required: false
comment-package:
description: 'The package name to add to the summary header comment'
required: false
git-token:
description:
'The git token to add the comment to the PR (required for PR comments)'
Expand Down
2 changes: 1 addition & 1 deletion .github/actions/specs-report/badges/coverage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 9 additions & 4 deletions .github/actions/specs-report/dist/index.js

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

2 changes: 1 addition & 1 deletion .github/actions/specs-report/dist/index.js.map

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions .github/actions/specs-report/src/action-inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export interface ActionInputs {
gitToken: string
/** Whether to add the report as a comment to the PR */
commentOnPr: boolean
/** The package name to be displayed on the Summary Header (useful for monorepos) */
packageName: string
/** Whether to fail the job if missing test vectors are found */
failOnMissingVectors: boolean
/** Whether to fail the job if failed test cases are found */
Expand Down Expand Up @@ -66,6 +68,7 @@ export const readActionInputs = (): ActionInputs => {
}

const commentOnPr = core.getInput('comment-on-pr') === 'true'
const packageName = core.getInput('package-name') || ''
const gitToken = core.getInput('git-token', {
required: commentOnPr || isReleaseMode
})
Expand Down Expand Up @@ -97,6 +100,7 @@ export const readActionInputs = (): ActionInputs => {
suiteRegexStrFilters,
gitToken,
commentOnPr,
packageName,
failOnMissingVectors,
failOnFailedTestCases,
releaseMode,
Expand Down
3 changes: 2 additions & 1 deletion .github/actions/specs-report/src/ci.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const handleCIReport = async (inputs: ActionInputs): Promise<void> => {
suiteRegexStrFilters,
gitToken,
commentOnPr,
packageName,
failOnMissingVectors,
failOnFailedTestCases
} = inputs
Expand All @@ -24,7 +25,7 @@ export const handleCIReport = async (inputs: ActionInputs): Promise<void> => {
suiteRegexStrFilters
)

const summary = generateSummary(report)
const summary = generateSummary(report, packageName)

if (commentOnPr) {
await addCommentToPr(summary, gitToken)
Expand Down
11 changes: 9 additions & 2 deletions .github/actions/specs-report/src/summary-report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,18 @@ const SUMMARY_HEADER = 'TBD Spec Test Vectors Report'
/**
* Generates the summary markdown report for the test vector results.
*/
export const generateSummary = (testVectorReport: TestVectorReport): string => {
export const generateSummary = (
testVectorReport: TestVectorReport,
packageName: string
): string => {
core.info(
`Generating summary... ${JSON.stringify(testVectorReport, null, 2)}`
)
core.summary.addHeading(SUMMARY_HEADER, 2)

const header = packageName
? `${SUMMARY_HEADER} (${packageName})`
: SUMMARY_HEADER
core.summary.addHeading(header, 2)

addOverallStatsTable(testVectorReport)

Expand Down

0 comments on commit 9f2ebf8

Please sign in to comment.