Skip to content

Compare Bundle Size #53

Compare Bundle Size

Compare Bundle Size #53

name: Compare Bundle Size
on:
workflow_run:
workflows: ['Build']
types: [completed]
permissions:
contents: read
actions: read
# To create the comment
pull-requests: write
jobs:
compare:
name: Compare Bundle Stats
runs-on: ubuntu-latest
if: github.event.workflow_run.event == 'pull_request'
steps:
- name: Harden Runner
uses: step-security/harden-runner@f4a75cfd619ee5ce8d5b864b0d183aff3c69b55a # v2.13.1
with:
egress-policy: audit
- name: Git Checkout
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
- name: Download Stats (HEAD)
uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6.0.0
with:
name: webpack-stats
path: head-stats
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Get Run ID from BASE
id: base-run
env:
WORKFLOW_ID: ${{ github.event.workflow_run.workflow_id }}
GH_TOKEN: ${{ github.token }}
run: |
ID=$(gh run list -c $GITHUB_SHA -w $WORKFLOW_ID -L 1 --json databaseId --jq ".[].databaseId")
echo "run_id=$ID" >> $GITHUB_OUTPUT
- name: Download Stats (BASE)
uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6.0.0
with:
name: webpack-stats
path: base-stats
run-id: ${{ steps.base-run.outputs.run_id }}
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Compare Bundle Size
id: compare-bundle-size
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
env:
HEAD_STATS_PATH: ./head-stats/webpack-stats.json
BASE_STATS_PATH: ./base-stats/webpack-stats.json
with:
script: |
const { compare } = await import('${{github.workspace}}/apps/site/scripts/compare-size/index.mjs')
await compare({core})
- name: Add Comment to PR
uses: thollander/actions-comment-pull-request@e2c37e53a7d2227b61585343765f73a9ca57eda9 # v3.0.0
with:
comment-tag: 'compare_bundle_size'
message: ${{ steps.compare-bundle-size.outputs.comment }}
pr-number: ${{ github.event.workflow_run.pull_requests[0].number }}