name: Build Artifacts

# Only runs on manual trigger or when preparing a release
on:
  workflow_dispatch:
    inputs:
      reason:
        description: "Reason for build"
        required: false
        default: "Manual build"

jobs:
  # ── Python wheel + sdist ────────────────────────────────────────
  build-python:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: "3.12"

      - name: Install build tools
        run: pip install build hatchling

      - name: Build package
        run: python -m build

      - name: Upload Python dist
        uses: actions/upload-artifact@v4
        with:
          name: dist-python
          path: dist/
          retention-days: 30

  # ── VS Code extension VSIX ─────────────────────────────────────
  build-extension:
    runs-on: ubuntu-latest
    defaults:
      run:
        working-directory: extension
    steps:
      - uses: actions/checkout@v4

      - name: Set up Node.js
        uses: actions/setup-node@v4
        with:
          node-version: 20

      - name: Install dependencies
        run: npm ci

      - name: Build extension
        run: npm run package

      - name: Package VSIX
        run: npx @vscode/vsce package --no-dependencies -o mcp-grid.vsix

      - name: Upload VSIX
        uses: actions/upload-artifact@v4
        with:
          name: dist-vsix
          path: extension/mcp-grid.vsix
          retention-days: 30
