satkit 0.20.2

Satellite Toolkit
Documentation
name: Build

on:
  push:
    branches:
      - "*"
    paths-ignore:
      - "docs/**"
      - "README.md"
      - "CHANGES.md"
      - "CONTRIBUTING.md"
      - "LICENSE"
  pull_request:
    branches:
      - "*"
      - "!wheel*"
    types:
      - opened
      - synchronize
      - reopened
      - closed
    paths-ignore:
      - "docs/**"
      - "README.md"
      - "CHANGES.md"
      - "CONTRIBUTING.md"
      - "LICENSE"

jobs:
  lint:
    name: rustfmt
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v5
      - uses: dtolnay/rust-toolchain@stable
        with:
          components: rustfmt
      - name: Check formatting
        run: cargo fmt --all -- --check

  clippy:
    name: clippy
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v5
      - uses: dtolnay/rust-toolchain@stable
        with:
          components: clippy
      - name: Cargo Cache
        uses: actions/cache@v4
        with:
          path: |
            ~/.cargo/registry/index/
            ~/.cargo/registry/cache/
            ~/.cargo/git/db/
            target/
          key: ${{ runner.os }}-cargo-clippy-${{ hashFiles('**/Cargo.lock') }}
          restore-keys: ${{ runner.os }}-cargo-clippy-
      - name: Clippy (deny warnings)
        run: cargo clippy --workspace --all-targets -- -D warnings

  audit:
    name: cargo audit
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v5
      - uses: dtolnay/rust-toolchain@stable
      - name: Install cargo-audit
        uses: taiki-e/install-action@cargo-audit
      - name: Audit dependencies (RustSec advisories)
        run: cargo audit

  sdist:
    # Guard against source-unbuildable sdists: a broken 0.20.0 sdist (missing
    # benches/ while Cargo.toml declared a bench target) shipped to PyPI
    # undetected because wheels and `cargo publish --dry-run` exercise
    # different artifacts. Build the sdist, then pip-install *from it* and
    # import the result.
    name: sdist installs from source
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v5
      - uses: dtolnay/rust-toolchain@stable
      - name: Set up Python
        uses: actions/setup-python@v6
        with:
          python-version: "3.13"
      - name: Cargo Cache
        uses: actions/cache@v4
        with:
          path: |
            ~/.cargo/registry/index/
            ~/.cargo/registry/cache/
            ~/.cargo/git/db/
          key: ${{ runner.os }}-cargo-sdist-${{ hashFiles('**/Cargo.lock') }}
          restore-keys: ${{ runner.os }}-cargo-sdist-
      - name: Build sdist
        run: |
          pip install build
          python -m build --sdist -o dist
      - name: Install from sdist and import
        run: |
          pip install numpy
          pip install --no-deps dist/satkit-*.tar.gz
          cd /tmp
          python -c "import satkit as sk; t = sk.time(2024, 1, 1, 12, 0, 0); q = sk.quaternion.rotz(0.5); assert abs(q.angle - 0.5) < 1e-12; print('sdist install OK:', sk.__version__, t)"

  rust:
    name: rust build and test (${{ matrix.os }})
    strategy:
      fail-fast: false
      matrix:
        os: [macos, ubuntu, windows]

    runs-on: ${{ format('{0}-latest', matrix.os) }}

    env:
      SATKIT_DATA: astro-data
      SATKIT_TESTVEC_ROOT: satkit-testvecs

    steps:
      - uses: actions/checkout@v5
      - uses: dtolnay/rust-toolchain@stable

      - name: Cache Satkit Data
        id: cache-satkit-data
        uses: actions/cache@v4
        with:
          path: astro-data
          enableCrossOsArchive: true
          key: satkit-data-cache

      - name: Download Satkit Data
        if: steps.cache-satkit-data.outputs.cache-hit != 'true'
        run: |
          python -m pip install requests
          python python/test/download_data.py astro-data

      - name: Cache Satkit Test Vectors
        id: cache-satkit-testvecs
        uses: actions/cache@v4
        with:
          path: satkit-testvecs
          enableCrossOsArchive: true
          key: satkit-testvecs-cache

      - name: Download Satkit Test Vectors
        if: steps.cache-satkit-testvecs.outputs.cache-hit != 'true'
        run: |
          python -m pip install requests
          python python/test/download_testvecs.py satkit-testvecs

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

      - name: Build
        run: cargo build --release

      - name: Test
        run: cargo test --features chrono

      - name: Doc
        run: cargo doc --no-deps

  python:
    name: python bindings test
    runs-on: ubuntu-latest

    env:
      SATKIT_DATA: astro-data
      SATKIT_TESTVEC_ROOT: satkit-testvecs

    steps:
      - uses: actions/checkout@v5
      - uses: dtolnay/rust-toolchain@stable

      - name: Set up Python
        uses: actions/setup-python@v6
        with:
          python-version: "3.13"

      - name: Cache Satkit Data
        id: cache-satkit-data
        uses: actions/cache@v4
        with:
          path: astro-data
          enableCrossOsArchive: true
          key: satkit-data-cache

      - name: Download Satkit Data
        if: steps.cache-satkit-data.outputs.cache-hit != 'true'
        run: |
          pip install requests
          python python/test/download_data.py astro-data

      - name: Cache Satkit Test Vectors
        id: cache-satkit-testvecs
        uses: actions/cache@v4
        with:
          path: satkit-testvecs
          enableCrossOsArchive: true
          key: satkit-testvecs-cache

      - name: Download Satkit Test Vectors
        if: steps.cache-satkit-testvecs.outputs.cache-hit != 'true'
        run: |
          pip install requests
          python python/test/download_testvecs.py satkit-testvecs

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

      - name: Install satkit
        run: pip install -e ".[test]"

      - name: Run Python tests
        run: pytest python/test/