mixtrics 0.2.3

One crate for all metrics.
Documentation
name: "CI"

on:
  push:
    branches:
      - "main"
      - "forks/*"
  pull_request:
    branches:
      - "main"
      - "v*.*.*-rc"

concurrency:
    group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name }}
    cancel-in-progress: ${{ github.event_name == 'pull_request' }}

env:
  RUST_TOOLCHAIN_NIGHTLY: nightly
  CARGO_TERM_COLOR: always
  CACHE_KEY_SUFFIX: 20250110

jobs:
  misc-check:
    name: misc check
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4
      - name: Run typos check
        uses: crate-ci/typos@master
  rust-machete:
    name: rust machete check
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4
      - name: Run cargo machete
        uses: bnjbvr/cargo-machete@main
  rust-ffmt-check:
    name: rust ffmt check
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest, macos-latest, windows-latest]
    runs-on: ${{ matrix.os }}
    steps:
      - name: Checkout
        uses: actions/checkout@v4
      - name: Install rust toolchain
        uses: dtolnay/rust-toolchain@master
        with:
          toolchain: nightly
          components: rustfmt
      - name: Cache Cargo home
        uses: actions/cache@v4
        id: cache
        with:
          path: |
            ~/.cargo/bin/
            ~/.cargo/registry/index/
            ~/.cargo/registry/cache/
            ~/.cargo/git/db/
          key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.toml') }}-${{ env.CACHE_KEY_SUFFIX }}-rust-ffmt-check
      - name: Fastidious Format Check
        run: |
          cargo fmt --all --check -- --config-path rustfmt.nightly.toml
      - name: Hint
        if: ${{ failure() }}
        run: |-
          echo "The ffmt (Fastidious Format Check) test is not a necessary."
          echo "It uses unstable features to achieve a better format."
          echo "If you want to pass the test, please install the nightly toolchain with \`rustup install nightly\`."
          echo "Then run \`make ffmt\`."
  rust-test:
    name: rust test with codecov
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest, macos-latest, windows-latest]
        rust_toolchain: [stable]
    runs-on: ${{ matrix.os }}
    steps:
      - name: Checkout
        uses: actions/checkout@v4
      - name: Install rust toolchain
        uses: dtolnay/rust-toolchain@master
        with:
          toolchain: ${{ matrix.rust_toolchain }}
          components: rustfmt, clippy, llvm-tools-preview
      - name: Cache Cargo home
        uses: actions/cache@v4
        id: cache
        with:
          path: |
            ~/.cargo/bin/
            ~/.cargo/registry/index/
            ~/.cargo/registry/cache/
            ~/.cargo/git/db/
          key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.toml') }}-${{ env.CACHE_KEY_SUFFIX }}-rust-test
      - name: Install cargo tools
        if: steps.cache.outputs.cache-hit != 'true'
        run: |
          cargo install cargo-sort --locked
      - name: Run rust cargo-sort check
        # https://github.com/DevinR528/cargo-sort/issues/56
        if: matrix.os != 'windows-latest'
        run: |
          cargo sort -w -c
      - name: Run rust format check
        run: |
          cargo fmt --all -- --check
      - name: Run rust clippy check (stable)
        if: matrix.rust_toolchain == 'stable'
        run: |
          cargo clippy --all-targets --all-features -- -D warnings
      - if: steps.cache.outputs.cache-hit != 'true'
        uses: taiki-e/install-action@cargo-llvm-cov
      - if: steps.cache.outputs.cache-hit != 'true'
        uses: taiki-e/install-action@nextest
      - name: Run rust test with coverage
        env:
          RUST_BACKTRACE: 1
          CI: true
        run: |
          cargo llvm-cov --no-report nextest --all-features
      - name: Run rust examples with coverage
        env:
          RUST_BACKTRACE: 1
          CI: true
        run: |
          cargo llvm-cov --no-report run --example basic --features prometheus_0_14
      - name: Generate codecov report
        run: |
          cargo llvm-cov report --lcov --output-path lcov.info
      - uses: codecov/codecov-action@v4
        if: runner.os == 'Linux' && matrix.rust_toolchain == 'stable'
        env:
          CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
        with:
          verbose: true
  rustdoc-test:
    name: rust doc test
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest, macos-latest, windows-latest]
    runs-on: ${{ matrix.os }}
    steps:
      - name: Checkout
        uses: actions/checkout@v4
      - name: Install rust toolchain
        uses: dtolnay/rust-toolchain@master
        with:
          toolchain: nightly
      - name: Cache Cargo home
        uses: actions/cache@v4
        id: cache
        with:
          path: |
            ~/.cargo/bin/
            ~/.cargo/registry/index/
            ~/.cargo/registry/cache/
            ~/.cargo/git/db/
          key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.toml') }}-${{ env.CACHE_KEY_SUFFIX }}-rustdoc-test
      - name: Run rustdoc test
        run: |
          cargo test --all-features --doc
      - name: Test docs build with docs.rs
        env:
          RUSTDOCFLAGS: --cfg docsrs -D warnings
        run: |
          cargo doc --all-features --no-deps
      - name: Upload docs.rs docs as artifacts
        uses: actions/upload-artifact@v4
        with:
          name: mixtrics-docs-${{ github.sha }}-${{ runner.os }}
          path: target/doc
          if-no-files-found: error
          retention-days: 7