duchess 0.3.3

Silky smooth Java-Rust interop
name: Rust

on:
  push:
    branches: [ "main" ]
  pull_request:
    branches: [ "main" ]

# Allow one instance of this workflow per pull request, and cancel older runs when new changes are pushed
concurrency:
  group: ci-yaml-${{ github.ref }}
  cancel-in-progress: true

env:
  CARGO_TERM_COLOR: always

jobs:
  build:
    strategy:
      matrix:
        os: [ubuntu-latest, macos-latest, windows-latest]
        java-version: ['17', '21']
        jni-version: ['1_6', '1_8']
      fail-fast: false
    runs-on: ${{ matrix.os }}

    steps:
    - uses: actions/checkout@v4
    - uses: actions/setup-java@v3
      with:
        distribution: 'corretto'
        java-version: ${{ matrix.java-version }}
    - name: Install mdBook
      if: matrix.os == 'ubuntu-latest'
      run: curl -sSL https://github.com/rust-lang/mdBook/releases/download/v0.4.28/mdbook-v0.4.28-x86_64-unknown-linux-gnu.tar.gz | tar -xz
    - name: Build
      run: cargo build --verbose
    - name: Test crates, jni_${{ matrix.jni-version }}
      run: cargo test --all-targets --verbose --features jni_${{ matrix.jni-version }}
    - name: Test client crates, jni_${{ matrix.jni-version }}
      run: cargo test --all-targets --verbose --manifest-path=test-crates/Cargo.toml --features jni_${{ matrix.jni-version }}
    - name: Test book
      if: matrix.os == 'ubuntu-latest'
      run: ./mdbook test book

  # JDK 25 changed Class.isInterface(), isArray(), isPrimitive() from native
  # to ordinary methods backed by HotSpot intrinsics. This job verifies duchess
  # works correctly on JDK 25+.
  build-jdk25:
    strategy:
      matrix:
        os: [ubuntu-latest]
        jni-version: ['1_8']
      fail-fast: false
    runs-on: ${{ matrix.os }}

    steps:
    - uses: actions/checkout@v4
    - uses: actions/setup-java@c1e323688fd81a25caa38c78aa6df2d33d3e20d9 # v4.8.0
      with:
        distribution: 'temurin'
        java-version: '25'
    - name: Show Java version
      run: java -version
    - name: Show javap output for Class native methods
      run: javap -p java.lang.Class | grep -E "(isInterface|isArray|isPrimitive)"
    - name: Build
      run: cargo build --verbose
    - name: Test crates, jni_${{ matrix.jni-version }}
      run: cargo test --all-targets --verbose --features jni_${{ matrix.jni-version }}
    - name: Test client crates, jni_${{ matrix.jni-version }}
      run: cargo test --all-targets --verbose --manifest-path=test-crates/Cargo.toml --features jni_${{ matrix.jni-version }}

  coverage:
    runs-on: 'ubuntu-latest'
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-java@v3
        with:
          distribution: 'corretto'
          java-version: 17
      - uses: Swatinem/rust-cache@v2
      - name: install just
        run: |
          cargo install just
      - name: coverage-deps
        run: just coverage-tools
      - name:
        run: just coverage
        env:
          NO_OPEN: true
      - name: Upload Coverage Report
        uses: actions/upload-artifact@v3
        with:
          name: ui-coverage-report
          path: target/ui-coverage-report/