Skip to content

Commit 2f413ec

Browse files
committed
chore: add new workfow
1 parent 2d24c80 commit 2f413ec

4 files changed

Lines changed: 38 additions & 25 deletions

File tree

.github/workflows/package-size-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
run: ls -R build/static/js/
3232

3333
- name: Run Package Size Badge Action
34-
uses: ./ # This will use the local action in the current repo
34+
uses: ./
3535
with:
3636
path: "build/static/js/*.js"
3737
preset: "app"

.github/workflows/test.yml

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
name: "Run Size Limit Test"
1+
name: "Package Size Badge"
22

33
on:
44
push:
55
branches:
66
- main
7+
pull_request:
78

89
jobs:
9-
run-size-limit:
10+
build:
1011
runs-on: ubuntu-latest
1112

1213
steps:
@@ -18,16 +19,28 @@ jobs:
1819
with:
1920
node-version: "20"
2021

21-
- name: Clean npm cache
22-
run: npm cache clean --force
23-
2422
- name: Install dependencies
2523
run: npm ci
2624

27-
- name: List files in build directory
28-
run: ls -R build/static/js/
29-
30-
- name: Run size-limit
31-
run: npx size-limit --json || node size-limit.js
32-
33-
timeout-minutes: 10
25+
- name: Run size-limit to calculate bundle size
26+
id: size-limit # We capture the size-limit output here
27+
run: |
28+
npx size-limit --json > size-report.json
29+
size=$(cat size-report.json | jq '.[0].size' | xargs -I {} echo "{}/1024" | bc)
30+
echo "size=${size}" >> $GITHUB_ENV
31+
# jq is used to extract the size from the JSON report
32+
# The size is divided by 1024 to convert bytes to KB and stored in the environment variable
33+
34+
- name: Generate badge URL
35+
id: generate-badge
36+
run: |
37+
size=${{ env.size }}
38+
echo "Badge URL: https://img.shields.io/badge/Bundle_Size-${size}KB-green"
39+
echo "badge-url=https://img.shields.io/badge/Bundle_Size-${size}KB-green" >> $GITHUB_ENV
40+
echo "Badge URL: https://img.shields.io/badge/Bundle_Size-${size}KB-green" > badge-url.txt
41+
42+
- name: Upload badge URL artifact
43+
uses: actions/upload-artifact@v4
44+
with:
45+
name: bundle-size-badge
46+
path: badge-url.txt

size-limit.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { execSync } from "child_process";
22
import fs from "fs";
3-
import core from "@actions/core";
3+
import * as core from "@actions/core";
44

55
(async function run() {
66
try {
@@ -12,18 +12,18 @@ import core from "@actions/core";
1212

1313
// Step 2: Ensure size-limit config is written to package.json
1414
const packageJsonPath = "./package.json";
15-
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
15+
// const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
1616

17-
// Update size-limit config if it doesn't exist
18-
packageJson["size-limit"] = [
19-
{
20-
path: path,
21-
limit: limit,
22-
},
23-
];
17+
// // Update size-limit config if it doesn't exist
18+
// packageJson["size-limit"] = [
19+
// {
20+
// path: path,
21+
// limit: limit,
22+
// },
23+
// ];
2424

25-
// Write updated config to package.json
26-
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
25+
// // Write updated config to package.json
26+
// fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
2727
console.log("Updated size-limit config in package.json");
2828

2929
// Step 3: Run size-limit to generate the report

size-report.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"passed": true,
55
"size": 88048,
66
"sizeLimit": 500000,
7-
"running": 2.1483,
7+
"running": 2.1714,
88
"loading": 1.7196875
99
}
1010
]

0 commit comments

Comments
 (0)