Skip to content

Commit

Permalink
feedback: add summary write options
Browse files Browse the repository at this point in the history
  • Loading branch information
robherley committed Mar 8, 2022
1 parent 6295f5d commit edee7cd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/core/__tests__/markdown-summary.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ describe('@actions/core/src/markdown-summary', () => {

it('overwrites text to summary file', async () => {
await fs.promises.writeFile(testFilePath, 'overwrite', {encoding: 'utf8'})
await markdownSummary.addRaw(fixtures.text).write(true)
await markdownSummary.addRaw(fixtures.text).write({overwrite: true})
await assertSummary(fixtures.text)
})

Expand Down
15 changes: 12 additions & 3 deletions packages/core/src/markdown-summary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ export interface SummaryImageOptions {
height?: string
}

export interface SummaryWriteOptions {
/**
* Replace all existing content in summary file with buffer contents
* (optional) default: false
*/
overwrite?: boolean
}

class MarkdownSummary {
private _buffer: string
private _filePath?: string
Expand Down Expand Up @@ -134,11 +142,12 @@ class MarkdownSummary {
* Writes text in the buffer to the summary buffer file and empties buffer. Will append by default.
* Checks if resulting file size > SUMMARY_LIMIT_BYTES, will throw and empty buffer
*
* @param {boolean} [overwrite=false] (optional) replace existing content in summary file with buffer contents, default: false
* @param {SummaryWriteOptions | undefined} options (optional) options for write operation
*
* @returns {Promise<MarkdownSummary>} markdown summary instance
*/
async write(overwrite = false): Promise<MarkdownSummary> {
async write(options?: SummaryWriteOptions): Promise<MarkdownSummary> {
const overwrite = !!options?.overwrite
const filePath = await this.filePath()

if (await this.willExceedLimit(overwrite)) {
Expand All @@ -160,7 +169,7 @@ class MarkdownSummary {
* @returns {MarkdownSummary} markdown summary instance
*/
async clear(): Promise<MarkdownSummary> {
return this.emptyBuffer().write(true)
return this.emptyBuffer().write({overwrite: true})
}

/**
Expand Down

0 comments on commit edee7cd

Please sign in to comment.