container-device-interface 1.1.1

CDI (Container Device Interface), is a specification, for container-runtimes, to support third-party devices.
Documentation
on:
  push:
    branches:
      - main
  pull_request:
    types:
      - opened
      - reopened
      - synchronize
  schedule:
    - cron: '0 0 * * *'

concurrency:
  group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
  cancel-in-progress: true

name: Static checks
permissions:
  contents: read

jobs:
  # Detect if only docs changed - skip CI if so
  changes:
    name: Detect changes
    runs-on: ubuntu-latest
    outputs:
      code: ${{ steps.filter.outputs.code }}
    steps:
      - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
        with:
          persist-credentials: false
      - uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2
        id: filter
        with:
          filters: |
            code:
              - '**/*.rs'
              - '**/*.toml'
              - '**/*.lock'
              - 'Cargo.lock'
              - '.cargo/**'

  # Run unit and integration tests
  test:
    name: cargo test
    needs: changes
    if: ${{ needs.changes.outputs.code == 'true' || github.event_name == 'schedule' }}
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
        with:
          fetch-depth: 0
          persist-credentials: false

      - name: Install pinned Rust toolchain
        uses: ./.github/actions/rust-toolchain

      - run: cargo test --locked --all-features

  # Check code formatting against Rust style guidelines
  formatting:
    name: cargo fmt
    needs: changes
    if: ${{ needs.changes.outputs.code == 'true' || github.event_name == 'schedule' }}
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
        with:
          fetch-depth: 0
          persist-credentials: false

      - name: Install pinned Rust toolchain
        uses: ./.github/actions/rust-toolchain
        with:
          components: rustfmt

      - run: cargo fmt --all -- --check

  # Lint for common mistakes and style issues
  linting:
    name: cargo clippy
    needs: changes
    if: ${{ needs.changes.outputs.code == 'true' || github.event_name == 'schedule' }}
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
        with:
          fetch-depth: 0
          persist-credentials: false

      - name: Install pinned Rust toolchain
        uses: ./.github/actions/rust-toolchain
        with:
          components: clippy

      - run: cargo clippy --locked --all-targets --all-features -- -D warnings

  # Check dependencies for known security vulnerabilities
  security:
    name: cargo audit
    needs: changes
    if: ${{ needs.changes.outputs.code == 'true' || github.event_name == 'schedule' }}
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
        with:
          fetch-depth: 0
          persist-credentials: false

      - name: Install pinned Rust toolchain
        uses: ./.github/actions/rust-toolchain

      - run: cargo install cargo-audit --locked
      - run: cargo audit

  # Verify licenses, check for banned dependencies, and audit sources
  deny:
    name: cargo deny
    needs: changes
    if: ${{ needs.changes.outputs.code == 'true' || github.event_name == 'schedule' }}
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
        with:
          fetch-depth: 0
          persist-credentials: false

      - name: Install pinned Rust toolchain
        uses: ./.github/actions/rust-toolchain

      - run: cargo install cargo-deny --locked
      - run: cargo deny check

  # Detect unused dependencies in Cargo.toml
  unused-deps:
    name: cargo udeps
    needs: changes
    if: ${{ needs.changes.outputs.code == 'true' || github.event_name == 'schedule' }}
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
        with:
          fetch-depth: 0
          persist-credentials: false

      - name: Install Rust nightly
        # WHY toolchain input: a SHA-pinned ref no longer selects the channel
        uses: dtolnay/rust-toolchain@fa04a1451ff1842e2626ccb99004d0195b455a88 # master (2026-06-30)
        with:
          toolchain: nightly

      # +nightly: a bare cargo would resolve to the rust-toolchain.toml pin
      - run: cargo +nightly install cargo-udeps --locked
      # udeps needs nightly-only -Z flags
      - run: cargo +nightly udeps --locked --all-features

  # Analyze binary size and identify largest functions
  bloat:
    name: cargo bloat
    needs: changes
    if: ${{ needs.changes.outputs.code == 'true' || github.event_name == 'schedule' }}
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
        with:
          fetch-depth: 0
          persist-credentials: false

      - name: Install pinned Rust toolchain
        uses: ./.github/actions/rust-toolchain

      - run: cargo install cargo-bloat --locked
      - run: cargo bloat --release --all-features -n 20

  # Detect undefined behavior in unsafe code using Miri interpreter
  miri:
    name: cargo miri
    timeout-minutes: 30
    needs: changes
    if: ${{ needs.changes.outputs.code == 'true' || github.event_name == 'schedule' }}
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
        with:
          fetch-depth: 0
          persist-credentials: false

      - name: Install Rust nightly
        # WHY toolchain input: a SHA-pinned ref no longer selects the channel
        uses: dtolnay/rust-toolchain@fa04a1451ff1842e2626ccb99004d0195b455a88 # master (2026-06-30)
        with:
          toolchain: nightly
          components: miri

      # +nightly outranks rust-toolchain.toml; miri only exists on nightly.
      # -Zmiri-disable-isolation: tests touch the real filesystem. Blocking:
      # the suite passes under miri (root-only FFI tests self-skip).
      - run: cargo +nightly miri test --locked
        env:
          MIRIFLAGS: -Zmiri-disable-isolation