From 36aa3c3495485cb63639116471daf84b9ddba7de Mon Sep 17 00:00:00 2001 From: Francesco Novy Date: Fri, 30 Aug 2024 10:14:29 +0200 Subject: [PATCH 01/25] ci: Show what size limit jobs exceeded the limit --- dev-packages/size-limit-gh-action/index.mjs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/dev-packages/size-limit-gh-action/index.mjs b/dev-packages/size-limit-gh-action/index.mjs index 3dbb8aa22127..9dd88144216e 100644 --- a/dev-packages/size-limit-gh-action/index.mjs +++ b/dev-packages/size-limit-gh-action/index.mjs @@ -27,8 +27,12 @@ async function fetchPreviousComment(octokit, repo, pr) { } class SizeLimit { - formatBytes(size) { - return bytes.format(size, { unitSeparator: ' ' }); + formatBytes(size, sizeLimit, passed) { + if (passed) { + return bytes.format(size, { unitSeparator: ' ' }); + } + + return `⛔️ ${bytes.format(size, { unitSeparator: ' ' })} (max: ${bytes.format(sizeLimit, { unitSeparator: ' ' })})`; } formatPercentageChange(base = 0, current = 0) { @@ -84,7 +88,7 @@ class SizeLimit { formatSizeResult(name, base, current) { return [ name, - this.formatBytes(current.size), + this.formatBytes(current.size, current.sizeLimit, current.passed), this.formatPercentageChange(base.size, current.size), this.formatChange(base.size, current.size), ]; @@ -100,6 +104,8 @@ class SizeLimit { [result.name]: { name: result.name, size: +result.size, + sizeLimit: +result.sizeLimit, + passed: result.passed || false, }, }; }, {}); From 0aade5e3f51c5a6383283f0d97545e92a8dd0a8a Mon Sep 17 00:00:00 2001 From: Francesco Novy Date: Fri, 30 Aug 2024 10:15:18 +0200 Subject: [PATCH 02/25] WIP debug try failed size limit --- .size-limit.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.size-limit.js b/.size-limit.js index d2211d91d5b0..7f97f6d3536f 100644 --- a/.size-limit.js +++ b/.size-limit.js @@ -8,7 +8,7 @@ module.exports = [ path: 'packages/browser/build/npm/esm/index.js', import: createImport('init'), gzip: true, - limit: '24 KB', + limit: '20 KB', }, { name: '@sentry/browser (incl. Tracing)', From 9370f06bfd8a431aa4898ace751ab547e56b77d5 Mon Sep 17 00:00:00 2001 From: Francesco Novy Date: Fri, 30 Aug 2024 10:28:33 +0200 Subject: [PATCH 03/25] fix it --- dev-packages/size-limit-gh-action/index.mjs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/dev-packages/size-limit-gh-action/index.mjs b/dev-packages/size-limit-gh-action/index.mjs index 9dd88144216e..db878b42fbfe 100644 --- a/dev-packages/size-limit-gh-action/index.mjs +++ b/dev-packages/size-limit-gh-action/index.mjs @@ -27,12 +27,16 @@ async function fetchPreviousComment(octokit, repo, pr) { } class SizeLimit { - formatBytes(size, sizeLimit, passed) { + formatBytes(size) { + return bytes.format(size, { unitSeparator: ' ' }); + } + + formatSizeLimitResult(size, sizeLimit, passed) { if (passed) { - return bytes.format(size, { unitSeparator: ' ' }); + return this.formatBytes(size); } - return `⛔️ ${bytes.format(size, { unitSeparator: ' ' })} (max: ${bytes.format(sizeLimit, { unitSeparator: ' ' })})`; + return `⛔️ ${this.formatBytes(size)} (max: ${this.formatBytes(sizeLimit)})`; } formatPercentageChange(base = 0, current = 0) { @@ -88,7 +92,7 @@ class SizeLimit { formatSizeResult(name, base, current) { return [ name, - this.formatBytes(current.size, current.sizeLimit, current.passed), + this.formatSizeLimitResult(current.size, current.sizeLimit, current.passed), this.formatPercentageChange(base.size, current.size), this.formatChange(base.size, current.size), ]; From d2a4835e7627d23bd567dcbf7d638567f51cacf3 Mon Sep 17 00:00:00 2001 From: Francesco Novy Date: Fri, 30 Aug 2024 10:35:01 +0200 Subject: [PATCH 04/25] log errors? --- dev-packages/size-limit-gh-action/index.mjs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/dev-packages/size-limit-gh-action/index.mjs b/dev-packages/size-limit-gh-action/index.mjs index db878b42fbfe..f87d6a46527c 100644 --- a/dev-packages/size-limit-gh-action/index.mjs +++ b/dev-packages/size-limit-gh-action/index.mjs @@ -279,8 +279,12 @@ async function run() { '⚠️ **Warning:** Base artifact is not the latest one, because the latest workflow run is not done yet. This may lead to incorrect results. Try to re-run all tests to get up to date results.', ); } - - bodyParts.push(markdownTable(limit.formatResults(base, current))); + try { + bodyParts.push(markdownTable(limit.formatResults(base, current))); + } catch (error) { + core.error('Error generating markdown table'); + core.error(error); + } if (baseWorkflowRun) { bodyParts.push(''); From dda8e0328e129d054b15623d36083587a8ecf2be Mon Sep 17 00:00:00 2001 From: Francesco Novy Date: Fri, 30 Aug 2024 10:54:17 +0200 Subject: [PATCH 05/25] improve action code & add some more logging --- dev-packages/size-limit-gh-action/index.mjs | 188 +++--------------- .../utils/size-limit-formatter.mjs | 126 ++++++++++++ 2 files changed, 158 insertions(+), 156 deletions(-) create mode 100644 dev-packages/size-limit-gh-action/utils/size-limit-formatter.mjs diff --git a/dev-packages/size-limit-gh-action/index.mjs b/dev-packages/size-limit-gh-action/index.mjs index f87d6a46527c..ed6669f70299 100644 --- a/dev-packages/size-limit-gh-action/index.mjs +++ b/dev-packages/size-limit-gh-action/index.mjs @@ -1,4 +1,3 @@ -/* eslint-disable max-lines */ import { promises as fs } from 'node:fs'; import path from 'node:path'; import { fileURLToPath } from 'node:url'; @@ -9,13 +8,18 @@ import { exec } from '@actions/exec'; import { context, getOctokit } from '@actions/github'; import * as glob from '@actions/glob'; import * as io from '@actions/io'; -import bytes from 'bytes'; import { markdownTable } from 'markdown-table'; +import { SizeLimit } from './utils/size-limit-formatter.mjs'; + const SIZE_LIMIT_HEADING = '## size-limit report 📦 '; const ARTIFACT_NAME = 'size-limit-action'; const RESULTS_FILE = 'size-limit-results.json'; +const RESULTS_FILE_PATH = path.resolve(__dirname, RESULTS_FILE); + +const { getInput, setFailed } = core; + async function fetchPreviousComment(octokit, repo, pr) { const { data: commentList } = await octokit.rest.issues.listComments({ ...repo, @@ -26,124 +30,6 @@ async function fetchPreviousComment(octokit, repo, pr) { return !sizeLimitComment ? null : sizeLimitComment; } -class SizeLimit { - formatBytes(size) { - return bytes.format(size, { unitSeparator: ' ' }); - } - - formatSizeLimitResult(size, sizeLimit, passed) { - if (passed) { - return this.formatBytes(size); - } - - return `⛔️ ${this.formatBytes(size)} (max: ${this.formatBytes(sizeLimit)})`; - } - - formatPercentageChange(base = 0, current = 0) { - if (base === 0) { - return 'added'; - } - - if (current === 0) { - return 'removed'; - } - - const value = ((current - base) / base) * 100; - const formatted = (Math.sign(value) * Math.ceil(Math.abs(value) * 100)) / 100; - - if (value > 0) { - return `+${formatted}%`; - } - - if (value === 0) { - return '-'; - } - - return `${formatted}%`; - } - - formatChange(base = 0, current = 0) { - if (base === 0) { - return 'added'; - } - - if (current === 0) { - return 'removed'; - } - - const value = current - base; - const formatted = this.formatBytes(value); - - if (value > 0) { - return `+${formatted} 🔺`; - } - - if (value === 0) { - return '-'; - } - - return `${formatted} 🔽`; - } - - formatLine(value, change) { - return `${value} (${change})`; - } - - formatSizeResult(name, base, current) { - return [ - name, - this.formatSizeLimitResult(current.size, current.sizeLimit, current.passed), - this.formatPercentageChange(base.size, current.size), - this.formatChange(base.size, current.size), - ]; - } - - parseResults(output) { - const results = JSON.parse(output); - - return results.reduce((current, result) => { - return { - // biome-ignore lint/performance/noAccumulatingSpread: - ...current, - [result.name]: { - name: result.name, - size: +result.size, - sizeLimit: +result.sizeLimit, - passed: result.passed || false, - }, - }; - }, {}); - } - - hasSizeChanges(base, current, threshold = 0) { - const names = [...new Set([...(base ? Object.keys(base) : []), ...Object.keys(current)])]; - - return !!names.find(name => { - const baseResult = base?.[name] || EmptyResult; - const currentResult = current[name] || EmptyResult; - - if (baseResult.size === 0 && currentResult.size === 0) { - return true; - } - - return Math.abs((currentResult.size - baseResult.size) / baseResult.size) * 100 > threshold; - }); - } - - formatResults(base, current) { - const names = [...new Set([...(base ? Object.keys(base) : []), ...Object.keys(current)])]; - const header = SIZE_RESULTS_HEADER; - const fields = names.map(name => { - const baseResult = base?.[name] || EmptyResult; - const currentResult = current[name] || EmptyResult; - - return this.formatSizeResult(name, baseResult, currentResult); - }); - - return [header, ...fields]; - } -} - async function execSizeLimit() { let output = ''; @@ -161,16 +47,7 @@ async function execSizeLimit() { return { status, output }; } -const SIZE_RESULTS_HEADER = ['Path', 'Size', '% Change', 'Change']; - -const EmptyResult = { - name: '-', - size: 0, -}; - async function run() { - const { getInput, setFailed } = core; - try { const { payload, repo } = context; const pr = payload.pull_request; @@ -185,35 +62,11 @@ async function run() { const octokit = getOctokit(githubToken); const limit = new SizeLimit(); - const artifactClient = artifact.create(); const __dirname = path.dirname(fileURLToPath(import.meta.url)); - const resultsFilePath = path.resolve(__dirname, RESULTS_FILE); // If we have no comparison branch, we just run size limit & store the result as artifact if (!comparisonBranch) { - let base; - const { output: baseOutput } = await execSizeLimit(); - - try { - base = limit.parseResults(baseOutput); - } catch (error) { - core.error('Error parsing size-limit output. The output should be a json.'); - throw error; - } - - try { - await fs.writeFile(resultsFilePath, JSON.stringify(base), 'utf8'); - } catch (err) { - core.error(err); - } - const globber = await glob.create(resultsFilePath, { - followSymbolicLinks: false, - }); - const files = await globber.glob(); - - await artifactClient.uploadArtifact(ARTIFACT_NAME, files, __dirname); - - return; + return runSizeLimitOnComparisonBranch(); } // Else, we run size limit for the current branch, AND fetch it for the comparison branch @@ -243,7 +96,7 @@ async function run() { downloadPath: __dirname, }); - base = JSON.parse(await fs.readFile(resultsFilePath, { encoding: 'utf8' })); + base = JSON.parse(await fs.readFile(RESULTS_FILE_PATH, { encoding: 'utf8' })); if (!artifacts.isLatest) { baseIsNotLatest = true; @@ -265,7 +118,6 @@ async function run() { const thresholdNumber = Number(threshold); - // @ts-ignore const sizeLimitComment = await fetchPreviousComment(octokit, repo, pr); const shouldComment = @@ -293,6 +145,8 @@ async function run() { const body = bodyParts.join('\r\n'); + core.debug(`Posting PR comment: \n\n${body}`); + try { if (!sizeLimitComment) { await octokit.rest.issues.createComment({ @@ -323,6 +177,28 @@ async function run() { } } +async function runSizeLimitOnComparisonBranch() { + const limit = new SizeLimit(); + const artifactClient = artifact.create(); + + const { output: baseOutput } = await execSizeLimit(); + + try { + const base = limit.parseResults(baseOutput); + await fs.writeFile(RESULTS_FILE_PATH, JSON.stringify(base), 'utf8'); + } catch (error) { + core.error('Error parsing size-limit output. The output should be a json.'); + throw error; + } + + const globber = await glob.create(RESULTS_FILE_PATH, { + followSymbolicLinks: false, + }); + const files = await globber.glob(); + + await artifactClient.uploadArtifact(ARTIFACT_NAME, files, __dirname); +} + // max pages of workflows to pagination through const DEFAULT_MAX_PAGES = 50; // max results per page diff --git a/dev-packages/size-limit-gh-action/utils/size-limit-formatter.mjs b/dev-packages/size-limit-gh-action/utils/size-limit-formatter.mjs new file mode 100644 index 000000000000..e2687910a0f3 --- /dev/null +++ b/dev-packages/size-limit-gh-action/utils/size-limit-formatter.mjs @@ -0,0 +1,126 @@ +import bytes from 'bytes'; + +const SIZE_RESULTS_HEADER = ['Path', 'Size', '% Change', 'Change']; + +const EmptyResult = { + name: '-', + size: 0, +}; + +export class SizeLimit { + formatBytes(size) { + return bytes.format(size, { unitSeparator: ' ' }); + } + + formatSizeLimitResult(size, sizeLimit, passed) { + if (passed) { + return this.formatBytes(size); + } + + return `⛔️ ${this.formatBytes(size)} (max: ${this.formatBytes(sizeLimit)})`; + } + + formatPercentageChange(base = 0, current = 0) { + if (base === 0) { + return 'added'; + } + + if (current === 0) { + return 'removed'; + } + + const value = ((current - base) / base) * 100; + const formatted = (Math.sign(value) * Math.ceil(Math.abs(value) * 100)) / 100; + + if (value > 0) { + return `+${formatted}%`; + } + + if (value === 0) { + return '-'; + } + + return `${formatted}%`; + } + + formatChange(base = 0, current = 0) { + if (base === 0) { + return 'added'; + } + + if (current === 0) { + return 'removed'; + } + + const value = current - base; + const formatted = this.formatBytes(value); + + if (value > 0) { + return `+${formatted} 🔺`; + } + + if (value === 0) { + return '-'; + } + + return `${formatted} 🔽`; + } + + formatLine(value, change) { + return `${value} (${change})`; + } + + formatSizeResult(name, base, current) { + return [ + name, + this.formatSizeLimitResult(current.size, current.sizeLimit, current.passed), + this.formatPercentageChange(base.size, current.size), + this.formatChange(base.size, current.size), + ]; + } + + parseResults(output) { + const results = JSON.parse(output); + + return results.reduce((current, result) => { + return { + // biome-ignore lint/performance/noAccumulatingSpread: + ...current, + [result.name]: { + name: result.name, + size: +result.size, + sizeLimit: +result.sizeLimit, + passed: result.passed || false, + }, + }; + }, {}); + } + + hasSizeChanges(base, current, threshold = 0) { + const names = [...new Set([...(base ? Object.keys(base) : []), ...Object.keys(current)])]; + + return !!names.find(name => { + const baseResult = base?.[name] || EmptyResult; + const currentResult = current[name] || EmptyResult; + + if (baseResult.size === 0 && currentResult.size === 0) { + return true; + } + + return Math.abs((currentResult.size - baseResult.size) / baseResult.size) * 100 > threshold; + }); + } + + formatResults(base, current) { + const names = [...new Set([...(base ? Object.keys(base) : []), ...Object.keys(current)])]; + const header = SIZE_RESULTS_HEADER; + const fields = names.map(name => { + const baseResult = base?.[name] || EmptyResult; + const currentResult = current[name] || EmptyResult; + + return this.formatSizeResult(name, baseResult, currentResult); + }); + + return [header, ...fields]; + } +} From d81cf454b0663b075a59c11dd45746ac03f57d60 Mon Sep 17 00:00:00 2001 From: Francesco Novy Date: Fri, 30 Aug 2024 11:14:41 +0200 Subject: [PATCH 06/25] fix module path --- dev-packages/size-limit-gh-action/index.mjs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/dev-packages/size-limit-gh-action/index.mjs b/dev-packages/size-limit-gh-action/index.mjs index ed6669f70299..555de30d19e9 100644 --- a/dev-packages/size-limit-gh-action/index.mjs +++ b/dev-packages/size-limit-gh-action/index.mjs @@ -16,8 +16,6 @@ const SIZE_LIMIT_HEADING = '## size-limit report 📦 '; const ARTIFACT_NAME = 'size-limit-action'; const RESULTS_FILE = 'size-limit-results.json'; -const RESULTS_FILE_PATH = path.resolve(__dirname, RESULTS_FILE); - const { getInput, setFailed } = core; async function fetchPreviousComment(octokit, repo, pr) { @@ -48,6 +46,8 @@ async function execSizeLimit() { } async function run() { + const resultsFilePath = path.resolve(__dirname, RESULTS_FILE); + try { const { payload, repo } = context; const pr = payload.pull_request; @@ -96,7 +96,7 @@ async function run() { downloadPath: __dirname, }); - base = JSON.parse(await fs.readFile(RESULTS_FILE_PATH, { encoding: 'utf8' })); + base = JSON.parse(await fs.readFile(resultsFilePath, { encoding: 'utf8' })); if (!artifacts.isLatest) { baseIsNotLatest = true; @@ -178,6 +178,8 @@ async function run() { } async function runSizeLimitOnComparisonBranch() { + const resultsFilePath = path.resolve(__dirname, RESULTS_FILE); + const limit = new SizeLimit(); const artifactClient = artifact.create(); @@ -185,13 +187,13 @@ async function runSizeLimitOnComparisonBranch() { try { const base = limit.parseResults(baseOutput); - await fs.writeFile(RESULTS_FILE_PATH, JSON.stringify(base), 'utf8'); + await fs.writeFile(resultsFilePath, JSON.stringify(base), 'utf8'); } catch (error) { core.error('Error parsing size-limit output. The output should be a json.'); throw error; } - const globber = await glob.create(RESULTS_FILE_PATH, { + const globber = await glob.create(resultsFilePath, { followSymbolicLinks: false, }); const files = await globber.glob(); From d3e3d0e10a128249fd93ef93d99342da9e6cdd46 Mon Sep 17 00:00:00 2001 From: Francesco Novy Date: Fri, 30 Aug 2024 11:22:57 +0200 Subject: [PATCH 07/25] fix dirname usage --- dev-packages/size-limit-gh-action/index.mjs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/dev-packages/size-limit-gh-action/index.mjs b/dev-packages/size-limit-gh-action/index.mjs index 555de30d19e9..9c493cfd7b26 100644 --- a/dev-packages/size-limit-gh-action/index.mjs +++ b/dev-packages/size-limit-gh-action/index.mjs @@ -16,6 +16,11 @@ const SIZE_LIMIT_HEADING = '## size-limit report 📦 '; const ARTIFACT_NAME = 'size-limit-action'; const RESULTS_FILE = 'size-limit-results.json'; +function getResultsFilePath() { + const __dirname = path.dirname(fileURLToPath(import.meta.url)); + return path.resolve(__dirname, RESULTS_FILE); +} + const { getInput, setFailed } = core; async function fetchPreviousComment(octokit, repo, pr) { @@ -46,7 +51,7 @@ async function execSizeLimit() { } async function run() { - const resultsFilePath = path.resolve(__dirname, RESULTS_FILE); + const __dirname = path.dirname(fileURLToPath(import.meta.url)); try { const { payload, repo } = context; @@ -62,7 +67,7 @@ async function run() { const octokit = getOctokit(githubToken); const limit = new SizeLimit(); - const __dirname = path.dirname(fileURLToPath(import.meta.url)); + const resultsFilePath = getResultsFilePath(); // If we have no comparison branch, we just run size limit & store the result as artifact if (!comparisonBranch) { @@ -178,7 +183,7 @@ async function run() { } async function runSizeLimitOnComparisonBranch() { - const resultsFilePath = path.resolve(__dirname, RESULTS_FILE); + const resultsFilePath = getResultsFilePath(); const limit = new SizeLimit(); const artifactClient = artifact.create(); From de2a3606b424d15f87cf9fb2f2c50d3eff49ed3c Mon Sep 17 00:00:00 2001 From: Francesco Novy Date: Fri, 30 Aug 2024 11:32:18 +0200 Subject: [PATCH 08/25] WIP debug --- dev-packages/size-limit-gh-action/index.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev-packages/size-limit-gh-action/index.mjs b/dev-packages/size-limit-gh-action/index.mjs index 9c493cfd7b26..9d37ddf7c7b4 100644 --- a/dev-packages/size-limit-gh-action/index.mjs +++ b/dev-packages/size-limit-gh-action/index.mjs @@ -312,7 +312,7 @@ async function getArtifactsForBranchAndWorkflow(octokit, { owner, repo, workflow } else { const foundArtifact = artifacts.find(({ name }) => name === artifactName); if (foundArtifact) { - core.info(`Found suitable artifact: ${foundArtifact.url}`); + core.info(`Found suitable artifact XXX: ${foundArtifact.url}`); return { artifact: foundArtifact, workflowRun, From 784e585bd53cc4e76a63aaa221dd67a651369ce9 Mon Sep 17 00:00:00 2001 From: Francesco Novy Date: Fri, 30 Aug 2024 11:39:16 +0200 Subject: [PATCH 09/25] streamline & extract --- .../size-limit-gh-action/.eslintrc.cjs | 2 +- dev-packages/size-limit-gh-action/index.mjs | 135 +----------------- ...t-formatter.mjs => SizeLimitFormatter.mjs} | 2 +- .../getArtifactsForBranchAndWorkflow.mjs | 134 +++++++++++++++++ 4 files changed, 138 insertions(+), 135 deletions(-) rename dev-packages/size-limit-gh-action/utils/{size-limit-formatter.mjs => SizeLimitFormatter.mjs} (98%) create mode 100644 dev-packages/size-limit-gh-action/utils/getArtifactsForBranchAndWorkflow.mjs diff --git a/dev-packages/size-limit-gh-action/.eslintrc.cjs b/dev-packages/size-limit-gh-action/.eslintrc.cjs index 8c67e0037908..4a92730d3b0b 100644 --- a/dev-packages/size-limit-gh-action/.eslintrc.cjs +++ b/dev-packages/size-limit-gh-action/.eslintrc.cjs @@ -7,7 +7,7 @@ module.exports = { overrides: [ { - files: ['*.mjs'], + files: ['**/*.mjs'], extends: ['@sentry-internal/sdk/src/base'], }, ], diff --git a/dev-packages/size-limit-gh-action/index.mjs b/dev-packages/size-limit-gh-action/index.mjs index 9d37ddf7c7b4..8b3322470064 100644 --- a/dev-packages/size-limit-gh-action/index.mjs +++ b/dev-packages/size-limit-gh-action/index.mjs @@ -10,7 +10,8 @@ import * as glob from '@actions/glob'; import * as io from '@actions/io'; import { markdownTable } from 'markdown-table'; -import { SizeLimit } from './utils/size-limit-formatter.mjs'; +import { SizeLimit } from './utils/SizeLimitFormatter.mjs'; +import { getArtifactsForBranchAndWorkflow } from './utils/getArtifactsForBranchAndWorkflow.mjs'; const SIZE_LIMIT_HEADING = '## size-limit report 📦 '; const ARTIFACT_NAME = 'size-limit-action'; @@ -206,138 +207,6 @@ async function runSizeLimitOnComparisonBranch() { await artifactClient.uploadArtifact(ARTIFACT_NAME, files, __dirname); } -// max pages of workflows to pagination through -const DEFAULT_MAX_PAGES = 50; -// max results per page -const DEFAULT_PAGE_LIMIT = 10; - -/** - * Fetch artifacts from a workflow run from a branch - * - * This is a bit hacky since GitHub Actions currently does not directly - * support downloading artifacts from other workflows - */ -/** - * Fetch artifacts from a workflow run from a branch - * - * This is a bit hacky since GitHub Actions currently does not directly - * support downloading artifacts from other workflows - */ -async function getArtifactsForBranchAndWorkflow(octokit, { owner, repo, workflowName, branch, artifactName }) { - core.startGroup(`getArtifactsForBranchAndWorkflow - workflow:"${workflowName}", branch:"${branch}"`); - - let repositoryWorkflow = null; - - // For debugging - const allWorkflows = []; - - // - // Find workflow id from `workflowName` - // - for await (const response of octokit.paginate.iterator(octokit.rest.actions.listRepoWorkflows, { - owner, - repo, - })) { - const targetWorkflow = response.data.find(({ name }) => name === workflowName); - - allWorkflows.push(...response.data.map(({ name }) => name)); - - // If not found in responses, continue to search on next page - if (!targetWorkflow) { - continue; - } - - repositoryWorkflow = targetWorkflow; - break; - } - - if (!repositoryWorkflow) { - core.info( - `Unable to find workflow with name "${workflowName}" in the repository. Found workflows: ${allWorkflows.join( - ', ', - )}`, - ); - core.endGroup(); - return null; - } - - const workflow_id = repositoryWorkflow.id; - - let currentPage = 0; - let latestWorkflowRun = null; - - for await (const response of octokit.paginate.iterator(octokit.rest.actions.listWorkflowRuns, { - owner, - repo, - workflow_id, - branch, - per_page: DEFAULT_PAGE_LIMIT, - event: 'push', - })) { - if (!response.data.length) { - core.warning(`Workflow ${workflow_id} not found in branch ${branch}`); - core.endGroup(); - return null; - } - - // Do not allow downloading artifacts from a fork. - const filtered = response.data.filter(workflowRun => workflowRun.head_repository.full_name === `${owner}/${repo}`); - - // Sort to ensure the latest workflow run is the first - filtered.sort((a, b) => { - return new Date(b.created_at).getTime() - new Date(a.created_at).getTime(); - }); - - // Store the first workflow run, to determine if this is the latest one... - if (!latestWorkflowRun) { - latestWorkflowRun = filtered[0]; - } - - // Search through workflow artifacts until we find a workflow run w/ artifact name that we are looking for - for (const workflowRun of filtered) { - core.info(`Checking artifacts for workflow run: ${workflowRun.html_url}`); - - const { - data: { artifacts }, - } = await octokit.rest.actions.listWorkflowRunArtifacts({ - owner, - repo, - run_id: workflowRun.id, - }); - - if (!artifacts) { - core.warning( - `Unable to fetch artifacts for branch: ${branch}, workflow: ${workflow_id}, workflowRunId: ${workflowRun.id}`, - ); - } else { - const foundArtifact = artifacts.find(({ name }) => name === artifactName); - if (foundArtifact) { - core.info(`Found suitable artifact XXX: ${foundArtifact.url}`); - return { - artifact: foundArtifact, - workflowRun, - isLatest: latestWorkflowRun.id === workflowRun.id, - }; - } else { - core.info(`No artifact found for ${artifactName}, trying next workflow run...`); - } - } - } - - if (currentPage > DEFAULT_MAX_PAGES) { - core.warning(`Workflow ${workflow_id} not found in branch: ${branch}`); - core.endGroup(); - return null; - } - - currentPage++; - } - - core.warning(`Artifact not found: ${artifactName}`); - core.endGroup(); - return null; -} - run(); /** diff --git a/dev-packages/size-limit-gh-action/utils/size-limit-formatter.mjs b/dev-packages/size-limit-gh-action/utils/SizeLimitFormatter.mjs similarity index 98% rename from dev-packages/size-limit-gh-action/utils/size-limit-formatter.mjs rename to dev-packages/size-limit-gh-action/utils/SizeLimitFormatter.mjs index e2687910a0f3..11a8963f703e 100644 --- a/dev-packages/size-limit-gh-action/utils/size-limit-formatter.mjs +++ b/dev-packages/size-limit-gh-action/utils/SizeLimitFormatter.mjs @@ -7,7 +7,7 @@ const EmptyResult = { size: 0, }; -export class SizeLimit { +export class SizeLimitFormatter { formatBytes(size) { return bytes.format(size, { unitSeparator: ' ' }); } diff --git a/dev-packages/size-limit-gh-action/utils/getArtifactsForBranchAndWorkflow.mjs b/dev-packages/size-limit-gh-action/utils/getArtifactsForBranchAndWorkflow.mjs new file mode 100644 index 000000000000..62a9d3878756 --- /dev/null +++ b/dev-packages/size-limit-gh-action/utils/getArtifactsForBranchAndWorkflow.mjs @@ -0,0 +1,134 @@ +import * as core from '@actions/core'; + +// max pages of workflows to pagination through +const DEFAULT_MAX_PAGES = 50; +// max results per page +const DEFAULT_PAGE_LIMIT = 10; + +/** + * Fetch artifacts from a workflow run from a branch + * + * This is a bit hacky since GitHub Actions currently does not directly + * support downloading artifacts from other workflows + */ +/** + * Fetch artifacts from a workflow run from a branch + * + * This is a bit hacky since GitHub Actions currently does not directly + * support downloading artifacts from other workflows + */ +export async function getArtifactsForBranchAndWorkflow(octokit, { owner, repo, workflowName, branch, artifactName }) { + core.startGroup(`getArtifactsForBranchAndWorkflow - workflow:"${workflowName}", branch:"${branch}"`); + + let repositoryWorkflow = null; + + // For debugging + const allWorkflows = []; + + // + // Find workflow id from `workflowName` + // + for await (const response of octokit.paginate.iterator(octokit.rest.actions.listRepoWorkflows, { + owner, + repo, + })) { + const targetWorkflow = response.data.find(({ name }) => name === workflowName); + + allWorkflows.push(...response.data.map(({ name }) => name)); + + // If not found in responses, continue to search on next page + if (!targetWorkflow) { + continue; + } + + repositoryWorkflow = targetWorkflow; + break; + } + + if (!repositoryWorkflow) { + core.info( + `Unable to find workflow with name "${workflowName}" in the repository. Found workflows: ${allWorkflows.join( + ', ', + )}`, + ); + core.endGroup(); + return null; + } + + const workflow_id = repositoryWorkflow.id; + + let currentPage = 0; + let latestWorkflowRun = null; + + for await (const response of octokit.paginate.iterator(octokit.rest.actions.listWorkflowRuns, { + owner, + repo, + workflow_id, + branch, + per_page: DEFAULT_PAGE_LIMIT, + event: 'push', + })) { + if (!response.data.length) { + core.warning(`Workflow ${workflow_id} not found in branch ${branch}`); + core.endGroup(); + return null; + } + + // Do not allow downloading artifacts from a fork. + const filtered = response.data.filter(workflowRun => workflowRun.head_repository.full_name === `${owner}/${repo}`); + + // Sort to ensure the latest workflow run is the first + filtered.sort((a, b) => { + return new Date(b.created_at).getTime() - new Date(a.created_at).getTime(); + }); + + // Store the first workflow run, to determine if this is the latest one... + if (!latestWorkflowRun) { + latestWorkflowRun = filtered[0]; + } + + // Search through workflow artifacts until we find a workflow run w/ artifact name that we are looking for + for (const workflowRun of filtered) { + core.info(`Checking artifacts for workflow run: ${workflowRun.html_url}`); + + const { + data: { artifacts }, + } = await octokit.rest.actions.listWorkflowRunArtifacts({ + owner, + repo, + run_id: workflowRun.id, + }); + + if (!artifacts) { + core.warning( + `Unable to fetch artifacts for branch: ${branch}, workflow: ${workflow_id}, workflowRunId: ${workflowRun.id}`, + ); + } else { + const foundArtifact = artifacts.find(({ name }) => name === artifactName); + if (foundArtifact) { + core.info(`Found suitable artifact: ${foundArtifact.url}`); + core.endGroup(); + return { + artifact: foundArtifact, + workflowRun, + isLatest: latestWorkflowRun.id === workflowRun.id, + }; + } else { + core.info(`No artifact found for ${artifactName}, trying next workflow run...`); + } + } + } + + if (currentPage > DEFAULT_MAX_PAGES) { + core.warning(`Workflow ${workflow_id} not found in branch: ${branch}`); + core.endGroup(); + return null; + } + + currentPage++; + } + + core.warning(`Artifact not found: ${artifactName}`); + core.endGroup(); + return null; +} From d36c032829e07b37fd097333a174f353bbc5c432 Mon Sep 17 00:00:00 2001 From: Francesco Novy Date: Fri, 30 Aug 2024 11:41:15 +0200 Subject: [PATCH 10/25] streamline log group better --- dev-packages/size-limit-gh-action/index.mjs | 5 ++++- .../utils/getArtifactsForBranchAndWorkflow.mjs | 6 ------ 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/dev-packages/size-limit-gh-action/index.mjs b/dev-packages/size-limit-gh-action/index.mjs index 8b3322470064..c46be2e8edc6 100644 --- a/dev-packages/size-limit-gh-action/index.mjs +++ b/dev-packages/size-limit-gh-action/index.mjs @@ -82,12 +82,15 @@ async function run() { let baseWorkflowRun; try { + const workflowName = `${process.env.GITHUB_WORKFLOW || ''}`; + core.startGroup(`getArtifactsForBranchAndWorkflow - workflow:"${workflowName}", branch:"${comparisonBranch}"`); const artifacts = await getArtifactsForBranchAndWorkflow(octokit, { ...repo, artifactName: ARTIFACT_NAME, branch: comparisonBranch, - workflowName: `${process.env.GITHUB_WORKFLOW || ''}`, + workflowName }); + core.endGroup(); if (!artifacts) { throw new Error('No artifacts found'); diff --git a/dev-packages/size-limit-gh-action/utils/getArtifactsForBranchAndWorkflow.mjs b/dev-packages/size-limit-gh-action/utils/getArtifactsForBranchAndWorkflow.mjs index 62a9d3878756..6d512b46afe1 100644 --- a/dev-packages/size-limit-gh-action/utils/getArtifactsForBranchAndWorkflow.mjs +++ b/dev-packages/size-limit-gh-action/utils/getArtifactsForBranchAndWorkflow.mjs @@ -18,8 +18,6 @@ const DEFAULT_PAGE_LIMIT = 10; * support downloading artifacts from other workflows */ export async function getArtifactsForBranchAndWorkflow(octokit, { owner, repo, workflowName, branch, artifactName }) { - core.startGroup(`getArtifactsForBranchAndWorkflow - workflow:"${workflowName}", branch:"${branch}"`); - let repositoryWorkflow = null; // For debugging @@ -51,7 +49,6 @@ export async function getArtifactsForBranchAndWorkflow(octokit, { owner, repo, w ', ', )}`, ); - core.endGroup(); return null; } @@ -70,7 +67,6 @@ export async function getArtifactsForBranchAndWorkflow(octokit, { owner, repo, w })) { if (!response.data.length) { core.warning(`Workflow ${workflow_id} not found in branch ${branch}`); - core.endGroup(); return null; } @@ -107,7 +103,6 @@ export async function getArtifactsForBranchAndWorkflow(octokit, { owner, repo, w const foundArtifact = artifacts.find(({ name }) => name === artifactName); if (foundArtifact) { core.info(`Found suitable artifact: ${foundArtifact.url}`); - core.endGroup(); return { artifact: foundArtifact, workflowRun, @@ -121,7 +116,6 @@ export async function getArtifactsForBranchAndWorkflow(octokit, { owner, repo, w if (currentPage > DEFAULT_MAX_PAGES) { core.warning(`Workflow ${workflow_id} not found in branch: ${branch}`); - core.endGroup(); return null; } From 6d9a2d1f3eaed55caadf2734619e04b7682191aa Mon Sep 17 00:00:00 2001 From: Francesco Novy Date: Fri, 30 Aug 2024 11:45:16 +0200 Subject: [PATCH 11/25] fix linting & import --- dev-packages/size-limit-gh-action/index.mjs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/dev-packages/size-limit-gh-action/index.mjs b/dev-packages/size-limit-gh-action/index.mjs index c46be2e8edc6..4cd2b1614468 100644 --- a/dev-packages/size-limit-gh-action/index.mjs +++ b/dev-packages/size-limit-gh-action/index.mjs @@ -10,7 +10,7 @@ import * as glob from '@actions/glob'; import * as io from '@actions/io'; import { markdownTable } from 'markdown-table'; -import { SizeLimit } from './utils/SizeLimitFormatter.mjs'; +import { SizeLimitFormatter } from './utils/SizeLimitFormatter.mjs'; import { getArtifactsForBranchAndWorkflow } from './utils/getArtifactsForBranchAndWorkflow.mjs'; const SIZE_LIMIT_HEADING = '## size-limit report 📦 '; @@ -67,7 +67,7 @@ async function run() { } const octokit = getOctokit(githubToken); - const limit = new SizeLimit(); + const limit = new SizeLimitFormatter(); const resultsFilePath = getResultsFilePath(); // If we have no comparison branch, we just run size limit & store the result as artifact @@ -88,7 +88,7 @@ async function run() { ...repo, artifactName: ARTIFACT_NAME, branch: comparisonBranch, - workflowName + workflowName, }); core.endGroup(); @@ -189,7 +189,7 @@ async function run() { async function runSizeLimitOnComparisonBranch() { const resultsFilePath = getResultsFilePath(); - const limit = new SizeLimit(); + const limit = new SizeLimitFormatter(); const artifactClient = artifact.create(); const { output: baseOutput } = await execSizeLimit(); From dec6cfd8a09da1ef3bc6c82780cb467bf2aa9d28 Mon Sep 17 00:00:00 2001 From: Francesco Novy Date: Fri, 30 Aug 2024 12:06:21 +0200 Subject: [PATCH 12/25] more debug --- dev-packages/size-limit-gh-action/index.mjs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/dev-packages/size-limit-gh-action/index.mjs b/dev-packages/size-limit-gh-action/index.mjs index 4cd2b1614468..42daa27beb0f 100644 --- a/dev-packages/size-limit-gh-action/index.mjs +++ b/dev-packages/size-limit-gh-action/index.mjs @@ -129,6 +129,10 @@ async function run() { const sizeLimitComment = await fetchPreviousComment(octokit, repo, pr); + if (sizeLimitComment) { + core.debug('Found existing size limit comment, udpating it instead of creating a new one...'); + } + const shouldComment = isNaN(thresholdNumber) || limit.hasSizeChanges(base, current, thresholdNumber) || sizeLimitComment; @@ -175,6 +179,8 @@ async function run() { "Error updating comment. This can happen for PR's originating from a fork without write permissions.", ); } + } else { + core.debug('Skipping comment because there are no changed.'); } if (status > 0) { From 60eff92334f7f47046e8dbff9a59fc52942f66de Mon Sep 17 00:00:00 2001 From: Francesco Novy Date: Fri, 30 Aug 2024 12:15:25 +0200 Subject: [PATCH 13/25] fix it --- dev-packages/size-limit-gh-action/index.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev-packages/size-limit-gh-action/index.mjs b/dev-packages/size-limit-gh-action/index.mjs index 42daa27beb0f..3c1d0f8c10d4 100644 --- a/dev-packages/size-limit-gh-action/index.mjs +++ b/dev-packages/size-limit-gh-action/index.mjs @@ -180,7 +180,7 @@ async function run() { ); } } else { - core.debug('Skipping comment because there are no changed.'); + core.debug('Skipping comment because there are no changes.'); } if (status > 0) { From 605ff632d7f85f1f3b301f29a29ad9c247437479 Mon Sep 17 00:00:00 2001 From: Francesco Novy Date: Fri, 30 Aug 2024 12:15:32 +0200 Subject: [PATCH 14/25] WIP add test content --- packages/browser/src/index.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/packages/browser/src/index.ts b/packages/browser/src/index.ts index 10b974dc35e8..65185d767dca 100644 --- a/packages/browser/src/index.ts +++ b/packages/browser/src/index.ts @@ -41,6 +41,21 @@ export { export * from './metrics'; +export const testThing = + 'just adding some stuff here to ensure this is larger, so size limit is triggered, yes yes yes. '; + +/** test */ +export class MyTestClass { + /** test */ + // eslint-disable-next-line @sentry-internal/sdk/no-class-field-initializers + public aha = 'why is this even here? I DO NOT UNDERSTAND!!'; + + /** test */ + public doSomething(): string { + return 'this does not even make any sense...'; + } +} + export { defaultRequestInstrumentationOptions, instrumentOutgoingRequests, From ad0528cbe3fb1b5a2623d0bd3afbc9994247ba1d Mon Sep 17 00:00:00 2001 From: Francesco Novy Date: Mon, 2 Sep 2024 10:58:47 +0200 Subject: [PATCH 15/25] some more debug & changes --- dev-packages/size-limit-gh-action/index.mjs | 1 + .../utils/SizeLimitFormatter.mjs | 12 ++++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/dev-packages/size-limit-gh-action/index.mjs b/dev-packages/size-limit-gh-action/index.mjs index 3c1d0f8c10d4..e81764409d25 100644 --- a/dev-packages/size-limit-gh-action/index.mjs +++ b/dev-packages/size-limit-gh-action/index.mjs @@ -181,6 +181,7 @@ async function run() { } } else { core.debug('Skipping comment because there are no changes.'); + core.debug(`Base result:\n\n${base}`); } if (status > 0) { diff --git a/dev-packages/size-limit-gh-action/utils/SizeLimitFormatter.mjs b/dev-packages/size-limit-gh-action/utils/SizeLimitFormatter.mjs index 11a8963f703e..bf77c947c631 100644 --- a/dev-packages/size-limit-gh-action/utils/SizeLimitFormatter.mjs +++ b/dev-packages/size-limit-gh-action/utils/SizeLimitFormatter.mjs @@ -97,13 +97,17 @@ export class SizeLimitFormatter { } hasSizeChanges(base, current, threshold = 0) { - const names = [...new Set([...(base ? Object.keys(base) : []), ...Object.keys(current)])]; + if(!base || !current) { + return true; + } - return !!names.find(name => { - const baseResult = base?.[name] || EmptyResult; + const names = [...new Set([...(Object.keys(base)), ...Object.keys(current)])]; + + return names.some(name => { + const baseResult = base[name] || EmptyResult; const currentResult = current[name] || EmptyResult; - if (baseResult.size === 0 && currentResult.size === 0) { + if (baseResult.size === 0 || currentResult.size === 0) { return true; } From e8ab2b6a5fbacfde9488a5eb6c87503589950777 Mon Sep 17 00:00:00 2001 From: Francesco Novy Date: Mon, 2 Sep 2024 12:05:06 +0200 Subject: [PATCH 16/25] proper log --- dev-packages/size-limit-gh-action/index.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev-packages/size-limit-gh-action/index.mjs b/dev-packages/size-limit-gh-action/index.mjs index e81764409d25..1bdca9d25f23 100644 --- a/dev-packages/size-limit-gh-action/index.mjs +++ b/dev-packages/size-limit-gh-action/index.mjs @@ -181,7 +181,7 @@ async function run() { } } else { core.debug('Skipping comment because there are no changes.'); - core.debug(`Base result:\n\n${base}`); + core.debug(`Base result:\n\n${JSON.stringify(base, null, 2)}`); } if (status > 0) { From c6844d93ee0ccb8a5c625c5fc27eb13a020b6bef Mon Sep 17 00:00:00 2001 From: Francesco Novy Date: Mon, 2 Sep 2024 13:24:08 +0200 Subject: [PATCH 17/25] debug sizes more... --- .../utils/SizeLimitFormatter.mjs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/dev-packages/size-limit-gh-action/utils/SizeLimitFormatter.mjs b/dev-packages/size-limit-gh-action/utils/SizeLimitFormatter.mjs index bf77c947c631..ce270ad9c318 100644 --- a/dev-packages/size-limit-gh-action/utils/SizeLimitFormatter.mjs +++ b/dev-packages/size-limit-gh-action/utils/SizeLimitFormatter.mjs @@ -1,3 +1,4 @@ +import * as core from '@actions/core'; import bytes from 'bytes'; const SIZE_RESULTS_HEADER = ['Path', 'Size', '% Change', 'Change']; @@ -97,17 +98,28 @@ export class SizeLimitFormatter { } hasSizeChanges(base, current, threshold = 0) { - if(!base || !current) { + if (!base || !current) { return true; } - const names = [...new Set([...(Object.keys(base)), ...Object.keys(current)])]; + const names = [...new Set([...Object.keys(base), ...Object.keys(current)])]; + + core.debug('hasSizeChanges....', names); return names.some(name => { const baseResult = base[name] || EmptyResult; const currentResult = current[name] || EmptyResult; - if (baseResult.size === 0 || currentResult.size === 0) { + // DEBUGGING?! + core.debug( + 'comparing...', + name, + baseResult.size, + currentResult.size, + Math.abs((currentResult.size - baseResult.size) / baseResult.size) * 100 > threshold, + ); + + if (!baseResult.size || !currentResult.size) { return true; } From afd1f8fa03d9588e0b0906ff0ca1d6d5944aa075 Mon Sep 17 00:00:00 2001 From: Francesco Novy Date: Mon, 2 Sep 2024 13:30:43 +0200 Subject: [PATCH 18/25] fix debug --- .../size-limit-gh-action/utils/SizeLimitFormatter.mjs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/dev-packages/size-limit-gh-action/utils/SizeLimitFormatter.mjs b/dev-packages/size-limit-gh-action/utils/SizeLimitFormatter.mjs index ce270ad9c318..13c82ae5d1c1 100644 --- a/dev-packages/size-limit-gh-action/utils/SizeLimitFormatter.mjs +++ b/dev-packages/size-limit-gh-action/utils/SizeLimitFormatter.mjs @@ -112,11 +112,9 @@ export class SizeLimitFormatter { // DEBUGGING?! core.debug( - 'comparing...', - name, - baseResult.size, - currentResult.size, - Math.abs((currentResult.size - baseResult.size) / baseResult.size) * 100 > threshold, + `comparing ${name} - ${baseResult.size} vs ${currentResult.size} - ${ + Math.abs((currentResult.size - baseResult.size) / baseResult.size) * 100 + }`, ); if (!baseResult.size || !currentResult.size) { From 03c933c27186779d5e67295f279d58636ac2f13e Mon Sep 17 00:00:00 2001 From: Francesco Novy Date: Mon, 2 Sep 2024 13:58:12 +0200 Subject: [PATCH 19/25] grow more?? --- packages/core/src/getCurrentHubShim.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/core/src/getCurrentHubShim.ts b/packages/core/src/getCurrentHubShim.ts index 46f8f94cb490..49808ddf76e1 100644 --- a/packages/core/src/getCurrentHubShim.ts +++ b/packages/core/src/getCurrentHubShim.ts @@ -24,6 +24,13 @@ import { // eslint-disable-next-line deprecation/deprecation export function getCurrentHubShim(): Hub { return { + // @ts-expect-error ignore this + aha: 'why is this even here? I DO NOT UNDERSTAND!!', + + doSomething(): string { + return 'this does not even make any sense...'; + }, + bindClient(client: Client): void { const scope = getCurrentScope(); scope.setClient(client); From 2e34805ff967e5b1dc2bbceeed60fb9be70d24ee Mon Sep 17 00:00:00 2001 From: Francesco Novy Date: Mon, 2 Sep 2024 15:43:18 +0200 Subject: [PATCH 20/25] fixes & cleanup --- dev-packages/size-limit-gh-action/index.mjs | 3 --- .../utils/SizeLimitFormatter.mjs | 12 +----------- 2 files changed, 1 insertion(+), 14 deletions(-) diff --git a/dev-packages/size-limit-gh-action/index.mjs b/dev-packages/size-limit-gh-action/index.mjs index 1bdca9d25f23..680d12237bf5 100644 --- a/dev-packages/size-limit-gh-action/index.mjs +++ b/dev-packages/size-limit-gh-action/index.mjs @@ -158,8 +158,6 @@ async function run() { const body = bodyParts.join('\r\n'); - core.debug(`Posting PR comment: \n\n${body}`); - try { if (!sizeLimitComment) { await octokit.rest.issues.createComment({ @@ -181,7 +179,6 @@ async function run() { } } else { core.debug('Skipping comment because there are no changes.'); - core.debug(`Base result:\n\n${JSON.stringify(base, null, 2)}`); } if (status > 0) { diff --git a/dev-packages/size-limit-gh-action/utils/SizeLimitFormatter.mjs b/dev-packages/size-limit-gh-action/utils/SizeLimitFormatter.mjs index 13c82ae5d1c1..27ac587f095d 100644 --- a/dev-packages/size-limit-gh-action/utils/SizeLimitFormatter.mjs +++ b/dev-packages/size-limit-gh-action/utils/SizeLimitFormatter.mjs @@ -1,4 +1,3 @@ -import * as core from '@actions/core'; import bytes from 'bytes'; const SIZE_RESULTS_HEADER = ['Path', 'Size', '% Change', 'Change']; @@ -18,7 +17,7 @@ export class SizeLimitFormatter { return this.formatBytes(size); } - return `⛔️ ${this.formatBytes(size)} (max: ${this.formatBytes(sizeLimit)})`; + return `⛔️ ${this.formatBytes(size)}\n(max: ${this.formatBytes(sizeLimit)})`; } formatPercentageChange(base = 0, current = 0) { @@ -104,19 +103,10 @@ export class SizeLimitFormatter { const names = [...new Set([...Object.keys(base), ...Object.keys(current)])]; - core.debug('hasSizeChanges....', names); - return names.some(name => { const baseResult = base[name] || EmptyResult; const currentResult = current[name] || EmptyResult; - // DEBUGGING?! - core.debug( - `comparing ${name} - ${baseResult.size} vs ${currentResult.size} - ${ - Math.abs((currentResult.size - baseResult.size) / baseResult.size) * 100 - }`, - ); - if (!baseResult.size || !currentResult.size) { return true; } From 7b374f7e761002c3b588961cc2a0ed5bef6e8f50 Mon Sep 17 00:00:00 2001 From: Francesco Novy Date: Mon, 2 Sep 2024 16:03:04 +0200 Subject: [PATCH 21/25] fix formatting --- .../size-limit-gh-action/utils/SizeLimitFormatter.mjs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/dev-packages/size-limit-gh-action/utils/SizeLimitFormatter.mjs b/dev-packages/size-limit-gh-action/utils/SizeLimitFormatter.mjs index 27ac587f095d..b9372673a4f2 100644 --- a/dev-packages/size-limit-gh-action/utils/SizeLimitFormatter.mjs +++ b/dev-packages/size-limit-gh-action/utils/SizeLimitFormatter.mjs @@ -12,12 +12,12 @@ export class SizeLimitFormatter { return bytes.format(size, { unitSeparator: ' ' }); } - formatSizeLimitResult(size, sizeLimit, passed) { + formatName(name, sizeLimit, passed) { if (passed) { - return this.formatBytes(size); + return name; } - return `⛔️ ${this.formatBytes(size)}\n(max: ${this.formatBytes(sizeLimit)})`; + return `⛔️ ${name} (max: ${this.formatBytes(sizeLimit)})`; } formatPercentageChange(base = 0, current = 0) { @@ -72,8 +72,8 @@ export class SizeLimitFormatter { formatSizeResult(name, base, current) { return [ - name, - this.formatSizeLimitResult(current.size, current.sizeLimit, current.passed), + this.formatName(name, current.sizeLimit, current.passed), + this.formatBytes(current.size), this.formatPercentageChange(base.size, current.size), this.formatChange(base.size, current.size), ]; From b3be271009522ffe9a3ba372dbfaf1536131b0a5 Mon Sep 17 00:00:00 2001 From: Francesco Novy Date: Mon, 2 Sep 2024 16:10:02 +0200 Subject: [PATCH 22/25] Revert "grow more??" This reverts commit c12934808a71df34df932b07d083bda3e0ea7128. --- packages/core/src/getCurrentHubShim.ts | 7 ------- 1 file changed, 7 deletions(-) diff --git a/packages/core/src/getCurrentHubShim.ts b/packages/core/src/getCurrentHubShim.ts index 49808ddf76e1..46f8f94cb490 100644 --- a/packages/core/src/getCurrentHubShim.ts +++ b/packages/core/src/getCurrentHubShim.ts @@ -24,13 +24,6 @@ import { // eslint-disable-next-line deprecation/deprecation export function getCurrentHubShim(): Hub { return { - // @ts-expect-error ignore this - aha: 'why is this even here? I DO NOT UNDERSTAND!!', - - doSomething(): string { - return 'this does not even make any sense...'; - }, - bindClient(client: Client): void { const scope = getCurrentScope(); scope.setClient(client); From 21db29887b80045cb3696d6a98d374ed0f673b64 Mon Sep 17 00:00:00 2001 From: Francesco Novy Date: Mon, 2 Sep 2024 16:10:16 +0200 Subject: [PATCH 23/25] Revert "WIP add test content" This reverts commit 233026977fd06b260b79ad000278bbf12cc9fd1b. --- packages/browser/src/index.ts | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/packages/browser/src/index.ts b/packages/browser/src/index.ts index 65185d767dca..10b974dc35e8 100644 --- a/packages/browser/src/index.ts +++ b/packages/browser/src/index.ts @@ -41,21 +41,6 @@ export { export * from './metrics'; -export const testThing = - 'just adding some stuff here to ensure this is larger, so size limit is triggered, yes yes yes. '; - -/** test */ -export class MyTestClass { - /** test */ - // eslint-disable-next-line @sentry-internal/sdk/no-class-field-initializers - public aha = 'why is this even here? I DO NOT UNDERSTAND!!'; - - /** test */ - public doSomething(): string { - return 'this does not even make any sense...'; - } -} - export { defaultRequestInstrumentationOptions, instrumentOutgoingRequests, From 30f4a4049010a44b2aafd0eb1b308829d739d07b Mon Sep 17 00:00:00 2001 From: Francesco Novy Date: Mon, 2 Sep 2024 16:10:35 +0200 Subject: [PATCH 24/25] Revert "WIP debug try failed size limit" This reverts commit c2de49c14885c5fa7f7332e02115fcaaf338fa20. --- .size-limit.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.size-limit.js b/.size-limit.js index 7f97f6d3536f..d2211d91d5b0 100644 --- a/.size-limit.js +++ b/.size-limit.js @@ -8,7 +8,7 @@ module.exports = [ path: 'packages/browser/build/npm/esm/index.js', import: createImport('init'), gzip: true, - limit: '20 KB', + limit: '24 KB', }, { name: '@sentry/browser (incl. Tracing)', From 5b05303679e055a9973be7b72fb0b880b209ab07 Mon Sep 17 00:00:00 2001 From: Francesco Novy Date: Tue, 3 Sep 2024 16:29:26 +0200 Subject: [PATCH 25/25] add debug log --- .../size-limit-gh-action/utils/SizeLimitFormatter.mjs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/dev-packages/size-limit-gh-action/utils/SizeLimitFormatter.mjs b/dev-packages/size-limit-gh-action/utils/SizeLimitFormatter.mjs index b9372673a4f2..034281b38224 100644 --- a/dev-packages/size-limit-gh-action/utils/SizeLimitFormatter.mjs +++ b/dev-packages/size-limit-gh-action/utils/SizeLimitFormatter.mjs @@ -1,3 +1,4 @@ +import * as core from '@actions/core'; import bytes from 'bytes'; const SIZE_RESULTS_HEADER = ['Path', 'Size', '% Change', 'Change']; @@ -71,6 +72,12 @@ export class SizeLimitFormatter { } formatSizeResult(name, base, current) { + if (!current.passed) { + core.debug( + `Size limit exceeded for ${name} - ${this.formatBytes(current.size)} > ${this.formatBytes(current.sizeLimit)}`, + ); + } + return [ this.formatName(name, current.sizeLimit, current.passed), this.formatBytes(current.size),