Skip to content

Commit e560b57

Browse files
👷 Pr comment markdown table alignment (#3876)
1 parent 9ae1f79 commit e560b57

File tree

5 files changed

+35
-6
lines changed

5 files changed

+35
-6
lines changed

scripts/lib/executionUtils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export function formatSize(bytes: number | null, { includeSign = false } = {}):
4646

4747
const sign = includeSign && bytes > 0 ? '+' : ''
4848

49-
if (bytes < 1024) {
49+
if (bytes > -1024 && bytes < 1024) {
5050
return `${sign}${Math.round(bytes)} B`
5151
}
5252

scripts/performance/lib/bundleSizes.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,14 @@ export function formatBundleSizes({
5050
}) {
5151
let highIncreaseDetected = false
5252
let message = markdownArray({
53-
headers: ['📦 Bundle Name', 'Base Size', 'Local Size', '𝚫', '𝚫%', 'Status'],
53+
headers: [
54+
{ label: '📦 Bundle Name', align: 'left' },
55+
{ label: 'Base Size', align: 'right' },
56+
{ label: 'Local Size', align: 'right' },
57+
{ label: '𝚫', align: 'right' },
58+
{ label: '𝚫%', align: 'right' },
59+
{ label: 'Status', align: 'center' },
60+
],
5461
rows: localBundleSizes.map((localBundleSize) => {
5562
const baseBundleSize = baseBundleSizes.find((baseBundleSize) => baseBundleSize.name === localBundleSize.name)
5663

scripts/performance/lib/cpuPerformance.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,12 @@ function formatCpuPerformance({
121121
localCpuPerformances: PerformanceMetric[]
122122
}) {
123123
return markdownArray({
124-
headers: ['Action Name', 'Base CPU Time (ms)', 'Local CPU Time (ms)', '𝚫 (%)'],
124+
headers: [
125+
{ label: 'Action Name', align: 'left' },
126+
{ label: 'Base CPU Time (ms)', align: 'right' },
127+
{ label: 'Local CPU Time (ms)', align: 'right' },
128+
{ label: '𝚫%', align: 'right' },
129+
],
125130
rows: localCpuPerformances.map((localCpuPerformance) => {
126131
const baseCpuPerformance = baseCpuPerformances.find(
127132
(baseCpuPerformance) => baseCpuPerformance.name === localCpuPerformance.name

scripts/performance/lib/memoryPerformance.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,12 @@ function formatMemoryPerformance({
169169
localMemoryPerformances: PerformanceMetric[]
170170
}) {
171171
return markdownArray({
172-
headers: ['Action Name', 'Base Memory Consumption', 'Local Memory Consumption', '𝚫'],
172+
headers: [
173+
{ label: 'Action Name', align: 'left' },
174+
{ label: 'Base Memory Consumption', align: 'right' },
175+
{ label: 'Local Memory Consumption', align: 'right' },
176+
{ label: '𝚫', align: 'right' },
177+
],
173178
rows: localMemoryPerformances.map((localMemoryPerformance) => {
174179
const baseMemoryPerformance = baseMemoryPerformances.find(
175180
(baseMemoryPerformance) => baseMemoryPerformance.name === localMemoryPerformance.name

scripts/performance/lib/reportAsAPrComment.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,26 @@ async function updatePrComment(prNumber: number, message: string): Promise<void>
7676
}
7777

7878
interface MarkdownArrayOptions {
79-
headers: string[]
79+
headers: Array<{ label: string; align: 'left' | 'right' | 'center' }>
8080
rows: string[][]
8181
}
8282

8383
export function markdownArray({ headers, rows }: MarkdownArrayOptions): string {
84-
let markdown = `| ${headers.join(' | ')} |\n| ${new Array(headers.length).fill('---').join(' | ')} |\n`
84+
let markdown = `| ${headers.map((header) => header.label).join(' | ')} |\n`
85+
markdown += `| ${headers.map((header) => align(header.align)).join(' | ')} |\n`
86+
8587
rows.forEach((row) => {
8688
markdown += `| ${row.join(' | ')} |\n`
8789
})
8890
return markdown
8991
}
92+
93+
function align(align: 'left' | 'right' | 'center') {
94+
if (align === 'center') {
95+
return ':---:'
96+
} else if (align === 'right') {
97+
return '---:'
98+
}
99+
100+
return '---'
101+
}

0 commit comments

Comments
 (0)