name: Rust CI

on:
  push:
    branches:
      - main
      - 'gaebal/**'
      - 'omx-issue-*'
    paths:
      - .github/workflows/rust-ci.yml
      - rust/**
  pull_request:
    branches:
      - main
    paths:
      - .github/workflows/rust-ci.yml
      - rust/**
  workflow_dispatch:

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

defaults:
  run:
    working-directory: rust

env:
  CARGO_TERM_COLOR: always

jobs:
  fmt:
    name: cargo fmt
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
        with:
          components: rustfmt
      - uses: Swatinem/rust-cache@v2
        with:
          workspaces: rust -> target
      - name: Check formatting
        run: cargo fmt --all --check

  test-rusty-claude-cli:
    name: cargo test -p rusty-claude-cli
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
      - uses: Swatinem/rust-cache@v2
        with:
          workspaces: rust -> target
      - name: Run crate tests
        run: cargo test -p rusty-claude-cli
