-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
172 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[*] | ||
indent_style = space | ||
end_of_line = lf | ||
indent_size = 2 | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
|
||
[*.md] | ||
max_line_length = 0 | ||
trim_trailing_whitespace = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { exec } from "@actions/exec"; | ||
|
||
class Git { | ||
async execSizeLimit( | ||
branch?: string | ||
): Promise<{ status: number; output: string }> { | ||
let output = ""; | ||
|
||
if (branch) { | ||
await exec(`git checkout -f ${branch}`); | ||
} | ||
|
||
await exec("npm install"); | ||
await exec("npm run build"); | ||
const status = await exec("npx size-limit --json", [], { | ||
windowsVerbatimArguments: true, | ||
ignoreReturnCode: true, | ||
listeners: { | ||
stdout: (data: Buffer) => { | ||
output += data.toString(); | ||
} | ||
} | ||
}); | ||
|
||
return { | ||
status, | ||
output | ||
}; | ||
} | ||
} | ||
|
||
export default Git; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
// @ts-ignore | ||
import bytes from "bytes"; | ||
|
||
interface IResult { | ||
name: string; | ||
size: number; | ||
running: number; | ||
loading: number; | ||
total: number; | ||
} | ||
|
||
class SizeLimit { | ||
parseResults(output: string): { [name: string]: IResult } { | ||
const results = JSON.parse(output); | ||
|
||
return results.reduce( | ||
(current: { [name: string]: IResult }, result: any) => { | ||
const total = result.running + result.loading; | ||
|
||
return { | ||
...current, | ||
[result.name]: { | ||
name: result.name, | ||
size: +result.size, | ||
running: +result.running, | ||
loading: +result.loading, | ||
total | ||
} | ||
}; | ||
}, | ||
{} | ||
); | ||
} | ||
|
||
formatBytes(size: number): string { | ||
return bytes.format(size, { unitSeparator: " " }); | ||
} | ||
|
||
formatTime(seconds: number): string { | ||
if (seconds >= 1) { | ||
return `${Math.ceil(seconds * 10) / 10} s`; | ||
} | ||
|
||
return `${Math.ceil(seconds * 1000)} ms`; | ||
} | ||
|
||
formatChange(base: number = 0, current: number = 0): string { | ||
if (current === 0) { | ||
return "-100%"; | ||
} | ||
|
||
const value = ((current - base) / current) * 100; | ||
const formatted = | ||
(Math.sign(value) * Math.ceil(Math.abs(value) * 100)) / 100; | ||
|
||
if (value > 0) { | ||
return `+${formatted}% 🔺`; | ||
} | ||
|
||
if (value === 0) { | ||
return `${formatted}%`; | ||
} | ||
|
||
return `${formatted}% 🔽`; | ||
} | ||
|
||
formatLine(value: string, change: string) { | ||
return `${value} (${change})`; | ||
} | ||
|
||
formatResult(name: string, base: IResult, current: IResult): Array<string> { | ||
return [ | ||
name, | ||
this.formatLine( | ||
this.formatBytes(current.size), | ||
this.formatChange(base.size, current.size) | ||
), | ||
this.formatLine( | ||
this.formatTime(current.loading), | ||
this.formatChange(base.loading, current.loading) | ||
), | ||
this.formatLine( | ||
this.formatTime(current.running), | ||
this.formatChange(base.running, current.running) | ||
), | ||
this.formatTime(current.total) | ||
]; | ||
} | ||
|
||
formatResults( | ||
base: { [name: string]: IResult }, | ||
current: { [name: string]: IResult } | ||
): Array<Array<string>> { | ||
const names = [...new Set([...Object.keys(base), ...Object.keys(current)])]; | ||
|
||
return names.map((name: string) => | ||
this.formatResult(name, base[name], current[name]) | ||
); | ||
} | ||
} | ||
export default SizeLimit; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters