feat/universal-modal #2791
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 | |
on: | |
pull_request: | |
branches: | |
- master | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} | |
cancel-in-progress: true | |
jobs: | |
main: | |
name: Check bundle size | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Install dependencies | |
run: yarn --frozen-lockfile | |
- name: calculate size | |
run: yarn analyze-package-sizes | |
- name: compare results | |
id: cr | |
uses: actions/github-script@v6 | |
with: | |
script: | | |
const shell = require('shelljs'); | |
const fs = require('fs'); | |
try { | |
const ret = shell.exec( | |
`wget -qO- https://raw.githubusercontent.com/core-ds/core-components/master/.storybook/package-sizes.json`, | |
{ silent: true }); | |
const masterFile = JSON.parse(ret.stdout); | |
const currentFile = JSON.parse(fs.readFileSync('./.storybook/package-sizes.json').toString()); | |
let shouldComment = false; | |
const masterComponents = Object.keys(masterFile); | |
const currentComponents = Object.keys(currentFile); | |
const table = [...new Set([...masterComponents, ...currentComponents])] | |
.reduce((acc, packageName) => { | |
const entryPoints = [...new Set([...Object.keys(masterFile[packageName] || {}), ...Object.keys(currentFile[packageName] || {})])]; | |
entryPoints.forEach((entryPoint) => { | |
const now = currentFile[packageName]?.[entryPoint] || 0; | |
const before = masterFile[packageName]?.[entryPoint] || 0; | |
if (Math.abs(now - before) > 2) { | |
shouldComment = true; | |
acc += `| ${packageName}/${entryPoint} | ${now} ${ | |
now - before > 0 ? `(+${(now - before).toFixed(2)} KB🔺)` : `(-${(before - now).toFixed(2)} KB)` | |
} |\n`; | |
} | |
}); | |
return acc; | |
}, '## Bundle size report\n| Entry point | Size (minified) |\n| --- | --- |\n'); | |
if (shouldComment) { | |
core.setOutput('comment', table); | |
} | |
} catch (e) { | |
core.setFailed(e); | |
} | |
- name: Find Comment | |
if: ${{ steps.cr.outputs.comment != '' }} | |
uses: peter-evans/find-comment@v2 | |
id: fc | |
with: | |
token: ${{ secrets.BOT_AUTH_TOKEN }} | |
issue-number: ${{ github.event.pull_request.number }} | |
comment-author: 'core-ds-bot' | |
body-includes: Bundle size report | |
- name: Create comment | |
if: ${{ steps.cr.outputs.comment != '' }} | |
uses: peter-evans/create-or-update-comment@v3 | |
with: | |
token: ${{ secrets.BOT_AUTH_TOKEN }} | |
comment-id: ${{ steps.fc.outputs.comment-id }} | |
issue-number: ${{ github.event.pull_request.number }} | |
body: | | |
${{ steps.cr.outputs.comment }} | |
edit-mode: replace |