1
0
Fork 0

summary: remove limit validation in client

pull/1014/head
Rob Herley 2022-04-20 20:10:56 +00:00 committed by GitHub
parent ed87cc6ce3
commit eef3e92175
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 48 deletions

View File

@ -1,11 +1,7 @@
import * as fs from 'fs'
import * as os from 'os'
import path from 'path'
import {
markdownSummary,
SUMMARY_ENV_VAR,
SUMMARY_LIMIT_BYTES
} from '../src/markdown-summary'
import {markdownSummary, SUMMARY_ENV_VAR} from '../src/markdown-summary'
const testFilePath = path.join(__dirname, 'test', 'test-summary.md')
@ -96,13 +92,6 @@ describe('@actions/core/src/markdown-summary', () => {
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 () => {
await fs.promises.writeFile(testFilePath, '# ', {encoding: 'utf8'})
await markdownSummary.addRaw(fixtures.text).write()

View File

@ -1,9 +1,7 @@
import {EOL} from 'os'
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_DOCS_URL =
'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
}
/**
* 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
*
@ -140,24 +116,14 @@ 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 {SummaryWriteOptions | undefined} options (optional) options for write operation
* @param {SummaryWriteOptions} [options] (optional) options for write operation
*
* @returns {Promise<MarkdownSummary>} markdown summary instance
*/
async write(options?: SummaryWriteOptions): Promise<MarkdownSummary> {
const overwrite = !!options?.overwrite
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
await writeFunc(filePath, this._buffer, {encoding: 'utf8'})
return this.emptyBuffer()