-
-
Notifications
You must be signed in to change notification settings - Fork 205
109 lines (92 loc) · 3.26 KB
/
nextjs_bundle_analysis.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# Copyright (c) HashiCorp, Inc.
# SPDX-License-Identifier: MPL-2.0
name: 'Next.js Bundle Analysis'
on:
push:
branches: [master]
pull_request:
branches: [master]
types: [opened, synchronize]
paths-ignore:
- 'tools/bumblebee/**'
defaults:
run:
# change this if your nextjs app does not live at the root of the repo
working-directory: ./
permissions:
contents: read # for checkout repository
actions: read # for fetching base branch bundle stats
pull-requests: write # for comments
jobs:
analyze:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install Node.js
uses: actions/setup-node@v3
with:
node-version: 20
- name: Install dependencies
uses: bahmutov/npm-install@v1
- name: Restore next build
uses: actions/cache@v3
id: restore-build-cache
env:
cache-name: cache-next-build
with:
path: client/.next/cache
key: ${{ runner.os }}-build-${{ env.cache-name }}
- name: Build next.js app
working-directory: client
env:
NODE_ENV: production
run: npm run build
- name: Analyze bundle
run: npx -p nextjs-bundle-analysis report
working-directory: client
- name: Upload bundle
uses: actions/upload-artifact@v3
with:
name: bundle
path: client/.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: client/.next/analyze/base
- name: Compare with base branch bundle
if: success() && github.event.number
working-directory: client
run: ls -laR .next/analyze/base && npx -p nextjs-bundle-analysis compare
- name: Get Comment Body
id: get-comment-body
if: success() && github.event.number
working-directory: client
# https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#multiline-strings
run: |
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