waterkit 0.1.1

Kit utilities and helpers
name: CI

permissions:
  contents: read
  checks: write
  id-token: write

on:
  # Integration branches only: a topic branch that also has a pull request
  # would otherwise run the whole workflow twice for one commit, booting two
  # hosted emulators that contend for the same nested-KVM capacity.
  push:
    branches: [main, dev]
  pull_request:
    branches: ["**"]

concurrency:
  group: ci-${{ github.ref }}
  cancel-in-progress: true

env:
  CARGO_TERM_COLOR: always

jobs:
  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 (${{ matrix.os }})
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest, windows-latest, macos-latest]
    steps:
      - uses: actions/checkout@v4
      # `shaderloom` compiles WGSL to DXIL on Windows and shells out to `dxc`,
      # which the runner image does not carry. WaterUI's Windows job installs it
      # the same way.
      - name: Install DirectX Shader Compiler
        if: runner.os == 'Windows'
        uses: tracel-ai/github-actions/install-dxc@295f2fdbae5271f4f8ad56d634e4ff6a95daafc8
      - name: Install Linux dependencies
        if: runner.os == 'Linux'
        run: |
          sudo apt-get update
          sudo apt-get install -y \
            libwayland-dev \
            libxkbcommon-dev \
            libasound2-dev \
            libudev-dev \
            libva-dev \
            libgbm-dev \
            libegl-dev \
            libpipewire-0.3-dev \
            libdav1d-dev \
            nasm \
            libavutil-dev \
            libavcodec-dev \
            libavformat-dev \
            libavfilter-dev \
            libavdevice-dev \
            libswscale-dev \
            libswresample-dev \
            libclang-dev \
            libxcb1-dev \
            libxcb-render0-dev \
            libxcb-shape0-dev \
            libxcb-xfixes0-dev \
            libdbus-1-dev
      - name: Install macOS dependencies
        if: runner.os == 'macOS'
        run: |
          brew install dav1d nasm ffmpeg
      - name: Install Windows dependencies
        if: runner.os == 'Windows'
        run: |
          choco install pkgconfiglite -y
          vcpkg install dav1d:x64-windows
        env:
          VCPKG_ROOT: C:\vcpkg
      - name: Set Windows pkg-config paths
        if: runner.os == 'Windows'
        shell: bash
        run: |
          echo "PKG_CONFIG_PATH=C:/vcpkg/installed/x64-windows/lib/pkgconfig" >> $GITHUB_ENV
          echo "C:/vcpkg/installed/x64-windows/bin" >> $GITHUB_PATH
      - uses: dtolnay/rust-toolchain@stable
        with:
          components: clippy
      - uses: Swatinem/rust-cache@v2
        with:
          shared-key: clippy-${{ matrix.os }}
      - run: cargo clippy --all-targets --all-features -- -D warnings

  cross-clippy:
    name: Clippy (${{ matrix.target }})
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        include:
          - target: aarch64-apple-ios
            os: macos-latest
          - target: aarch64-linux-android
            os: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      # `shaderloom` compiles WGSL to DXIL on Windows and shells out to `dxc`,
      # which the runner image does not carry. WaterUI's Windows job installs it
      # the same way.
      - name: Install DirectX Shader Compiler
        if: runner.os == 'Windows'
        uses: tracel-ai/github-actions/install-dxc@295f2fdbae5271f4f8ad56d634e4ff6a95daafc8
      - name: Install Linux dependencies
        if: runner.os == 'Linux'
        run: |
          sudo apt-get update
          sudo apt-get install -y \
            libwayland-dev \
            libxkbcommon-dev \
            libasound2-dev \
            libudev-dev \
            libva-dev \
            libgbm-dev \
            libegl-dev \
            libpipewire-0.3-dev \
            libdav1d-dev \
            nasm \
            libavutil-dev \
            libavcodec-dev \
            libavformat-dev \
            libavfilter-dev \
            libavdevice-dev \
            libswscale-dev \
            libswresample-dev \
            libclang-dev \
            libxcb1-dev \
            libxcb-render0-dev \
            libxcb-shape0-dev \
            libxcb-xfixes0-dev \
            libdbus-1-dev
      - name: Setup Android NDK
        if: contains(matrix.target, 'android')
        uses: nttld/setup-ndk@v1
        id: setup-ndk
        with:
          ndk-version: r27c
          add-to-path: true
      - name: Set Android environment
        if: contains(matrix.target, 'android')
        run: |
          echo "ANDROID_NDK_HOME=${{ steps.setup-ndk.outputs.ndk-path }}" >> $GITHUB_ENV
          echo "CC_aarch64-linux-android=${{ steps.setup-ndk.outputs.ndk-path }}/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android24-clang" >> $GITHUB_ENV
          echo "CXX_aarch64-linux-android=${{ steps.setup-ndk.outputs.ndk-path }}/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android24-clang++" >> $GITHUB_ENV
          echo "AR_aarch64-linux-android=${{ steps.setup-ndk.outputs.ndk-path }}/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ar" >> $GITHUB_ENV
          echo "CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER=${{ steps.setup-ndk.outputs.ndk-path }}/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android24-clang" >> $GITHUB_ENV
      - name: Install macOS dependencies
        if: runner.os == 'macOS'
        run: |
          brew install dav1d nasm ffmpeg
      - uses: dtolnay/rust-toolchain@stable
        with:
          targets: ${{ matrix.target }}
          components: clippy
      - uses: Swatinem/rust-cache@v2
        with:
          shared-key: cross-${{ matrix.target }}
      - run: cargo clippy --target ${{ matrix.target }} --all-features -- -D warnings

  coverage:
    name: Coverage
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      # `shaderloom` compiles WGSL to DXIL on Windows and shells out to `dxc`,
      # which the runner image does not carry. WaterUI's Windows job installs it
      # the same way.
      - name: Install DirectX Shader Compiler
        if: runner.os == 'Windows'
        uses: tracel-ai/github-actions/install-dxc@295f2fdbae5271f4f8ad56d634e4ff6a95daafc8
      - name: Install Linux dependencies
        run: |
          sudo apt-get update
          sudo apt-get install -y \
            libwayland-dev \
            libxkbcommon-dev \
            libasound2-dev \
            libudev-dev \
            libva-dev \
            libgbm-dev \
            libegl-dev \
            libpipewire-0.3-dev \
            libdav1d-dev \
            nasm \
            libavutil-dev \
            libavcodec-dev \
            libavformat-dev \
            libavfilter-dev \
            libavdevice-dev \
            libswscale-dev \
            libswresample-dev \
            libclang-dev \
            libxcb1-dev \
            libxcb-render0-dev \
            libxcb-shape0-dev \
            libxcb-xfixes0-dev \
            libdbus-1-dev
      - uses: dtolnay/rust-toolchain@stable
        with:
          components: llvm-tools-preview
      - uses: Swatinem/rust-cache@v2
        with:
          shared-key: ci-ubuntu
      - uses: taiki-e/install-action@cargo-llvm-cov
      - run: >
          cargo llvm-cov --all-features --workspace --lcov --output-path lcov.info
          --exclude waterkit-audio-test
          --exclude waterkit-biometric-test
          --exclude waterkit-camera-test
          --exclude waterkit-codec-bench
          --exclude waterkit-dialog-test
          --exclude waterkit-location-test
          --exclude waterkit-notification-test
          --exclude waterkit-sensor-test
          --exclude waterkit-video-test
          --exclude waterkit-test-ios
          --exclude waterkit-test-android
      - uses: codecov/codecov-action@v4
        with:
          use_oidc: true
          fail_ci_if_error: false

  typos:
    name: Typos
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: crate-ci/typos@v1.49.0

  audit:
    name: Security Audit
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Generate Cargo.lock
        run: cargo generate-lockfile
      - uses: Swatinem/rust-cache@v2
        with:
          shared-key: ci-ubuntu
      - uses: rustsec/audit-check@v2
        with:
          token: ${{ secrets.GITHUB_TOKEN }}

  unused-deps:
    name: Unused Dependencies
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
      - uses: Swatinem/rust-cache@v2
        with:
          shared-key: ci-ubuntu
      - uses: taiki-e/install-action@cargo-machete
      - run: cargo machete

  feature-checks:
    name: Features
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      # `shaderloom` compiles WGSL to DXIL on Windows and shells out to `dxc`,
      # which the runner image does not carry. WaterUI's Windows job installs it
      # the same way.
      - name: Install DirectX Shader Compiler
        if: runner.os == 'Windows'
        uses: tracel-ai/github-actions/install-dxc@295f2fdbae5271f4f8ad56d634e4ff6a95daafc8
      - name: Install Linux dependencies
        run: |
          sudo apt-get update
          sudo apt-get install -y \
            libwayland-dev \
            libxkbcommon-dev \
            libasound2-dev \
            libudev-dev \
            libva-dev \
            libgbm-dev \
            libegl-dev \
            libpipewire-0.3-dev \
            libdav1d-dev \
            nasm \
            libavutil-dev \
            libavcodec-dev \
            libavformat-dev \
            libavfilter-dev \
            libavdevice-dev \
            libswscale-dev \
            libswresample-dev \
            libclang-dev \
            libxcb1-dev \
            libxcb-render0-dev \
            libxcb-shape0-dev \
            libxcb-xfixes0-dev \
            libdbus-1-dev
      - uses: dtolnay/rust-toolchain@stable
      - uses: Swatinem/rust-cache@v2
        with:
          shared-key: ci-ubuntu
      - uses: taiki-e/install-action@cargo-hack
      - run: cargo hack check --each-feature --no-dev-deps
      - run: cargo hack check --feature-powerset --no-dev-deps --depth 2

  test:
    name: Test
    uses: ./.github/workflows/test.yml