Skip to content
Merged
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
117 changes: 96 additions & 21 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ on:
pull_request:
workflow_dispatch:

defaults:
run:
working-directory: ./

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

jobs:
lint:
name: Lint
Expand Down Expand Up @@ -32,7 +41,7 @@ jobs:
cache: 'npm'

- name: Install NPM packages
run: npm ci
run: npm ci --no-audit --no-fund

- name: Run Linting
run: npx turbo lint
Expand All @@ -46,15 +55,6 @@ jobs:
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: ${{ secrets.TURBO_TEAM }}

- name: Save Cache
uses: actions/cache/save@v3
with:
path: |
~/.npm
.next/cache
node_modules/.cache
key: cache-${{ hashFiles('package-lock.json') }}

unit-tests:
name: Tests on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
Expand Down Expand Up @@ -92,7 +92,7 @@ jobs:
cache: 'npm'

- name: Install NPM packages
run: npm ci
run: npm ci --no-audit --no-fund

- name: Run Unit Tests
run: npx turbo test:unit -- --coverage
Expand All @@ -106,15 +106,6 @@ jobs:
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: ${{ secrets.TURBO_TEAM }}

- name: Save Cache
uses: actions/cache/save@v3
with:
path: |
~/.npm
.next/cache
node_modules/.cache
key: cache-${{ hashFiles('package-lock.json') }}

build:
name: Build on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
Expand Down Expand Up @@ -152,7 +143,7 @@ jobs:
cache: 'npm'

- name: Install NPM packages
run: npm ci --omit=dev
run: npm ci --no-audit --no-fund --omit=dev

- name: Build Next.js
run: npx turbo build
Expand All @@ -162,6 +153,15 @@ jobs:
NODE_OPTIONS: '--max_old_space_size=4096'
NEXT_TELEMETRY_DISABLED: 1

- name: Analyse Build
run: npx -p nextjs-bundle-analysis report

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

- name: Save Cache
uses: actions/cache/save@v3
with:
Expand All @@ -170,3 +170,78 @@ jobs:
.next/cache
node_modules/.cache
key: cache-${{ hashFiles('package-lock.json') }}

analysis:
name: Analysis
runs-on: ubuntu-latest
needs: build

steps:
- name: Git Checkout
uses: actions/checkout@v3

- name: Restore Cache
uses: actions/cache/restore@v3
with:
path: |
~/.npm
.next/cache
node_modules/.cache
key: cache-${{ hashFiles('package-lock.json') }}-
restore-keys: cache-

- name: Download PR Bundle Analysis
uses: actions/download-artifact@v3
with:
name: bundle-analysis
path: .next/analyze

- name: Copy PR Bundle Analysis (Fallback)
run: |
mkdir -p .next/analyze/base/bundle/
cp .next/analyze/__bundle_analysis.json .next/analyze/base/bundle/__bundle_analysis.json

- name: Download Base Bundle Analysis
uses: dawidd6/action-download-artifact@v2
if: success() && github.event.number
with:
name: bundle-analysis
branch: ${{ github.event.pull_request.base.ref }}
path: .next/analyze/base/bundle
if_no_artifact_found: warn

- name: Compare with base branch bundle
if: success() && github.event.number
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
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: find-comment-id
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.find-comment-id.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.find-comment-id.outputs.comment-id != 0
with:
issue-number: ${{ github.event.number }}
body: ${{ steps.get-comment-body.outputs.body }}
comment-id: ${{ steps.find-comment-id.outputs.comment-id }}
edit-mode: replace