mirror of https://github.com/actions/toolkit
feedback: add summary write options
parent
6295f5d25b
commit
edee7cde32
|
@ -111,7 +111,7 @@ describe('@actions/core/src/markdown-summary', () => {
|
||||||
|
|
||||||
it('overwrites text to summary file', async () => {
|
it('overwrites text to summary file', async () => {
|
||||||
await fs.promises.writeFile(testFilePath, 'overwrite', {encoding: 'utf8'})
|
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)
|
await assertSummary(fixtures.text)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -45,6 +45,14 @@ export interface SummaryImageOptions {
|
||||||
height?: string
|
height?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface SummaryWriteOptions {
|
||||||
|
/**
|
||||||
|
* Replace all existing content in summary file with buffer contents
|
||||||
|
* (optional) default: false
|
||||||
|
*/
|
||||||
|
overwrite?: boolean
|
||||||
|
}
|
||||||
|
|
||||||
class MarkdownSummary {
|
class MarkdownSummary {
|
||||||
private _buffer: string
|
private _buffer: string
|
||||||
private _filePath?: 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.
|
* 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
|
* 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
|
* @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()
|
const filePath = await this.filePath()
|
||||||
|
|
||||||
if (await this.willExceedLimit(overwrite)) {
|
if (await this.willExceedLimit(overwrite)) {
|
||||||
|
@ -160,7 +169,7 @@ class MarkdownSummary {
|
||||||
* @returns {MarkdownSummary} markdown summary instance
|
* @returns {MarkdownSummary} markdown summary instance
|
||||||
*/
|
*/
|
||||||
async clear(): Promise<MarkdownSummary> {
|
async clear(): Promise<MarkdownSummary> {
|
||||||
return this.emptyBuffer().write(true)
|
return this.emptyBuffer().write({overwrite: true})
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue