|
| 1 | +name: Analyze Bundle |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + push: |
| 6 | + branches: |
| 7 | + - main # change this if your default branch is named differently |
| 8 | + workflow_dispatch: |
| 9 | + |
| 10 | +jobs: |
| 11 | + analyze: |
| 12 | + runs-on: ubuntu-latest |
| 13 | + steps: |
| 14 | + - uses: actions/checkout@v2 |
| 15 | + |
| 16 | + - name: Set up node |
| 17 | + uses: actions/setup-node@v1 |
| 18 | + with: |
| 19 | + node-version: "14.x" |
| 20 | + |
| 21 | + - name: Install dependencies |
| 22 | + uses: bahmutov/npm-install@v1.6.0 |
| 23 | + with: |
| 24 | + working-directory: 'beta' |
| 25 | + |
| 26 | + - name: Restore next build |
| 27 | + uses: actions/cache@v2 |
| 28 | + id: restore-build-cache |
| 29 | + env: |
| 30 | + cache-name: cache-next-build |
| 31 | + with: |
| 32 | + path: beta/.next/cache |
| 33 | + # change this if you prefer a more strict cache |
| 34 | + key: ${{ runner.os }}-build-${{ env.cache-name }} |
| 35 | + |
| 36 | + - name: Build next.js app |
| 37 | + # change this if your site requires a custom build command |
| 38 | + run: ./node_modules/.bin/next build |
| 39 | + working-directory: beta |
| 40 | + |
| 41 | + # Here's the first place where next-bundle-analysis' own script is used |
| 42 | + # This step pulls the raw bundle stats for the current bundle |
| 43 | + - name: Analyze bundle |
| 44 | + run: npx -p nextjs-bundle-analysis report |
| 45 | + working-directory: beta |
| 46 | + |
| 47 | + - name: Upload bundle |
| 48 | + uses: actions/upload-artifact@v2 |
| 49 | + with: |
| 50 | + path: beta/.next/analyze/__bundle_analysis.json |
| 51 | + name: bundle_analysis.json |
| 52 | + |
| 53 | + - name: Download base branch bundle stats |
| 54 | + uses: dawidd6/action-download-artifact@v2 |
| 55 | + if: success() && github.event.number |
| 56 | + with: |
| 57 | + workflow: bundle_analysis_upload.yml |
| 58 | + branch: ${{ github.event.pull_request.base.ref }} |
| 59 | + name: bundle_analysis.json |
| 60 | + path: beta/.next/analyze/base/bundle |
| 61 | + |
| 62 | + # And here's the second place - this runs after we have both the current and |
| 63 | + # base branch bundle stats, and will compare them to determine what changed. |
| 64 | + # There are two configurable arguments that come from package.json: |
| 65 | + # |
| 66 | + # - budget: optional, set a budget (bytes) against which size changes are measured |
| 67 | + # it's set to 350kb here by default, as informed by the following piece: |
| 68 | + # https://infrequently.org/2021/03/the-performance-inequality-gap/ |
| 69 | + # |
| 70 | + # - red-status-percentage: sets the percent size increase where you get a red |
| 71 | + # status indicator, defaults to 20% |
| 72 | + # |
| 73 | + # Either of these arguments can be changed or removed by editing the `nextBundleAnalysis` |
| 74 | + # entry in your package.json file. |
| 75 | + - name: Compare with base branch bundle |
| 76 | + if: success() && github.event.number |
| 77 | + run: ls -laR .next/analyze/base && npx -p nextjs-bundle-analysis compare |
| 78 | + working-directory: beta |
| 79 | + |
| 80 | + - name: Upload analysis comment |
| 81 | + uses: actions/upload-artifact@v2 |
| 82 | + with: |
| 83 | + name: analysis_comment.txt |
| 84 | + path: beta/.next/analyze/__bundle_analysis_comment.txt |
| 85 | + |
| 86 | + - name: Save PR number |
| 87 | + run: echo ${{ github.event.number }} > ./pr_number |
| 88 | + |
| 89 | + - name: Upload PR number |
| 90 | + uses: actions/upload-artifact@v2 |
| 91 | + with: |
| 92 | + name: pr_number |
| 93 | + path: ./pr_number |
| 94 | + |
| 95 | + # The actual commenting happens in the other action, matching the guidance in |
| 96 | + # https://securitylab.github.com/research/github-actions-preventing-pwn-requests/ |
0 commit comments