Skip to content

Commit

Permalink
Merge pull request #59 from Southclaws/next-bundle-analysis
Browse files Browse the repository at this point in the history
try nextjs bundle analysis
  • Loading branch information
Southclaws authored Dec 28, 2023
2 parents 22e8849 + ca793b1 commit 79ffa62
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 0 deletions.
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
}
}

2 comments on commit 79ffa62

@vercel
Copy link

@vercel vercel bot commented on 79ffa62 Dec 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 79ffa62 Dec 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.