chore: add new workfow #2
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
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 |