name: Packaging 📦

on:
  workflow_call:
    inputs:
      commit:
        required: false
        type: string

jobs:
  run-build-prod:
    name: Run production build 🏗️
    runs-on: ubuntu-latest

    steps:
      - name: Check out Git repository
        uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
        with:
          ref: ${{ inputs.commit || github.sha }}

      - name: Setup node environment
        uses: actions/setup-node@249970729cb0ef3589644e2896645e5dc5ba9c38 # v6.5.0
        with:
          node-version-file: .nvmrc
          cache: npm
          check-latest: true

      - name: Install Node.js dependencies
        run: npm ci --no-audit

      - name: Run a production build
        env:
          JELLYFIN_VERSION: ${{ inputs.commit || github.sha }}
        run: npm run build:production

      - name: Update config.json for testing
        run: |
          jq '.multiserver=true | .servers=["https://demo.jellyfin.org/unstable"]' dist/config.json > dist/config.tmp.json
          mv dist/config.tmp.json dist/config.json

      - name: Upload artifact
        uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
        with:
          name: frontend
          path: dist
          if-no-files-found: error
