|
| 1 | +name: CI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + pull_request: |
| 7 | + branches: [main] |
| 8 | + |
| 9 | +env: |
| 10 | + CARGO_TERM_COLOR: always |
| 11 | + RUST_BACKTRACE: 1 |
| 12 | + |
| 13 | +permissions: |
| 14 | + contents: read |
| 15 | + |
| 16 | +jobs: |
| 17 | + test: |
| 18 | + name: Test (${{ matrix.name }}) |
| 19 | + runs-on: ${{ matrix.os }} |
| 20 | + strategy: |
| 21 | + fail-fast: false |
| 22 | + matrix: |
| 23 | + include: |
| 24 | + - name: "default features" |
| 25 | + os: ubuntu-latest |
| 26 | + features: "" |
| 27 | + - name: "openblas" |
| 28 | + os: ubuntu-latest |
| 29 | + features: "--features openblas" |
| 30 | + - name: "accelerate" |
| 31 | + os: macos-latest |
| 32 | + features: "--features accelerate" |
| 33 | + steps: |
| 34 | + - uses: actions/checkout@v7 |
| 35 | + |
| 36 | + - name: Install OpenBLAS |
| 37 | + if: matrix.name == 'openblas' |
| 38 | + run: sudo apt-get update && sudo apt-get install -y libopenblas-dev pkg-config |
| 39 | + |
| 40 | + - name: Install Rust toolchain |
| 41 | + uses: dtolnay/rust-toolchain@stable |
| 42 | + |
| 43 | + - name: Cache cargo registry and build |
| 44 | + uses: actions/cache@v6 |
| 45 | + with: |
| 46 | + path: | |
| 47 | + ~/.cargo/registry |
| 48 | + ~/.cargo/git |
| 49 | + target |
| 50 | + key: ${{ runner.os }}-cargo-${{ matrix.name }}-${{ hashFiles('**/Cargo.lock', '**/Cargo.toml') }} |
| 51 | + restore-keys: | |
| 52 | + ${{ runner.os }}-cargo-${{ matrix.name }}- |
| 53 | +
|
| 54 | + - name: Run tests (${{ matrix.name }}) |
| 55 | + run: cargo test ${{ matrix.features }} --verbose |
| 56 | + |
| 57 | + clippy: |
| 58 | + name: Clippy |
| 59 | + runs-on: ubuntu-latest |
| 60 | + steps: |
| 61 | + - uses: actions/checkout@v7 |
| 62 | + |
| 63 | + - name: Install Rust toolchain |
| 64 | + uses: dtolnay/rust-toolchain@stable |
| 65 | + with: |
| 66 | + components: clippy |
| 67 | + |
| 68 | + - name: Cache cargo registry and build |
| 69 | + uses: actions/cache@v6 |
| 70 | + with: |
| 71 | + path: | |
| 72 | + ~/.cargo/registry |
| 73 | + ~/.cargo/git |
| 74 | + target |
| 75 | + key: ${{ runner.os }}-cargo-clippy-${{ hashFiles('**/Cargo.lock', '**/Cargo.toml') }} |
| 76 | + restore-keys: | |
| 77 | + ${{ runner.os }}-cargo-clippy- |
| 78 | +
|
| 79 | + - name: Run Clippy (default features) |
| 80 | + run: cargo clippy -- -D warnings |
| 81 | + |
| 82 | + - name: Run Clippy (openblas backend) |
| 83 | + run: cargo clippy --features openblas -- -D warnings |
| 84 | + |
| 85 | + fmt: |
| 86 | + name: Format |
| 87 | + runs-on: ubuntu-latest |
| 88 | + steps: |
| 89 | + - uses: actions/checkout@v7 |
| 90 | + |
| 91 | + - name: Install Rust toolchain |
| 92 | + uses: dtolnay/rust-toolchain@stable |
| 93 | + with: |
| 94 | + components: rustfmt |
| 95 | + |
| 96 | + - name: Check formatting |
| 97 | + run: cargo fmt --all -- --check |
| 98 | + |
| 99 | + docs: |
| 100 | + name: Documentation |
| 101 | + runs-on: ubuntu-latest |
| 102 | + steps: |
| 103 | + - uses: actions/checkout@v7 |
| 104 | + |
| 105 | + - name: Install Rust toolchain |
| 106 | + uses: dtolnay/rust-toolchain@stable |
| 107 | + |
| 108 | + - name: Cache cargo registry and build |
| 109 | + uses: actions/cache@v6 |
| 110 | + with: |
| 111 | + path: | |
| 112 | + ~/.cargo/registry |
| 113 | + ~/.cargo/git |
| 114 | + target |
| 115 | + key: ${{ runner.os }}-cargo-docs-${{ hashFiles('**/Cargo.lock', '**/Cargo.toml') }} |
| 116 | + restore-keys: | |
| 117 | + ${{ runner.os }}-cargo-docs- |
| 118 | +
|
| 119 | + - name: Check documentation |
| 120 | + env: |
| 121 | + RUSTDOCFLAGS: -D warnings |
| 122 | + run: cargo doc --no-deps |
| 123 | + |
| 124 | + msrv: |
| 125 | + name: Minimum Supported Rust Version |
| 126 | + runs-on: ubuntu-latest |
| 127 | + steps: |
| 128 | + - uses: actions/checkout@v7 |
| 129 | + |
| 130 | + - name: Install Rust toolchain (MSRV) |
| 131 | + uses: dtolnay/rust-toolchain@1.89 |
| 132 | + |
| 133 | + - name: Cache cargo registry and build |
| 134 | + uses: actions/cache@v6 |
| 135 | + with: |
| 136 | + path: | |
| 137 | + ~/.cargo/registry |
| 138 | + ~/.cargo/git |
| 139 | + target |
| 140 | + key: ${{ runner.os }}-cargo-msrv-${{ hashFiles('**/Cargo.lock', '**/Cargo.toml') }} |
| 141 | + restore-keys: | |
| 142 | + ${{ runner.os }}-cargo-msrv- |
| 143 | +
|
| 144 | + - name: Check MSRV compatibility |
| 145 | + run: cargo check |
| 146 | + |
| 147 | + coverage: |
| 148 | + name: Code Coverage |
| 149 | + runs-on: ubuntu-latest |
| 150 | + steps: |
| 151 | + - uses: actions/checkout@v7 |
| 152 | + |
| 153 | + - name: Install Rust toolchain |
| 154 | + uses: dtolnay/rust-toolchain@stable |
| 155 | + with: |
| 156 | + components: llvm-tools-preview |
| 157 | + |
| 158 | + - name: Install cargo-llvm-cov |
| 159 | + uses: taiki-e/install-action@cargo-llvm-cov |
| 160 | + |
| 161 | + - name: Cache cargo registry and build |
| 162 | + uses: actions/cache@v6 |
| 163 | + with: |
| 164 | + path: | |
| 165 | + ~/.cargo/registry |
| 166 | + ~/.cargo/git |
| 167 | + target |
| 168 | + key: ${{ runner.os }}-cargo-cov-${{ hashFiles('**/Cargo.lock', '**/Cargo.toml') }} |
| 169 | + restore-keys: | |
| 170 | + ${{ runner.os }}-cargo-cov- |
| 171 | +
|
| 172 | + - name: Generate coverage report |
| 173 | + run: cargo llvm-cov --lcov --output-path lcov.info |
| 174 | + |
| 175 | + - name: Upload coverage to Codecov |
| 176 | + uses: codecov/codecov-action@v7 |
| 177 | + with: |
| 178 | + files: lcov.info |
| 179 | + fail_ci_if_error: true |
| 180 | + token: ${{ secrets.CODECOV_TOKEN }} |
| 181 | + slug: paradedb/superkmeans-rs |
| 182 | + |
| 183 | + - name: Generate coverage summary |
| 184 | + run: | |
| 185 | + # Run coverage and capture the human-readable table. |
| 186 | + COVERAGE_OUTPUT=$(cargo llvm-cov 2>&1) |
| 187 | +
|
| 188 | + # The TOTAL row lists percentages as: Regions Functions Lines (Branches). |
| 189 | + TOTAL_LINE=$(echo "$COVERAGE_OUTPUT" | grep "^TOTAL") |
| 190 | + REGION_COV=$(echo "$TOTAL_LINE" | grep -oE '[0-9]+\.[0-9]+%' | head -1) |
| 191 | + FUNC_COV=$(echo "$TOTAL_LINE" | grep -oE '[0-9]+\.[0-9]+%' | head -2 | tail -1) |
| 192 | + LINE_COV=$(echo "$TOTAL_LINE" | grep -oE '[0-9]+\.[0-9]+%' | head -3 | tail -1) |
| 193 | +
|
| 194 | + echo "## 📊 Code Coverage Summary" >> $GITHUB_STEP_SUMMARY |
| 195 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 196 | + echo "| Metric | Coverage |" >> $GITHUB_STEP_SUMMARY |
| 197 | + echo "|--------|----------|" >> $GITHUB_STEP_SUMMARY |
| 198 | + echo "| **Lines** | $LINE_COV |" >> $GITHUB_STEP_SUMMARY |
| 199 | + echo "| **Functions** | $FUNC_COV |" >> $GITHUB_STEP_SUMMARY |
| 200 | + echo "| **Regions** | $REGION_COV |" >> $GITHUB_STEP_SUMMARY |
0 commit comments