async-snmp 0.18.0

Modern async-first SNMP client library for Rust
name: CI

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

env:
  CARGO_TERM_COLOR: always
  CARGO_INCREMENTAL: 0
  CARGO_NET_RETRY: 10
  RUSTUP_MAX_RETRIES: 10

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

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

  feature-combinations:
    name: Features (${{ matrix.name }})
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        include:
          - name: default client
            arguments: ""
          - name: no-default client
            arguments: --no-default-features
          - name: agent without crypto
            arguments: --no-default-features --features agent
            complete_lib: true
          - name: RustCrypto client
            arguments: --no-default-features --features crypto-rustcrypto
          - name: FIPS client
            arguments: --no-default-features --features crypto-fips
          - name: both providers client
            arguments: --no-default-features --features crypto-rustcrypto,crypto-fips
          - name: agent with RustCrypto
            arguments: --no-default-features --features agent,crypto-rustcrypto
          - name: agent with FIPS
            arguments: --no-default-features --features agent,crypto-fips
            complete_lib: true
    steps:
      - uses: actions/checkout@v7
      - uses: dtolnay/rust-toolchain@stable
      - uses: Swatinem/rust-cache@v2
      - run: "cargo test --locked ${{ matrix.arguments }} --test feature_contract"
      - name: Complete agent library tests
        if: matrix.complete_lib == true
        run: "cargo test --locked ${{ matrix.arguments }} --lib"

  minimal-features:
    name: No defaults (library, integrations, docs, examples)
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
      - uses: dtolnay/rust-toolchain@stable
      - uses: Swatinem/rust-cache@v2
      - run: cargo test --locked --no-default-features --lib
      - run: cargo test --locked --no-default-features --test community_only
      - run: cargo test --locked --no-default-features --test v3_without_crypto
      - run: cargo test --locked --no-default-features --doc
      - run: cargo check --locked --no-default-features --examples

  cli-features:
    name: CLI (${{ matrix.name }})
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        include:
          - name: no crypto
            features: cli
          - name: RustCrypto
            features: cli,crypto-rustcrypto
          - name: FIPS
            features: cli,crypto-fips
          - name: both backends
            features: cli,crypto-rustcrypto,crypto-fips
    steps:
      - uses: actions/checkout@v7
      - uses: dtolnay/rust-toolchain@stable
      - uses: Swatinem/rust-cache@v2
      # The CLI unit suite covers community, V3 noAuthNoPriv, password
      # rejection without crypto, explicit V3 without a username, and backend
      # selection when the corresponding providers are present. Check all three
      # binaries separately because they contain no binary-local tests.
      - run: "cargo test --locked --no-default-features --features ${{ matrix.features }} --lib cli::"
      - run: "cargo check --locked --no-default-features --features ${{ matrix.features }} --bins"

  crypto-features:
    name: Crypto (${{ matrix.name }})
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        include:
          - name: RustCrypto
            feature: crypto-rustcrypto
          - name: FIPS
            feature: crypto-fips
    steps:
      - uses: actions/checkout@v7
      - uses: dtolnay/rust-toolchain@stable
      - uses: Swatinem/rust-cache@v2
      - run: "cargo test --locked --no-default-features --features agent,${{ matrix.feature }} --test kat"
      - run: "cargo test --locked --no-default-features --features agent,${{ matrix.feature }} --test client_v3"
      - run: "cargo test --locked --no-default-features --features agent,${{ matrix.feature }} --test notification_sender"
      - run: "cargo test --locked --no-default-features --features agent,${{ matrix.feature }} --lib v3::config::tests"

  test:
    name: Test (${{ matrix.os }}, ${{ matrix.toolchain }})
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest, macos-latest, windows-latest]
        toolchain: ['1.88', stable]
    steps:
      - uses: actions/checkout@v7
      - uses: dtolnay/rust-toolchain@master
        with:
          toolchain: ${{ matrix.toolchain }}
      - uses: Swatinem/rust-cache@v2
      - name: Run tests
        run: |
          cargo test --locked --features agent,crypto-rustcrypto,cli,mib,rt-multi-thread --lib
          cargo test --locked --tests --features agent,crypto-rustcrypto,cli,mib,rt-multi-thread

  all-features:
    name: All features
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
      - uses: dtolnay/rust-toolchain@stable
      - uses: Swatinem/rust-cache@v2
      - run: cargo test --locked --all-features
      - run: cargo check --locked --all-features --all-targets

  docs:
    name: Documentation
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
      - uses: dtolnay/rust-toolchain@stable
      - uses: Swatinem/rust-cache@v2
      - name: Test and build docs
        run: |
          cargo test --locked --doc --all-features
          cargo doc --locked --all-features --no-deps
          cargo doc --locked --no-default-features --no-deps
        env:
          RUSTDOCFLAGS: -D warnings

  audit:
    name: Security Audit
    runs-on: ubuntu-latest
    permissions:
      contents: read
      checks: write
    steps:
      - uses: actions/checkout@v7
      - uses: dtolnay/rust-toolchain@stable
      - uses: rustsec/audit-check@v2
        with:
          token: ${{ secrets.GITHUB_TOKEN }}

  # Container integration tests - run separately as they require Docker
  container-tests:
    name: Container Tests
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
      - uses: dtolnay/rust-toolchain@stable
      - uses: Swatinem/rust-cache@v2
      - uses: docker/setup-buildx-action@v4
      - name: Build test container
        uses: docker/build-push-action@v7
        with:
          context: tests/containers/snmpd
          load: true
          tags: async-snmp-test:latest
          cache-from: type=gha
          cache-to: type=gha,mode=max
      - name: Run container tests
        run: cargo test --locked --test interop --features agent,crypto-rustcrypto,cli,mib,rt-multi-thread -- --ignored