noah-sdk 1.1.0

A modern, type-safe Rust SDK for the Noah Business API
name: Rust CI

on:
  workflow_dispatch:
  pull_request:
    branches: [main]
  push:
    branches: [main]

jobs:
  prettier:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v6
      - name: Run prettier
        run: |-
          npx prettier --check .

  toml-lint:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout toml files
        uses: actions/checkout@v6
      - name: Run toml check
        run: npx @taplo/cli fmt --config ./taplo/taplo.toml --check

  rust_build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v6
      - run: rustup show
      - uses: Swatinem/rust-cache@v2
        with:
          # Only save the cache on the main branch to avoid PRs filling
          # up the cache.
          save-if: ${{ github.ref == 'refs/heads/main' }}
          # Further, save the cache per key - e.g. language grouping.
          key: rust-cache-key
      - name: Build the project
        run: |
          cargo build --release --workspace

  cargo-lint:
    runs-on: ubuntu-latest
    needs: rust_build
    steps:
      - uses: actions/checkout@v6
      - run: rustup show
      - uses: Swatinem/rust-cache@v2
        with:
          # Only save the cache on the main branch to avoid PRs filling
          # up the cache.
          save-if: ${{ github.ref == 'refs/heads/main' }}
          # Further, save the cache per key - e.g. language grouping.
          key: rust-cache-key
      - name: Format and clippy
        run: |
          cargo fmt -- --check
          cargo clippy --no-deps -- -D warnings
          cargo clippy --tests --no-deps -- -D warnings

  tests-rust:
    runs-on: ubuntu-latest
    needs: cargo-lint
    steps:
      - uses: actions/checkout@v6
      - uses: Swatinem/rust-cache@v2
        with:
          # Only save the cache on the main branch to avoid PRs filling
          # up the cache.
          save-if: ${{ github.ref == 'refs/heads/main' }}
          # Further, save the cache per key - e.g. language grouping.
          key: rust-cache-key
      - name: Run tests
        run: cargo test

  # https://github.com/marketplace/actions/alls-green#why
  # used for branch protection checks
  check:
    if: always()

    needs: [prettier, toml-lint, rust_build, cargo-lint, tests-rust]
    runs-on: ubuntu-latest
    steps:
      - name: Decide whether the needed jobs succeeded or failed
        uses: re-actors/alls-green@release/v1
        with:
          jobs: ${{ toJSON(needs) }}