From 0cce3aa1ee6eece17f85db2a08a1d6f3ebeefa1d Mon Sep 17 00:00:00 2001 From: Claudio Wunder Date: Sun, 9 Jul 2023 16:01:08 +0000 Subject: [PATCH 1/5] chore: attempt to create a bundle analysis file --- .github/workflows/pull-request.yml | 91 ++++++++++++++++++++++++------ 1 file changed, 73 insertions(+), 18 deletions(-) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 3426b022634f9..970a8e221900e 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -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 @@ -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 }} @@ -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 }} @@ -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: @@ -170,3 +170,58 @@ jobs: .next/cache node_modules/.cache key: cache-${{ hashFiles('package-lock.json') }} + + analysis: + name: Analysis + runs-on: ubuntu-latest + needs: build + + steps: + - name: Download PR Bundle Analysis + uses: actions/download-artifact@v3 + with: + name: bundle-analysis + + - name: Download Base Bundle Analysis + uses: dawidd6/action-download-artifact@v2 + if: success() && github.event.number + with: + workflow: pull-request.yml + branch: ${{ github.event.pull_request.base.ref }} + path: .next/analyze/base + + - 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<> $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: '' + + - 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 From 92773802a1df922765ecd54b430cdd17ce53c37b Mon Sep 17 00:00:00 2001 From: Claudio Wunder Date: Sun, 9 Jul 2023 16:17:29 +0000 Subject: [PATCH 2/5] chore: attempt to have a fallback file --- .github/workflows/pull-request.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 970a8e221900e..92f4d5d88a535 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -181,12 +181,16 @@ jobs: uses: actions/download-artifact@v3 with: name: bundle-analysis + path: .next/analyze/base + + - name: Copy PR Bundle Analysis (Fallback) + run: cp .next/analyze/base/__bundle_analysis.json .next/analyze/__bundle_analysis.json - name: Download Base Bundle Analysis uses: dawidd6/action-download-artifact@v2 if: success() && github.event.number with: - workflow: pull-request.yml + name: bundle-analysis branch: ${{ github.event.pull_request.base.ref }} path: .next/analyze/base From 1d53c2e91b106accf30a8d0c74d472bb2b6fc54b Mon Sep 17 00:00:00 2001 From: Claudio Wunder Date: Sun, 9 Jul 2023 16:21:22 +0000 Subject: [PATCH 3/5] chore: mention if no artifact found --- .github/workflows/pull-request.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 92f4d5d88a535..36007a0db3359 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -193,6 +193,7 @@ jobs: name: bundle-analysis branch: ${{ github.event.pull_request.base.ref }} path: .next/analyze/base + if_no_artifact_found: warn - name: Compare with base branch bundle if: success() && github.event.number From 9bc02861acefb74dbd84b6d8c78d33cb3434e355 Mon Sep 17 00:00:00 2001 From: Claudio Wunder Date: Sun, 9 Jul 2023 16:24:54 +0000 Subject: [PATCH 4/5] chore: git checkout and restore cache --- .github/workflows/pull-request.yml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 36007a0db3359..b34a233c57641 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -177,6 +177,19 @@ jobs: 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: From 9c3902ebb5433b8384836d283740e424d51756ae Mon Sep 17 00:00:00 2001 From: Claudio Wunder Date: Sun, 9 Jul 2023 16:56:06 +0000 Subject: [PATCH 5/5] chore: separate analysis step --- .github/workflows/pull-request.yml | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index b34a233c57641..3563c63f4b54f 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -41,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 @@ -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 @@ -143,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 @@ -194,10 +194,12 @@ jobs: uses: actions/download-artifact@v3 with: name: bundle-analysis - path: .next/analyze/base + path: .next/analyze - name: Copy PR Bundle Analysis (Fallback) - run: cp .next/analyze/base/__bundle_analysis.json .next/analyze/__bundle_analysis.json + 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 @@ -205,7 +207,7 @@ jobs: with: name: bundle-analysis branch: ${{ github.event.pull_request.base.ref }} - path: .next/analyze/base + path: .next/analyze/base/bundle if_no_artifact_found: warn - name: Compare with base branch bundle