name: CI

on:
  push:
    branches: ["**"]
    tags-ignore: ["v*"]
  pull_request:

permissions:
  contents: read

jobs:
  extension-tests:
    runs-on: ubuntu-latest
    defaults:
      run:
        working-directory: openclaw-extension
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: "22"
      - run: npm install
      - run: npx vitest run

  check:
    strategy:
      fail-fast: false
      matrix:
        include:
          - os: ubuntu-latest
            target: x86_64-unknown-linux-gnu
          - os: macos-14
            target: aarch64-apple-darwin
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v4

      - uses: dtolnay/rust-toolchain@stable
        with:
          components: clippy
          targets: ${{ matrix.target }}

      - uses: Swatinem/rust-cache@v2
        with:
          # Shared across all branches — cache is only invalidated when
          # Cargo.lock changes (new deps). Dramatically cuts CI time for
          # PRs that don't touch dependencies (most of them).
          shared-key: ${{ matrix.target }}-v2
          # Cache all crates (including dev-dependencies like wiremock)
          cache-all-crates: "true"
          # Save cache even if tests fail, so next run has partial builds
          save-if: "true"

      - name: Install protoc
        uses: arduino/setup-protoc@v3
        with:
          repo-token: ${{ secrets.GITHUB_TOKEN }}

      - name: Clippy (warnings = errors)
        timeout-minutes: 10
        run: cargo clippy --tests --target ${{ matrix.target }} -- -D warnings

      - name: Tests
        # Global safety timeout — no individual test should hang more than
        # a few seconds; if the step takes longer than 8 minutes something
        # is wrong and we fail fast instead of waiting for CI timeout
        timeout-minutes: 8
        run: cargo test --target ${{ matrix.target }}

      # Formatting is enforced by dprint locally (not rustfmt)
      # dprint handles Rust, Markdown, YAML, JSON, TOML
