name: 📦 Package Size Report

on:
  pull_request:
    branches:
      - 'master'
    types: [opened, synchronize]

jobs:
  size-report:
    runs-on: ubuntu-latest

    env:
      CI_JOB_NUMBER: 1

    steps:
      - uses: actions/checkout@v4

      - name: Setup pnpm
        uses: pnpm/action-setup@v4

      - name: Setup node
        uses: actions/setup-node@v4
        with:
          node-version: 20

      - name: Get pnpm store directory
        id: pnpm-cache
        run: |
          echo "pnpm_cache_dir=$(pnpm store path)" >> $GITHUB_OUTPUT

      - uses: actions/cache@v4
        name: Setup pnpm cache
        with:
          path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }}
          key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
          restore-keys: |
            ${{ runner.os }}-pnpm-store-

      - uses: preactjs/compressed-size-action@v2
        with:
          repo-token: ${{ secrets.GITHUB_TOKEN }}
          pattern: './dist/element-plus/dist/*.{js,mjs,css}'
        env:
          NODE_OPTIONS: --max-old-space-size=4096
