mirror of
https://github.com/videojs/video.js.git
synced 2026-11-20 06:29:27 +01:00
182 lines
5.5 KiB
YAML
182 lines
5.5 KiB
YAML
name: Bundle Size
|
|
|
|
on:
|
|
pull_request:
|
|
|
|
permissions:
|
|
pull-requests: write
|
|
|
|
jobs:
|
|
pr-size:
|
|
runs-on: blacksmith-4vcpu-ubuntu-2404
|
|
|
|
steps:
|
|
- name: Checkout PR
|
|
uses: actions/checkout@v5
|
|
with:
|
|
ref: ${{ github.event.pull_request.head.sha }}
|
|
|
|
- name: Setup pnpm
|
|
uses: pnpm/action-setup@v6.1.0
|
|
|
|
- name: Setup Node.js
|
|
uses: actions/setup-node@v5
|
|
with:
|
|
node-version-file: '.nvmrc'
|
|
cache: pnpm
|
|
|
|
- name: Install dependencies
|
|
run: pnpm install
|
|
|
|
- name: Restore Vite Task cache
|
|
uses: actions/cache/restore@v6
|
|
with:
|
|
path: node_modules/.vite/task-cache
|
|
key: vite-task-${{ runner.os }}-${{ runner.arch }}-restore-only-${{ github.run_id }}-${{ github.run_attempt }}-${{ github.job }}
|
|
restore-keys: |
|
|
vite-task-${{ runner.os }}-${{ runner.arch }}-packages-
|
|
|
|
- name: Build packages
|
|
run: pnpm build:packages
|
|
|
|
- name: Test bundle size reporting
|
|
run: pnpm test:size
|
|
|
|
- name: Measure bundle size
|
|
run: node .github/scripts/bundle-size.js --json pr-size.json
|
|
|
|
- name: Upload size data
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: pr-size
|
|
path: pr-size.json
|
|
|
|
base-size:
|
|
runs-on: blacksmith-4vcpu-ubuntu-2404
|
|
|
|
steps:
|
|
- name: Checkout comparison history
|
|
uses: actions/checkout@v5
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: Checkout merge base
|
|
env:
|
|
BASE_SHA: ${{ github.event.pull_request.base.sha }}
|
|
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
|
|
run: |
|
|
comparison_base=$(git merge-base "$HEAD_SHA" "$BASE_SHA")
|
|
echo "Checking out comparison base $comparison_base"
|
|
git checkout --detach "$comparison_base"
|
|
|
|
- name: Checkout PR scripts
|
|
uses: actions/checkout@v5
|
|
with:
|
|
repository: ${{ github.event.pull_request.head.repo.full_name }}
|
|
ref: ${{ github.event.pull_request.head.sha }}
|
|
path: .bundle-size-pr
|
|
|
|
- name: Setup pnpm
|
|
uses: pnpm/action-setup@v6.1.0
|
|
|
|
- name: Setup Node.js
|
|
uses: actions/setup-node@v5
|
|
with:
|
|
node-version-file: '.bundle-size-pr/.nvmrc'
|
|
cache: pnpm
|
|
cache-dependency-path: |
|
|
pnpm-lock.yaml
|
|
.bundle-size-pr/pnpm-lock.yaml
|
|
|
|
- name: Install dependencies
|
|
run: pnpm install
|
|
|
|
- name: Restore Vite Task cache
|
|
uses: actions/cache/restore@v6
|
|
with:
|
|
path: node_modules/.vite/task-cache
|
|
key: vite-task-${{ runner.os }}-${{ runner.arch }}-restore-only-${{ github.run_id }}-${{ github.run_attempt }}-${{ github.job }}
|
|
restore-keys: |
|
|
vite-task-${{ runner.os }}-${{ runner.arch }}-packages-
|
|
|
|
- name: Build and measure base
|
|
run: |
|
|
if [ -f .bundle-size-pr/.github/scripts/bundle-size.js ]; then
|
|
pnpm --dir .bundle-size-pr --fail-if-no-match install --frozen-lockfile --ignore-scripts --filter @videojs/monorepo
|
|
pnpm build:packages
|
|
node .bundle-size-pr/.github/scripts/bundle-size.js --root . --json base-size.json
|
|
else
|
|
echo '[]' > base-size.json
|
|
fi
|
|
|
|
- name: Upload size data
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: base-size
|
|
path: base-size.json
|
|
|
|
report:
|
|
runs-on: blacksmith-2vcpu-ubuntu-2404
|
|
needs: [pr-size, base-size]
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v5
|
|
with:
|
|
ref: ${{ github.event.pull_request.head.sha }}
|
|
|
|
- name: Download size data
|
|
uses: actions/download-artifact@v4
|
|
with:
|
|
path: artifacts
|
|
|
|
- name: Generate report
|
|
run: >
|
|
node .github/scripts/bundle-size-report.js
|
|
--pr artifacts/pr-size/pr-size.json
|
|
--base artifacts/base-size/base-size.json
|
|
> report.md
|
|
|
|
- name: Publish summary
|
|
run: cat report.md >> "$GITHUB_STEP_SUMMARY"
|
|
|
|
- name: Post comment
|
|
# The default token is read-only on fork pull requests, so the comment
|
|
# can only be posted when the branch lives in this repository.
|
|
if: github.event.pull_request.head.repo.full_name == github.repository
|
|
uses: actions/github-script@v7
|
|
with:
|
|
script: |
|
|
const fs = require('fs');
|
|
const body = fs.readFileSync('report.md', 'utf8');
|
|
const marker = '<!-- bundle-size-report -->';
|
|
|
|
const { data: comments } = await github.rest.issues.listComments({
|
|
owner: context.repo.owner,
|
|
repo: context.repo.repo,
|
|
issue_number: context.issue.number,
|
|
});
|
|
|
|
const existing = comments.find(c => c.body?.startsWith(marker));
|
|
|
|
if (existing) {
|
|
await github.rest.issues.updateComment({
|
|
owner: context.repo.owner,
|
|
repo: context.repo.repo,
|
|
comment_id: existing.id,
|
|
body,
|
|
});
|
|
} else {
|
|
await github.rest.issues.createComment({
|
|
owner: context.repo.owner,
|
|
repo: context.repo.repo,
|
|
issue_number: context.issue.number,
|
|
body,
|
|
});
|
|
}
|
|
|
|
# Runs after the report is posted, so an over-budget PR still shows its sizes.
|
|
# Budgets live in .github/scripts/bundle-size-budget.js.
|
|
- name: Check size budgets
|
|
run: node .github/scripts/bundle-size-budget.js artifacts/pr-size/pr-size.json
|