name: Build

on: [workflow_call]

jobs:
  build-wheel:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4
      with:
        fetch-depth: 0

    - uses: actions/setup-node@v4
      with:
        node-version: lts/*

    - uses: actions/setup-python@v5
      with:
        python-version: 3.13

    - name: Install npm dependencies
      run: npm ci

    - name: Install tox
      run: python -m pip install --upgrade tox==4.23.2 tox-uv~=1.16.0

    - name: Build docs
      run: tox run -e docs

    - name: Build UI
      run: npm run build
      env:
        CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

    - name: Build python app
      run: tox run -e build

    - name: Require non dirty git workspace
      run: |
        CHANGES=$(git status --porcelain)
        if [[ -n "$CHANGES" ]]; then
          echo "❌ Workspace is dirty. The following files have been modified:"
          echo "$CHANGES"
          exit 1
        else
          echo "✅ Workspace is clean."
        fi

    - name: Upload rollup visualizer result
      uses: actions/upload-artifact@v4
      with:
        name: rollup-visualizer
        path: reports/bundle-report.html

    - name: Upload python artifacts
      uses: actions/upload-artifact@v4
      with:
        name: dist
        path: dist/*

    - name: Upload docs
      uses: actions/upload-artifact@v4
      with:
        name: docs
        path: src/vdoc/docs/*
