Skip to content

chore: add new workfow #2

chore: add new workfow

chore: add new workfow #2

Workflow file for this run

name: "Package Size Badge"
on:
push:
branches:
- main
pull_request:
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
- name: Install dependencies
run: npm ci
- name: Run size-limit to calculate bundle size
id: size-limit # We capture the size-limit output here
run: |
npx size-limit --json > size-report.json
size=$(cat size-report.json | jq '.[0].size' | xargs -I {} echo "{}/1024" | bc)
echo "size=${size}" >> $GITHUB_ENV
# jq is used to extract the size from the JSON report
# The size is divided by 1024 to convert bytes to KB and stored in the environment variable
- name: Generate badge URL
id: generate-badge
run: |
size=${{ env.size }}
echo "Badge URL: https://img.shields.io/badge/Bundle_Size-${size}KB-green"
echo "badge-url=https://img.shields.io/badge/Bundle_Size-${size}KB-green" >> $GITHUB_ENV
echo "Badge URL: https://img.shields.io/badge/Bundle_Size-${size}KB-green" > badge-url.txt
- name: Upload badge URL artifact
uses: actions/upload-artifact@v4
with:
name: bundle-size-badge
path: badge-url.txt