diff --git a/packages/core/__tests__/markdown-summary.test.ts b/packages/core/__tests__/markdown-summary.test.ts index 00f4ad6c..08f19c91 100644 --- a/packages/core/__tests__/markdown-summary.test.ts +++ b/packages/core/__tests__/markdown-summary.test.ts @@ -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) }) diff --git a/packages/core/src/markdown-summary.ts b/packages/core/src/markdown-summary.ts index b2880e90..5835a37c 100644 --- a/packages/core/src/markdown-summary.ts +++ b/packages/core/src/markdown-summary.ts @@ -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 @@ -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} markdown summary instance */ - async write(overwrite = false): Promise { + async write(options?: SummaryWriteOptions): Promise { + const overwrite = !!options?.overwrite const filePath = await this.filePath() if (await this.willExceedLimit(overwrite)) { @@ -160,7 +169,7 @@ class MarkdownSummary { * @returns {MarkdownSummary} markdown summary instance */ async clear(): Promise { - return this.emptyBuffer().write(true) + return this.emptyBuffer().write({overwrite: true}) } /**