name: CI

on:
  workflow_dispatch:

permissions:
  contents: read

jobs:
  rust:
    name: Rust workspace
    runs-on: macos-15
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Use pinned Rust toolchain
        run: rustup show

      - name: Check formatting
        run: cargo fmt --all --check

      - name: Check workspace
        run: cargo check --workspace --all-targets

      - name: Lint workspace
        run: cargo clippy --workspace --all-targets -- -D warnings

      - name: Test workspace
        run: cargo test --workspace --all-targets

      - name: Check Servo engine host
        run: cargo check -p ely_servo_host --features servo-engine --all-targets

      - name: Lint Servo engine host
        run: cargo clippy -p ely_servo_host --features servo-engine --all-targets -- -D warnings

      - name: Test Servo engine host
        run: cargo test -p ely_servo_host --features servo-engine --test software_host

      - name: Test PRD site compatibility
        run: scripts/verify_prd_site_rendering.sh

      - name: Audit source file size
        run: scripts/audit_source_lines.sh

      - name: Verify macOS bundle metadata
        run: scripts/verify_macos_bundle_metadata.sh

      - name: Verify Linux desktop metadata
        run: scripts/verify_linux_desktop_metadata.sh

      - name: Verify Windows app manifest metadata
        run: scripts/verify_windows_app_manifest.sh

      - name: Build macOS app bundle
        run: scripts/create_macos_app_bundle.sh

      - name: Verify built macOS app bundle metadata
        run: scripts/verify_macos_bundle_metadata.sh "target/macos/ELY Browser.app/Contents/Info.plist"

  cloudflare:
    name: Cloudflare worker
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Use Node
        uses: actions/setup-node@v5
        with:
          node-version: 24
          cache: npm
          cache-dependency-path: cloudflare/package-lock.json

      - name: Install dependencies
        run: npm ci
        working-directory: cloudflare

      - name: Check worker types
        run: npm run check
        working-directory: cloudflare

      - name: Test worker contracts
        run: npm test
        working-directory: cloudflare
