Skip to content

Commit

Permalink
ci: add additional workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
timeowilliams committed Sep 14, 2024
1 parent af8627a commit 2d24c80
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 9 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/package-size-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ jobs:
build:
runs-on: ubuntu-latest

permissions:
contents: write

steps:
- name: Checkout code
uses: actions/checkout@v4
Expand Down
33 changes: 33 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: "Run Size Limit Test"

on:
push:
branches:
- main

jobs:
run-size-limit:
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: Clean npm cache
run: npm cache clean --force

- name: Install dependencies
run: npm ci

- name: List files in build directory
run: ls -R build/static/js/

- name: Run size-limit
run: npx size-limit --json || node size-limit.js

timeout-minutes: 10
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: "Package Size Badge Action"
description: "GitHub Action to calculate JavaScript package size and create a dynamic badge."
author: "Your Name"
author: "Timeo Williams"

inputs:
github_token:
Expand Down
14 changes: 6 additions & 8 deletions size-limit.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ import core from "@actions/core";

// Step 3: Run size-limit to generate the report
try {
execSync("npx size-limit --json > size-report.json");
console.log("Running size-limit...");
execSync("npx size-limit --json > size-report.json", {
stdio: "inherit",
});
console.log("Size limit executed successfully");
} catch (error) {
core.setFailed(
"Failed to run size-limit. Ensure size-limit is installed and configured correctly.",
);
core.setFailed(`Failed to run size-limit: ${error.message}`);
return;
}

Expand All @@ -51,10 +53,6 @@ import core from "@actions/core";
const size = Math.round(report[0].size / 1024); // Convert bytes to KB
core.setOutput("size", size);
console.log(`Bundle size: ${size} KB`);

// Step 6: Create the badge URL using shields.io
const badgeUrl = `https://img.shields.io/badge/${encodeURIComponent(label)}-${size}KB-${color}`;
console.log(`Badge URL: ${badgeUrl}`);
} catch (error) {
core.setFailed(error.message);
}
Expand Down

0 comments on commit 2d24c80

Please sign in to comment.