name: E2E nlohmann/json

# 实际项目独立 CI：nlohmann/json
on:
  push:
    branches: ["main", "master"]
    paths:
      - "src/**"
      - "tests/nlohmann_json_e2e_test.rs"
      - ".github/workflows/e2e-nlohmann-json.yml"
  pull_request:
    branches: ["main", "master"]
  workflow_dispatch:

env:
  CARGO_TERM_COLOR: always
  RUST_BACKTRACE: 1

jobs:
  nlohmann_json:
    name: nlohmann/json init+merge+check
    runs-on: ubuntu-latest
    permissions:
      contents: read
    steps:
      - uses: actions/checkout@v4
        with:
          submodules: false

      - name: Init submodule
        run: git submodule update --init references/nlohmann-json

      - name: Install system dependencies
        run: |
          sudo apt-get update -qq
          sudo apt-get install -y --no-install-recommends \
            clang libclang-dev g++ libstdc++-14-dev

      - name: Install Rust toolchain
        uses: dtolnay/rust-toolchain@stable

      - name: Cache cargo
        uses: actions/cache@v4
        with:
          path: |
            ~/.cargo/registry
            ~/.cargo/git
            target
          key: ${{ runner.os }}-cargo-e2e-nlohmann-json-${{ hashFiles('**/Cargo.toml') }}
          restore-keys: ${{ runner.os }}-cargo-

      - name: Run nlohmann/json E2E
        run: cargo test --test nlohmann_json_e2e_test -- --test-threads=1
