Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

try nextjs bundle analysis #59

Merged
merged 5 commits into from
Dec 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 105 additions & 0 deletions .github/workflows/nextjs_bundle_analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
# Copyright (c) HashiCorp, Inc.
# SPDX-License-Identifier: MPL-2.0

name: "Next.js Bundle Analysis"

on:
pull_request:
push:
branches:
- main
workflow_dispatch:

permissions:
contents: read
actions: read
pull-requests: write

jobs:
analyze:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Install Node.js
uses: actions/setup-node@v3
with:
node-version: 18

- name: Install dependencies
uses: bahmutov/npm-install@v1
with:
working-directory: web

- name: Restore next build
uses: actions/cache@v3
id: restore-build-cache
env:
cache-name: cache-next-build
with:
path: web/.next/cache
key: ${{ runner.os }}-build-${{ env.cache-name }}

- name: Build next.js app
run: |
cd web
./node_modules/.bin/next experimental-compile

- name: Analyze bundle
run: |
cd web
npx -p nextjs-bundle-analysis report

- name: Upload bundle
uses: actions/upload-artifact@v3
with:
name: bundle
path: web/.next/analyze/__bundle_analysis.json

- name: Download base branch bundle stats
uses: dawidd6/action-download-artifact@v2
if: success() && github.event.number
with:
workflow: nextjs_bundle_analysis.yml
branch: ${{ github.event.pull_request.base.ref }}
path: web/.next/analyze/base

- name: Compare with base branch bundle
if: success() && github.event.number
run: |
cd web
ls -laR .next/analyze/base && npx -p nextjs-bundle-analysis compare

- name: Get Comment Body
id: get-comment-body
if: success() && github.event.number
# https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#multiline-strings
run: |
cd web
echo "body<<EOF" >> $GITHUB_OUTPUT
echo "$(cat .next/analyze/__bundle_analysis_comment.txt)" >> $GITHUB_OUTPUT
echo EOF >> $GITHUB_OUTPUT

- name: Find Comment
uses: peter-evans/find-comment@v2
if: success() && github.event.number
id: fc
with:
issue-number: ${{ github.event.number }}
body-includes: "<!-- __NEXTJS_BUNDLE -->"

- name: Create Comment
uses: peter-evans/create-or-update-comment@v2
if: success() && github.event.number && steps.fc.outputs.comment-id == 0
with:
issue-number: ${{ github.event.number }}
body: ${{ steps.get-comment-body.outputs.body }}

- name: Update Comment
uses: peter-evans/create-or-update-comment@v2
if: success() && github.event.number && steps.fc.outputs.comment-id != 0
with:
issue-number: ${{ github.event.number }}
body: ${{ steps.get-comment-body.outputs.body }}
comment-id: ${{ steps.fc.outputs.comment-id }}
edit-mode: replace
6 changes: 6 additions & 0 deletions web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,11 @@
},
"resolutions": {
"@ark-ui/react": "^1.2.1"
},
"nextBundleAnalysis": {
"budget": 358400,
"budgetPercentIncreaseRed": 20,
"minimumChangeThreshold": 0,
"showDetails": true
}
}
Loading