From eef3e92175f5af99e5cbc5c09691a98ff2574e5c Mon Sep 17 00:00:00 2001 From: Rob Herley Date: Wed, 20 Apr 2022 20:10:56 +0000 Subject: [PATCH] summary: remove limit validation in client --- .../core/__tests__/markdown-summary.test.ts | 13 +------ packages/core/src/markdown-summary.ts | 38 +------------------ 2 files changed, 3 insertions(+), 48 deletions(-) diff --git a/packages/core/__tests__/markdown-summary.test.ts b/packages/core/__tests__/markdown-summary.test.ts index 08f19c91..d9b8ee5c 100644 --- a/packages/core/__tests__/markdown-summary.test.ts +++ b/packages/core/__tests__/markdown-summary.test.ts @@ -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() diff --git a/packages/core/src/markdown-summary.ts b/packages/core/src/markdown-summary.ts index eebc8812..97d2d3ca 100644 --- a/packages/core/src/markdown-summary.ts +++ b/packages/core/src/markdown-summary.ts @@ -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} whether or not the file will exceed the limit - */ - private async willExceedLimit(overwrite: boolean): Promise { - 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} markdown summary instance */ async write(options?: SummaryWriteOptions): Promise { 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()