siderust 0.9.1

High-precision astronomy and satellite mechanics in Rust.
Documentation
name: Siderust CI

on:
  push:
    branches: [main, master]
  pull_request:
    types: [opened, synchronize, reopened, ready_for_review]

permissions:
  contents: read
  checks: write
  pull-requests: write   # needed to post PR comments

concurrency:
  group: ${{ github.workflow }}-${{ github.event.ref }}
  cancel-in-progress: true

env:
  CARGO_TERM_COLOR: always
  # Deterministic CI: do not download multi-GB JPL BSP files during --all-features.
  SIDERUST_JPL_STUB: all

jobs:
  check:
    name: Check (all features)
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0
      - uses: dtolnay/rust-toolchain@stable
      - run: cargo check --workspace --all-targets --all-features

  fmt:
    name: Format
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0
      - uses: dtolnay/rust-toolchain@stable
        with:
          components: rustfmt
      - run: cargo fmt --all -- --check

  clippy:
    name: Clippy (all features)
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0
      - uses: dtolnay/rust-toolchain@stable
        with:
          components: clippy
      - run: cargo clippy --workspace --all-targets --all-features -- -D warnings

  test:
    name: Test (all features)
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0
      - uses: dtolnay/rust-toolchain@stable
      - run: cargo test --workspace --all-targets --all-features
      - run: cargo test --doc --workspace --all-features

  test-pod:
    name: Test (pod)
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
      - run: cargo test --features pod

  test-spice:
    name: Test (spice)
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
      - run: cargo test --features spice

  test-runtime-data:
    name: Test (runtime-data)
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
      - run: cargo test --features runtime-data

  test-pod-parquet:
    name: Test (pod-parquet)
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
      - run: cargo test --features pod-parquet

  test-pod-doris:
    name: Test (pod-doris)
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
      - run: cargo test --features pod-doris

  coverage:
    name: Test & Coverage
    if: ${{ github.event_name == 'push' || github.event.pull_request.draft == false }}
    runs-on: ubuntu-latest
    env:
      SIDERUST_JPL_STUB: all

    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Set up Rust (nightly + llvm-tools)
        uses: dtolnay/rust-toolchain@v1
        with:
          toolchain: nightly
          components: llvm-tools-preview

      - name: Install cargo-llvm-cov
        uses: taiki-e/install-action@v2
        with:
          tool: cargo-llvm-cov

      - name: Clean previous coverage data
        run: |
          cargo +nightly llvm-cov clean --workspace
          rm -rf target/llvm-cov-target/*.profraw

      - name: Coverage (run, no report)
        run: cargo +nightly llvm-cov --workspace --all-features --doctests --no-report

      - name: Coverage (Cobertura XML)
        run: cargo +nightly llvm-cov report --cobertura --output-path coverage.xml

      - name: Coverage (HTML)
        run: cargo +nightly llvm-cov report --html --output-dir coverage_html

      - name: Build coverage summary (Markdown)
        uses: irongut/CodeCoverageSummary@v1.3.0
        with:
          filename: coverage.xml
          badge: true
          format: markdown
          output: file

      - name: Publish to Job Summary
        run: cat code-coverage-results.md >> "$GITHUB_STEP_SUMMARY"

      - name: Post coverage as PR comment
        if: github.event_name == 'pull_request'
        uses: mshick/add-pr-comment@v2
        with:
          message-path: code-coverage-results.md
          repo-token: ${{ secrets.GITHUB_TOKEN }}

      - name: Coverage gate (≥90% lines)
        run: cargo +nightly llvm-cov --workspace --all-features --doctests --no-run --fail-under-lines 90

      - name: Upload coverage HTML
        if: always()
        uses: actions/upload-artifact@v4
        with:
          name: coverage-html
          path: coverage_html
          retention-days: 7