name: Build pull request

on:
  pull_request:
    types: ['opened', 'synchronize']

jobs:
  build-pull-request:
    name: Build pull request
    runs-on: ubuntu-latest
    env:
      PR_NUMBER: ${{github.event.number}}
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4.2.0
      - name: Setup node
        uses: actions/setup-node@v4.0.4
        with:
          node-version: 20.12.2
          cache: 'npm'
      - name: Install dependencies
        run: npm ci
      - name: Build app
        env:
          NODE_OPTIONS: '--max_old_space_size=4096'
        run: npm run build
      - name: Upload artifact
        uses: actions/upload-artifact@v4.6.0
        with:
          name: preview
          path: dist
          retention-days: 1
      - name: Save pr number
        run: echo ${PR_NUMBER} > ./pr.txt
      - name: Upload pr number
        uses: actions/upload-artifact@v4.6.0
        with:
          name: pr
          path: ./pr.txt
          retention-days: 1
