@@ -11,6 +11,7 @@ defaults:
1111permissions :
1212 contents : read
1313 actions : read
14+ pull-requests : write
1415
1516jobs :
1617 lint :
@@ -104,3 +105,143 @@ jobs:
104105 env :
105106 TURBO_TOKEN : ${{ secrets.TURBO_TOKEN }}
106107 TURBO_TEAM : ${{ secrets.TURBO_TEAM }}
108+
109+ build :
110+ name : Build on ${{ matrix.os }}
111+ runs-on : ${{ matrix.os }}
112+
113+ strategy :
114+ fail-fast : false
115+ matrix :
116+ os : [ubuntu-latest, windows-latest]
117+
118+ steps :
119+ - name : ' Use GNU tar instead BSD tar'
120+ if : matrix.os == 'windows-latest'
121+ shell : cmd
122+ run : echo C:\Program Files\Git\usr\bin>>"%GITHUB_PATH%"
123+
124+ - name : Git Checkout
125+ uses : actions/checkout@v3
126+ with :
127+ fetch-depth : 2
128+
129+ - name : Restore Cache
130+ uses : actions/cache/restore@v3
131+ with :
132+ path : |
133+ ~/.npm
134+ .next/cache
135+ node_modules/.cache
136+ key : cache-${{ hashFiles('package-lock.json') }}-
137+ restore-keys : cache-
138+
139+ - name : Set up Node.js
140+ uses : actions/setup-node@v3
141+ with :
142+ node-version-file : ' .nvmrc'
143+ cache : ' npm'
144+
145+ - name : Install NPM packages
146+ run : npm ci --no-audit --no-fund --omit=dev
147+
148+ - name : Build Next.js
149+ run : npx turbo build
150+ env :
151+ TURBO_TOKEN : ${{ secrets.TURBO_TOKEN }}
152+ TURBO_TEAM : ${{ secrets.TURBO_TEAM }}
153+ NODE_OPTIONS : ' --max_old_space_size=4096'
154+ NEXT_TELEMETRY_DISABLED : 1
155+
156+ - name : Analyse Build
157+ run : npx -p nextjs-bundle-analysis report
158+
159+ - name : Upload Build Analysis
160+ uses : actions/upload-artifact@v3
161+ with :
162+ name : bundle-analysis
163+ path : .next/analyze/__bundle_analysis.json
164+
165+ - name : Save Cache
166+ uses : actions/cache/save@v3
167+ with :
168+ path : |
169+ ~/.npm
170+ .next/cache
171+ node_modules/.cache
172+ key : cache-${{ hashFiles('package-lock.json') }}
173+
174+ analysis :
175+ name : Analysis
176+ runs-on : ubuntu-latest
177+ needs : build
178+
179+ steps :
180+ - name : Git Checkout
181+ uses : actions/checkout@v3
182+
183+ - name : Restore Cache
184+ uses : actions/cache/restore@v3
185+ with :
186+ path : |
187+ ~/.npm
188+ .next/cache
189+ node_modules/.cache
190+ key : cache-${{ hashFiles('package-lock.json') }}-
191+ restore-keys : cache-
192+
193+ - name : Download PR Bundle Analysis
194+ uses : actions/download-artifact@v3
195+ with :
196+ name : bundle-analysis
197+ path : .next/analyze
198+
199+ - name : Copy PR Bundle Analysis (Fallback)
200+ run : |
201+ mkdir -p .next/analyze/base/bundle/
202+ cp .next/analyze/__bundle_analysis.json .next/analyze/base/bundle/__bundle_analysis.json
203+
204+ - name : Download Base Bundle Analysis
205+ uses : dawidd6/action-download-artifact@v2
206+ if : success() && github.event.number
207+ with :
208+ name : bundle-analysis
209+ branch : ${{ github.event.pull_request.base.ref }}
210+ path : .next/analyze/base/bundle
211+ if_no_artifact_found : warn
212+
213+ - name : Compare with base branch bundle
214+ if : success() && github.event.number
215+ run : ls -laR .next/analyze/base && npx -p nextjs-bundle-analysis compare
216+
217+ - name : Get Comment Body
218+ id : get-comment-body
219+ if : success() && github.event.number
220+ run : |
221+ echo "body<<EOF" >> $GITHUB_OUTPUT
222+ echo "$(cat .next/analyze/__bundle_analysis_comment.txt)" >> $GITHUB_OUTPUT
223+ echo EOF >> $GITHUB_OUTPUT
224+
225+ - name : Find Comment
226+ uses : peter-evans/find-comment@v2
227+ if : success() && github.event.number
228+ id : find-comment-id
229+ with :
230+ issue-number : ${{ github.event.number }}
231+ body-includes : ' <!-- __NEXTJS_BUNDLE -->'
232+
233+ - name : Create Comment
234+ uses : peter-evans/create-or-update-comment@v2
235+ if : success() && github.event.number && steps.find-comment-id.outputs.comment-id == 0
236+ with :
237+ issue-number : ${{ github.event.number }}
238+ body : ${{ steps.get-comment-body.outputs.body }}
239+
240+ - name : Update Comment
241+ uses : peter-evans/create-or-update-comment@v2
242+ if : success() && github.event.number && steps.find-comment-id.outputs.comment-id != 0
243+ with :
244+ issue-number : ${{ github.event.number }}
245+ body : ${{ steps.get-comment-body.outputs.body }}
246+ comment-id : ${{ steps.find-comment-id.outputs.comment-id }}
247+ edit-mode : replace
0 commit comments