indicators-ta 0.1.2

Technical analysis indicators and market regime detection for algorithmic trading
Documentation
name: CI

on:
  push:
    branches: [main]
    tags:
      - "v[0-9]+.[0-9]+.[0-9]+" # e.g. v0.1.0 — triggers publish
  pull_request:
    branches: [main]

env:
  CARGO_TERM_COLOR: always
  RUSTFLAGS: "-D warnings" # treat all warnings as errors
  FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true # Forces Node 24 to silence the deprecation warning

jobs:
  # ── Format ────────────────────────────────────────────────────────────────
  fmt:
    name: Rustfmt
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
        with:
          components: rustfmt
      - run: cargo fmt --all -- --check

  # ── Clippy ────────────────────────────────────────────────────────────────
  clippy:
    name: Clippy
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
        with:
          components: clippy
      - uses: Swatinem/rust-cache@v2
      - run: cargo clippy --all-targets -- -D warnings

  # ── Tests ─────────────────────────────────────────────────────────────────
  test:
    name: Tests
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
      - uses: Swatinem/rust-cache@v2
      - run: cargo test --all-features

  # ── MSRV ──────────────────────────────────────────────────────────────────
  msrv:
    name: MSRV (1.92.0)
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@1.92.0
      - uses: Swatinem/rust-cache@v2
      - run: cargo test --all-features

  # ── Docs ──────────────────────────────────────────────────────────────────
  docs:
    name: Docs
    runs-on: ubuntu-latest
    env:
      RUSTDOCFLAGS: "-D warnings"
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
      - uses: Swatinem/rust-cache@v2
      - run: cargo doc --no-deps --all-features

  # ── Publish to crates.io ──────────────────────────────────────────────────
  publish:
    name: Publish to crates.io
    runs-on: ubuntu-latest
    # Only run on version tags, never on branch pushes or PRs.
    if: startsWith(github.ref, 'refs/tags/v')
    # Every CI gate must be green before we publish.
    needs: [fmt, clippy, test, msrv, docs]
    steps:
      - uses: actions/checkout@v4

      - uses: dtolnay/rust-toolchain@stable

      - uses: Swatinem/rust-cache@v2

      # Verify the tag matches the version declared in Cargo.toml so we
      # never accidentally publish with a mismatched version number.
      - name: Verify tag matches Cargo.toml version
        run: |
          CARGO_VERSION=$(cargo metadata --no-deps --format-version 1 \
            | python3 -c "import sys,json; print(json.load(sys.stdin)['packages'][0]['version'])")
          TAG_VERSION="${GITHUB_REF_NAME#v}"   # strips leading 'v'
          echo "Cargo.toml version : $CARGO_VERSION"
          echo "Git tag version    : $TAG_VERSION"
          if [ "$CARGO_VERSION" != "$TAG_VERSION" ]; then
            echo "::error::Version mismatch — bump Cargo.toml before tagging."
            exit 1
          fi

      - name: Publish
        run: cargo publish --no-verify
        env:
          CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}