motto 0.4.3

Compiler-as-a-Service: Turn Rust schema.rs into multi-platform SDK toolkits
Documentation
name: CI

on:
  push:
    branches: [master]
  pull_request:
    branches: [master]

env:
  CARGO_TERM_COLOR: always
  RUSTFLAGS: -Dwarnings

jobs:
  check:
    name: Check
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
      - uses: Swatinem/rust-cache@v2
      - run: cargo check --all-features

  test:
    name: Test (${{ matrix.env }})
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        include:
          - env: rust
            features: ""
            targets: rust
          - env: typescript
            features: emitter-typescript
            targets: typescript
          - env: swift
            features: emitter-swift
            targets: swift
          - env: kotlin
            features: emitter-kotlin
            targets: kotlin
          - env: unity
            features: emitter-unity
            targets: unity
          - env: all
            features: all-emitters
            targets: all
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
      - uses: Swatinem/rust-cache@v2

      - name: Setup Node.js
        if: matrix.env == 'typescript' || matrix.env == 'all'
        uses: actions/setup-node@v4
        with:
          node-version: '22'

      - name: Setup Java
        if: matrix.env == 'kotlin' || matrix.env == 'all'
        uses: actions/setup-java@v4
        with:
          distribution: temurin
          java-version: '21'

      - name: Setup Gradle
        if: matrix.env == 'kotlin' || matrix.env == 'all'
        uses: gradle/actions/setup-gradle@v4
        with:
          gradle-version: '8.10.2'

      - name: Setup .NET
        if: matrix.env == 'unity' || matrix.env == 'all'
        uses: actions/setup-dotnet@v4
        with:
          dotnet-version: '8.0.x'

      - name: Run tests for environment
        run: |
          if [ -n "${{ matrix.features }}" ]; then
            cargo test --no-default-features --features "${{ matrix.features }}"
            cargo test --no-default-features --features "${{ matrix.features }}" -- --ignored
          else
            cargo test --no-default-features
            cargo test --no-default-features -- --ignored
          fi

      - name: Generate SDK for environment
        env:
          OUT_DIR: ${{ runner.temp }}/sdk-${{ matrix.env }}
        run: |
          rm -rf "${OUT_DIR}"
          if [ -n "${{ matrix.features }}" ]; then
            cargo run --no-default-features --features "${{ matrix.features }}" -- \
              generate --schema src/templates/example_schema.rs --output "${OUT_DIR}" --targets "${{ matrix.targets }}"
          else
            cargo run --no-default-features -- \
              generate --schema src/templates/example_schema.rs --output "${OUT_DIR}" --targets "${{ matrix.targets }}"
          fi

      - name: Test generated Rust SDK (if present)
        env:
          OUT_DIR: ${{ runner.temp }}/sdk-${{ matrix.env }}
        run: |
          if [ -f "${OUT_DIR}/rust/Cargo.toml" ]; then
            cargo test --manifest-path "${OUT_DIR}/rust/Cargo.toml"
          else
            echo "No generated Rust SDK for env=${{ matrix.env }}"
          fi

      - name: Verify generated test assets
        env:
          OUT_DIR: ${{ runner.temp }}/sdk-${{ matrix.env }}
        run: |
          case "${{ matrix.env }}" in
            rust)
              test -f "${OUT_DIR}/rust/src/tests.rs"
              ;;
            typescript)
              test -f "${OUT_DIR}/typescript/tests/codec.test.ts"
              ;;
            swift)
              test -f "${OUT_DIR}/swift/Tests/MottoSDKTests/MottoSDKTests.swift"
              ;;
            kotlin)
              test -f "${OUT_DIR}/kotlin/src/test/kotlin/io/motto/sdk/MottoSdkTests.kt"
              ;;
            unity)
              test -f "${OUT_DIR}/unity/MottoSDK/Runtime/Tests/CodecTests.cs"
              ;;
            all)
              test -f "${OUT_DIR}/rust/src/tests.rs"
              test -f "${OUT_DIR}/typescript/tests/codec.test.ts"
              test -f "${OUT_DIR}/swift/Tests/MottoSDKTests/MottoSDKTests.swift"
              test -f "${OUT_DIR}/kotlin/src/test/kotlin/io/motto/sdk/MottoSdkTests.kt"
              test -f "${OUT_DIR}/unity/MottoSDK/Runtime/Tests/CodecTests.cs"
              ;;
          esac

      - name: Generate native-toolchain fixture SDK
        if: matrix.env == 'typescript' || matrix.env == 'swift' || matrix.env == 'kotlin' || matrix.env == 'unity' || matrix.env == 'all'
        env:
          OUT_NATIVE_DIR: ${{ runner.temp }}/sdk-native-${{ matrix.env }}
        run: |
          rm -rf "${OUT_NATIVE_DIR}"
          if [ -n "${{ matrix.features }}" ]; then
            cargo run --no-default-features --features "${{ matrix.features }}" -- \
              generate --schema src/templates/native_ci_schema.rs --output "${OUT_NATIVE_DIR}" --targets "${{ matrix.targets }}"
          else
            cargo run --no-default-features -- \
              generate --schema src/templates/native_ci_schema.rs --output "${OUT_NATIVE_DIR}" --targets "${{ matrix.targets }}"
          fi

      - name: Run generated TypeScript tests
        if: matrix.env == 'typescript' || matrix.env == 'all'
        env:
          OUT_NATIVE_DIR: ${{ runner.temp }}/sdk-native-${{ matrix.env }}
        run: |
          cd "${OUT_NATIVE_DIR}/typescript"
          npm install
          npm test

      - name: Run generated Swift tests
        if: matrix.env == 'swift' || matrix.env == 'all'
        env:
          OUT_NATIVE_DIR: ${{ runner.temp }}/sdk-native-${{ matrix.env }}
        run: |
          cd "${OUT_NATIVE_DIR}/swift"
          swift test

      - name: Run generated Kotlin tests
        if: matrix.env == 'kotlin' || matrix.env == 'all'
        env:
          OUT_NATIVE_DIR: ${{ runner.temp }}/sdk-native-${{ matrix.env }}
        run: |
          cd "${OUT_NATIVE_DIR}/kotlin"
          gradle test --no-daemon

      - name: Run generated Unity C# tests
        if: matrix.env == 'unity' || matrix.env == 'all'
        env:
          OUT_NATIVE_DIR: ${{ runner.temp }}/sdk-native-${{ matrix.env }}
        run: |
          cd "${OUT_NATIVE_DIR}/unity/MottoSDK"
          dotnet test Motto.SDK.Tests.csproj --configuration Release

  fmt:
    name: Format
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
        with:
          components: rustfmt
      - run: cargo fmt --all --check

  clippy:
    name: Clippy
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
        with:
          components: clippy
      - uses: Swatinem/rust-cache@v2
      - run: cargo clippy --all-features -- -D warnings