|
| 1 | +on: |
| 2 | + pull_request: |
| 3 | + pull_request_target: |
| 4 | + |
| 5 | +jobs: |
| 6 | + # Build and upload stats for `head` |
| 7 | + build: |
| 8 | + name: 'Build and upload for ${{ matrix.target }}' |
| 9 | + runs-on: ubuntu-latest |
| 10 | + permissions: |
| 11 | + contents: read |
| 12 | + strategy: |
| 13 | + matrix: |
| 14 | + target: [browser, node] # Runs for both browser and node bundles |
| 15 | + steps: |
| 16 | + - uses: actions/checkout@v4 |
| 17 | + with: |
| 18 | + ref: ${{ github.event.pull_request.head.ref }} |
| 19 | + - name: Setup pnpm |
| 20 | + uses: .github/actions/setup-pnpm |
| 21 | + - name: Install dependencies |
| 22 | + run: pnpm install --frozen-lockfile |
| 23 | + - name: Build |
| 24 | + run: pnpm build:clean |
| 25 | + env: |
| 26 | + NODE_ENV: production |
| 27 | + - name: Upload stats.json |
| 28 | + uses: actions/upload-artifact@v4 |
| 29 | + with: |
| 30 | + name: head-stats-${{ matrix.target }} |
| 31 | + path: .stats/bundle.${{ matrix.target }}.json |
| 32 | + |
| 33 | + # Build base stats for comparison |
| 34 | + build-base: |
| 35 | + name: 'Build base and upload for ${{ matrix.target }}' |
| 36 | + runs-on: ubuntu-latest |
| 37 | + permissions: |
| 38 | + contents: read |
| 39 | + strategy: |
| 40 | + matrix: |
| 41 | + target: [browser, node] |
| 42 | + steps: |
| 43 | + - uses: actions/checkout@v4 |
| 44 | + with: |
| 45 | + ref: ${{ github.base_ref }} |
| 46 | + - name: Setup pnpm |
| 47 | + uses: .github/actions/setup-pnpm |
| 48 | + - name: Install dependencies |
| 49 | + run: pnpm install --frozen-lockfile |
| 50 | + - name: Build |
| 51 | + run: pnpm build:clean |
| 52 | + env: |
| 53 | + NODE_ENV: production |
| 54 | + - name: Upload stats.json |
| 55 | + uses: actions/upload-artifact@v4 |
| 56 | + with: |
| 57 | + name: base-stats-${{ matrix.target }} |
| 58 | + path: .stats/bundle.${{ matrix.target }}.json |
| 59 | + |
| 60 | + # Compare base and head stats.json files |
| 61 | + compare: |
| 62 | + name: 'Compare base & head bundle sizes for ${{ matrix.target }}' |
| 63 | + runs-on: ubuntu-latest |
| 64 | + needs: [build, build-base] |
| 65 | + permissions: |
| 66 | + pull-requests: write |
| 67 | + strategy: |
| 68 | + matrix: |
| 69 | + target: [browser, node] |
| 70 | + steps: |
| 71 | + - uses: actions/download-artifact@v4 |
| 72 | + with: |
| 73 | + name: head-stats-${{ matrix.target }} |
| 74 | + - uses: actions/download-artifact@v4 |
| 75 | + with: |
| 76 | + name: base-stats-${{ matrix.target }} |
| 77 | + - uses: twk3/rollup-size-compare-action@v1.0.0 |
| 78 | + with: |
| 79 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 80 | + current-stats-json-path: ./head-stats-${{ matrix.target }}/bundle.${{ matrix.target }}.json |
| 81 | + base-stats-json-path: ./base-stats-${{ matrix.target }}/bundle.${{ matrix.target }}.json |
0 commit comments