name: PR Preview Build

on:
  pull_request:
    types: [opened, synchronize, reopened]
    paths-ignore:
      - 'docs/wiki/**'

permissions:
  contents: read

jobs:
  build-preview:
    runs-on: ubuntu-latest

    steps:
      - name: Check out Git repository
        uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
        with:
          persist-credentials: false

      - name: Setup Node.js
        uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
        with:
          node-version: 22
          cache: 'npm'

      # work around for npm installs from git+https://github.com/johannesjo/J2M.git
      - name: Reconfigure git to use HTTP authentication
        run: >
          git config --global url."https://github.com/".insteadOf
          ssh://git@github.com/

      - name: Install npm Packages
        run: npm i

      - name: Generate environment file
        run: npm run env

      - name: Build Frontend for Web
        run: npm run buildFrontend:prodWeb

      - name: Upload build artifact
        uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
        with:
          name: pr-preview-build
          path: dist/browser
          retention-days: 1
