|
1 | | -const { readFile } = require('node:fs/promises'); |
| 1 | +import { readFile } from 'node:fs/promises'; |
2 | 2 |
|
3 | | -const { setFailed, setOutput } = require('@actions/core'); |
4 | | -const { getExecOutput } = require('@actions/exec'); |
5 | | -const { markdownTable } = require('markdown-table'); |
6 | | -const bytes = require('bytes'); |
7 | | - |
8 | | -/** |
9 | | - * @param size {number} |
10 | | - * @return {string | null} |
11 | | - */ |
12 | | -function formatBytes(size) { |
13 | | - return bytes.format(size, { unitSeparator: ' ' }); |
14 | | -} |
15 | | - |
16 | | -/** |
17 | | - * @param current {number} |
18 | | - * @param baseline {number} |
19 | | - * @return {string} |
20 | | - */ |
21 | | -function compareSizeWithBaseline(current, baseline) { |
22 | | - if (baseline === 0) { |
23 | | - return '+100% 🔺'; |
24 | | - } |
25 | | - |
26 | | - const value = ((current - baseline) / baseline) * 100; |
27 | | - const formatted = (Math.sign(value) * Math.ceil(Math.abs(value) * 100)) / 100; |
28 | | - |
29 | | - if (value > 0) { |
30 | | - return `+${formatted}% 🔺`; |
31 | | - } |
32 | | - |
33 | | - if (value === 0) { |
34 | | - return `${formatted}% 🟰`; |
35 | | - } |
36 | | - |
37 | | - return `${formatted}% 🔽👏`; |
38 | | -} |
| 3 | +import { setFailed, setOutput } from '@actions/core'; |
| 4 | +import { getExecOutput } from '@actions/exec'; |
| 5 | +import bytes from 'bytes'; |
| 6 | +import { markdownTable } from 'markdown-table'; |
39 | 7 |
|
40 | 8 | async function run() { |
41 | 9 | /** |
@@ -89,8 +57,36 @@ async function run() { |
89 | 57 | } |
90 | 58 | } |
91 | 59 |
|
92 | | -// Replace top-level await with function call that handles the promise |
93 | | -run().catch((error) => { |
94 | | - console.error(error); |
95 | | - setFailed(error.message); |
96 | | -}); |
| 60 | +/** |
| 61 | + * @param size {number} |
| 62 | + * @return {string | null} |
| 63 | + */ |
| 64 | +function formatBytes(size) { |
| 65 | + return bytes.format(size, { unitSeparator: ' ' }); |
| 66 | +} |
| 67 | + |
| 68 | +/** |
| 69 | + * @param current {number} |
| 70 | + * @param baseline {number} |
| 71 | + * @return {string} |
| 72 | + */ |
| 73 | +function compareSizeWithBaseline(current, baseline) { |
| 74 | + if (baseline === 0) { |
| 75 | + return '+100% 🔺'; |
| 76 | + } |
| 77 | + |
| 78 | + const value = ((current - baseline) / baseline) * 100; |
| 79 | + const formatted = (Math.sign(value) * Math.ceil(Math.abs(value) * 100)) / 100; |
| 80 | + |
| 81 | + if (value > 0) { |
| 82 | + return `+${formatted}% 🔺`; |
| 83 | + } |
| 84 | + |
| 85 | + if (value === 0) { |
| 86 | + return `${formatted}% 🟰`; |
| 87 | + } |
| 88 | + |
| 89 | + return `${formatted}% 🔽👏`; |
| 90 | +} |
| 91 | + |
| 92 | +await run(); |
0 commit comments