Skip to content
Merged
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
17 changes: 14 additions & 3 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,13 @@ describe('handleLargeSummary', () => {
expect(result).toContain('actions/runs/12345')
})

test('returns original summary and logs a warning when artifact handling fails', async () => {
test('returns truncated summary and replaces buffer when artifact upload fails', async () => {
const warningMock = core.warning as jest.Mock
const emptyBufferMock = core.summary.emptyBuffer as jest.Mock
const addRawMock = core.summary.addRaw as jest.Mock
warningMock.mockClear()
emptyBufferMock.mockClear()
addRawMock.mockClear()
const largeSummary = 'b'.repeat(1024 * 1024 + 1)

DefaultArtifactClientMock.mockImplementation(() => ({
Expand All @@ -145,9 +149,16 @@ describe('handleLargeSummary', () => {

const result = await handleLargeSummary(largeSummary)

expect(result).toBe(largeSummary)
// Should NOT return the original oversized content
expect(result).not.toBe(largeSummary)
// Should return a truncated summary
expect(result).toContain('Dependency Review Summary')
expect(result).toContain('too large to display')
// Should replace the core.summary buffer to prevent write() from failing
expect(emptyBufferMock).toHaveBeenCalled()
expect(addRawMock).toHaveBeenCalledWith(result)
expect(warningMock).toHaveBeenCalledWith(
expect.stringContaining('Failed to handle large summary')
expect.stringContaining('Failed to upload large summary as artifact')
)
})
})
26 changes: 20 additions & 6 deletions dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

28 changes: 23 additions & 5 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ export async function handleLargeSummary(
return summaryContent
}

const summarySize = Math.round(
Buffer.byteLength(summaryContent, 'utf8') / 1024
)
const truncatedSummary = `# Dependency Review Summary

The full dependency review summary was too large to display here (${summarySize}KB, limit is 1024KB).`

const artifactClient = new DefaultArtifactClient()
const artifactName = 'dependency-review-summary'
const files = ['summary.md']
Expand All @@ -87,9 +94,9 @@ export async function handleLargeSummary(
})

// Return a shorter summary with a link to the artifact
const shortSummary = `# Dependency Review Summary
const shortSummary = `${truncatedSummary}

The full dependency review summary is too large to display here. Please download the artifact named "${artifactName}" to view the complete report.
Please download the artifact named "${artifactName}" to view the complete report.

[View full job summary](${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID})`

Expand All @@ -99,9 +106,14 @@ The full dependency review summary is too large to display here. Please download
return shortSummary
} catch (error) {
core.warning(
`Failed to handle large summary: ${error instanceof Error ? error.message : 'Unknown error'}`
`Failed to upload large summary as artifact: ${error instanceof Error ? error.message : 'Unknown error'}`
)
return summaryContent
// Even though artifact upload failed, we must still replace the buffer
// with a truncated summary to prevent core.summary.write() from failing
// with the oversized content (see issue #867)
core.summary.emptyBuffer()
core.summary.addRaw(truncatedSummary)
return truncatedSummary
}
}

Expand Down Expand Up @@ -268,7 +280,13 @@ async function run(): Promise<void> {
}
}
} finally {
await core.summary.write()
try {
await core.summary.write()
} catch (error) {
core.warning(
`Failed to write job summary: ${error instanceof Error ? error.message : 'Unknown error'}`
)
}
}
}

Expand Down