name: Imaging and meshing gate

on:
  push:
    paths:
      - ".gitea/workflows/imaging-meshing.yml"
      - "Cargo.toml"
      - "Cargo.lock"
      - "crates/libremetaverse/Cargo.toml"
      - "crates/libremetaverse/src/generated.rs"
      - "crates/libremetaverse/src/skeleton.rs"
      - "crates/libremetaverse/src/*_catalog.rs"
      - "crates/libremetaverse-types/**"
      - "crates/libremetaverse-imaging/**"
      - "crates/libremetaverse-imaging-skia/**"
      - "crates/libremetaverse-prim-mesher/**"
      - "crates/libremetaverse-rendering-mesh-foundry/**"
      - "tests/compat/Cargo.toml"
      - "tests/compat/build.rs"
      - "tests/compat/src/**"
      - "tests/compat/tests/imaging_meshing_semantics.rs"
      - "tests/upstream-tests.json"
      - "tools/check_milestone_06.py"
      - "tools/install_openjpeg_2_5_4.sh"
  pull_request:
    paths:
      - ".gitea/workflows/imaging-meshing.yml"
      - "Cargo.toml"
      - "Cargo.lock"
      - "crates/libremetaverse/Cargo.toml"
      - "crates/libremetaverse/src/generated.rs"
      - "crates/libremetaverse/src/skeleton.rs"
      - "crates/libremetaverse/src/*_catalog.rs"
      - "crates/libremetaverse-types/**"
      - "crates/libremetaverse-imaging/**"
      - "crates/libremetaverse-imaging-skia/**"
      - "crates/libremetaverse-prim-mesher/**"
      - "crates/libremetaverse-rendering-mesh-foundry/**"
      - "tests/compat/Cargo.toml"
      - "tests/compat/build.rs"
      - "tests/compat/src/**"
      - "tests/compat/tests/imaging_meshing_semantics.rs"
      - "tests/upstream-tests.json"
      - "tools/check_milestone_06.py"
      - "tools/install_openjpeg_2_5_4.sh"
  workflow_dispatch:

jobs:
  native:
    runs-on: ubuntu-latest
    env:
      RUSTDOCFLAGS: -D warnings
      OPENJPEG_PREFIX: /tmp/metacrate-openjpeg-${{ github.run_id }}
      PKG_CONFIG_PATH: /tmp/metacrate-openjpeg-${{ github.run_id }}/lib/pkgconfig
      LD_LIBRARY_PATH: /tmp/metacrate-openjpeg-${{ github.run_id }}/lib
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v5
        with:
          python-version: "3.11"
      - uses: dtolnay/rust-toolchain@stable
        with:
          components: clippy,rustfmt
      - name: Install audited OpenJPEG 2.5.4
        run: |
          sudo apt-get update
          sudo apt-get install --yes build-essential cmake pkg-config
          tools/install_openjpeg_2_5_4.sh "$OPENJPEG_PREFIX"
      - name: Audit milestone ownership and feature isolation
        run: python tools/check_milestone_06.py
      - name: Test native imaging and meshing crates
        run: |
          cargo test -p libremetaverse-imaging
          cargo test -p libremetaverse-imaging-skia --no-default-features
          cargo test -p libremetaverse-prim-mesher
      - name: Test reviewed milestone parity cases
        run: |
          cargo test -p libremetaverse-compat-tests --test imaging_meshing_semantics reviewed_managedimagetests_
          cargo test -p libremetaverse-compat-tests --test imaging_meshing_semantics reviewed_coordtests_
          cargo test -p libremetaverse-compat-tests --test imaging_meshing_semantics reviewed_quattests_
          cargo test -p libremetaverse-compat-tests --test imaging_meshing_semantics reviewed_primmeshtests_
      - name: Compile performance baselines
        run: |
          cargo bench -p libremetaverse-imaging --bench image_pipeline --no-run -j 1
          cargo bench -p libremetaverse-prim-mesher --bench meshing --no-run -j 1
      - name: Lint and document milestone crates
        run: |
          cargo clippy -p libremetaverse-imaging -p libremetaverse-imaging-skia -p libremetaverse-prim-mesher --all-targets -- -D warnings
          cargo doc -p libremetaverse-imaging -p libremetaverse-imaging-skia -p libremetaverse-prim-mesher --no-deps
      - name: Verify formatting
        run: cargo fmt --all -- --check
