name: CI

# GitHub Actions is public mirror validation only.
# Primary registry release evidence must be produced on Russian build-runner.

on:
  push:
  pull_request:
  workflow_dispatch:

permissions:
  contents: read

jobs:
  rust-checks:
    name: Rust checks
    runs-on: ubuntu-latest
    defaults:
      run:
        shell: bash
        working-directory: adk-rust
    steps:
      - name: Checkout
        uses: actions/checkout@v4
        with:
          lfs: false

      - name: Install stable Rust
        uses: dtolnay/rust-toolchain@stable
        with:
          components: rustfmt, clippy

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

      - name: cargo test
        run: cargo test --workspace

      - name: cargo clippy
        run: cargo clippy --workspace --all-targets -- -D warnings

      - name: cargo build
        run: cargo build --workspace

  docs-registry-checks:
    name: Docs and registry checks
    runs-on: ubuntu-latest
    defaults:
      run:
        shell: bash
    steps:
      - name: Checkout
        uses: actions/checkout@v4
        with:
          lfs: false

      - name: Registry script syntax
        run: bash -n scripts/registry_readiness_check.sh

      - name: Registry readiness
        run: bash scripts/registry_readiness_check.sh

      - name: Release evidence script syntax
        run: |
          if [[ -f scripts/build_release_evidence.sh ]]; then
            bash -n scripts/build_release_evidence.sh
          fi
          if [[ -f scripts/check_release_evidence.sh ]]; then
            bash -n scripts/check_release_evidence.sh
          fi

      - name: Whitespace diff check
        run: git diff --check

  smoke-checks:
    name: Smoke checks
    runs-on: ubuntu-latest
    defaults:
      run:
        shell: bash
    steps:
      - name: Checkout
        uses: actions/checkout@v4
        with:
          lfs: false

      - name: Install Node.js
        uses: actions/setup-node@v4
        with:
          node-version: "20"

      - name: Deployment readiness smoke
        run: |
          if command -v node >/dev/null 2>&1 && [[ -f scripts/deployment-readiness-smoke.mjs ]]; then
            node scripts/deployment-readiness-smoke.mjs
          else
            echo "skipped: node or scripts/deployment-readiness-smoke.mjs missing"
          fi

      - name: Pilot validation smoke
        run: |
          if command -v node >/dev/null 2>&1 && [[ -f scripts/pilot-validation-smoke.mjs ]]; then
            node scripts/pilot-validation-smoke.mjs
          else
            echo "skipped: node or scripts/pilot-validation-smoke.mjs missing"
          fi

      - name: Browser conformance smoke
        run: |
          if [[ -f scripts/browser-conformance-smoke.mjs ]]; then
            echo "skipped: requires live stand unless explicitly run by operator"
          else
            echo "skipped: scripts/browser-conformance-smoke.mjs missing"
          fi
