mirror of https://github.com/actions/toolkit
summary: remove limit validation in client
parent
ed87cc6ce3
commit
eef3e92175
|
@ -1,11 +1,7 @@
|
||||||
import * as fs from 'fs'
|
import * as fs from 'fs'
|
||||||
import * as os from 'os'
|
import * as os from 'os'
|
||||||
import path from 'path'
|
import path from 'path'
|
||||||
import {
|
import {markdownSummary, SUMMARY_ENV_VAR} from '../src/markdown-summary'
|
||||||
markdownSummary,
|
|
||||||
SUMMARY_ENV_VAR,
|
|
||||||
SUMMARY_LIMIT_BYTES
|
|
||||||
} from '../src/markdown-summary'
|
|
||||||
|
|
||||||
const testFilePath = path.join(__dirname, 'test', 'test-summary.md')
|
const testFilePath = path.join(__dirname, 'test', 'test-summary.md')
|
||||||
|
|
||||||
|
@ -96,13 +92,6 @@ describe('@actions/core/src/markdown-summary', () => {
|
||||||
await expect(write).rejects.toThrow()
|
await expect(write).rejects.toThrow()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('throws if write will exceed file limit', async () => {
|
|
||||||
const aaa = 'a'.repeat(SUMMARY_LIMIT_BYTES + 1)
|
|
||||||
const write = markdownSummary.addRaw(aaa).write()
|
|
||||||
|
|
||||||
await expect(write).rejects.toThrow()
|
|
||||||
})
|
|
||||||
|
|
||||||
it('appends text to summary file', async () => {
|
it('appends text to summary file', async () => {
|
||||||
await fs.promises.writeFile(testFilePath, '# ', {encoding: 'utf8'})
|
await fs.promises.writeFile(testFilePath, '# ', {encoding: 'utf8'})
|
||||||
await markdownSummary.addRaw(fixtures.text).write()
|
await markdownSummary.addRaw(fixtures.text).write()
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
import {EOL} from 'os'
|
import {EOL} from 'os'
|
||||||
import {constants, promises} from 'fs'
|
import {constants, promises} from 'fs'
|
||||||
const {access, appendFile, stat, writeFile} = promises
|
const {access, appendFile, writeFile} = promises
|
||||||
|
|
||||||
// The runner & server will also block any upload greater than this size
|
|
||||||
export const SUMMARY_LIMIT_BYTES = 1024 * 1024 // 1MiB
|
|
||||||
export const SUMMARY_ENV_VAR = 'GITHUB_STEP_SUMMARY'
|
export const SUMMARY_ENV_VAR = 'GITHUB_STEP_SUMMARY'
|
||||||
export const SUMMARY_DOCS_URL =
|
export const SUMMARY_DOCS_URL =
|
||||||
'https://docs.github.com/actions/using-workflows/workflow-commands-for-github-actions#adding-a-markdown-summary'
|
'https://docs.github.com/actions/using-workflows/workflow-commands-for-github-actions#adding-a-markdown-summary'
|
||||||
|
@ -91,28 +89,6 @@ class MarkdownSummary {
|
||||||
return this._filePath
|
return this._filePath
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if the write of the current buffer will exceed the job summary upload limit
|
|
||||||
*
|
|
||||||
* @param {boolean} overwrite if the operation is overwrite (otherwise it's append)
|
|
||||||
*
|
|
||||||
* @returns {Promise<boolean>} whether or not the file will exceed the limit
|
|
||||||
*/
|
|
||||||
private async willExceedLimit(overwrite: boolean): Promise<boolean> {
|
|
||||||
let expectedSize = 0
|
|
||||||
if (!overwrite) {
|
|
||||||
// if appending, we need to check the current size of the summary file
|
|
||||||
const filePath = await this.filePath()
|
|
||||||
const {size} = await stat(filePath)
|
|
||||||
expectedSize += size
|
|
||||||
}
|
|
||||||
|
|
||||||
const bufferLen = Buffer.byteLength(this._buffer, 'utf8')
|
|
||||||
expectedSize += bufferLen
|
|
||||||
|
|
||||||
return expectedSize > SUMMARY_LIMIT_BYTES
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wraps content in an HTML tag, adding any HTML attributes
|
* Wraps content in an HTML tag, adding any HTML attributes
|
||||||
*
|
*
|
||||||
|
@ -140,24 +116,14 @@ 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
|
|
||||||
*
|
*
|
||||||
* @param {SummaryWriteOptions | undefined} options (optional) options for write operation
|
* @param {SummaryWriteOptions} [options] (optional) options for write operation
|
||||||
*
|
*
|
||||||
* @returns {Promise<MarkdownSummary>} markdown summary instance
|
* @returns {Promise<MarkdownSummary>} markdown summary instance
|
||||||
*/
|
*/
|
||||||
async write(options?: SummaryWriteOptions): Promise<MarkdownSummary> {
|
async write(options?: SummaryWriteOptions): Promise<MarkdownSummary> {
|
||||||
const overwrite = !!options?.overwrite
|
const overwrite = !!options?.overwrite
|
||||||
const filePath = await this.filePath()
|
const filePath = await this.filePath()
|
||||||
|
|
||||||
if (await this.willExceedLimit(overwrite)) {
|
|
||||||
this.emptyBuffer()
|
|
||||||
const limitK = SUMMARY_LIMIT_BYTES / 1024
|
|
||||||
throw new Error(
|
|
||||||
`Aborting write to summary file. File size would exceed limit of ${limitK}KiB. For more information see: ${SUMMARY_DOCS_URL}`
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
const writeFunc = overwrite ? writeFile : appendFile
|
const writeFunc = overwrite ? writeFile : appendFile
|
||||||
await writeFunc(filePath, this._buffer, {encoding: 'utf8'})
|
await writeFunc(filePath, this._buffer, {encoding: 'utf8'})
|
||||||
return this.emptyBuffer()
|
return this.emptyBuffer()
|
||||||
|
|
Loading…
Reference in New Issue