|
| 1 | +#!/bin/bash |
| 2 | +set -e |
| 3 | + |
| 4 | +# CI Check Script - Runs local checks matching GitHub CI |
| 5 | +# Usage: ./ci-check.sh [options] |
| 6 | +# Options: |
| 7 | +# --skip-format Skip cargo fmt check |
| 8 | +# --skip-lint Skip clippy lint checks |
| 9 | +# --skip-test Skip cargo test checks |
| 10 | +# --skip-msrv Skip MSRV check |
| 11 | +# --format-fix Fix formatting issues instead of checking |
| 12 | +# --continue Continue on failures instead of stopping |
| 13 | + |
| 14 | +RED='\033[0;31m' |
| 15 | +GREEN='\033[0;32m' |
| 16 | +YELLOW='\033[1;33m' |
| 17 | +NC='\033[0m' # No Color |
| 18 | + |
| 19 | +SKIP_FORMAT=0 |
| 20 | +SKIP_LINT=0 |
| 21 | +SKIP_TEST=0 |
| 22 | +SKIP_MSRV=0 |
| 23 | +FORMAT_FIX=0 |
| 24 | +CONTINUE=0 |
| 25 | +FAILED_CHECKS=() |
| 26 | + |
| 27 | +# Parse arguments |
| 28 | +while [[ $# -gt 0 ]]; do |
| 29 | + case $1 in |
| 30 | + --skip-format) SKIP_FORMAT=1; shift ;; |
| 31 | + --skip-lint) SKIP_LINT=1; shift ;; |
| 32 | + --skip-test) SKIP_TEST=1; shift ;; |
| 33 | + --skip-msrv) SKIP_MSRV=1; shift ;; |
| 34 | + --format-fix) FORMAT_FIX=1; shift ;; |
| 35 | + --continue) CONTINUE=1; shift ;; |
| 36 | + *) echo "Unknown option: $1"; exit 1 ;; |
| 37 | + esac |
| 38 | +done |
| 39 | + |
| 40 | +run_check() { |
| 41 | + local name=$1 |
| 42 | + local cmd=$2 |
| 43 | + |
| 44 | + echo -e "${YELLOW}Running: $name${NC}" |
| 45 | + if eval "$cmd"; then |
| 46 | + echo -e "${GREEN}✓ $name passed${NC}\n" |
| 47 | + return 0 |
| 48 | + else |
| 49 | + echo -e "${RED}✗ $name failed${NC}\n" |
| 50 | + FAILED_CHECKS+=("$name") |
| 51 | + if [[ $CONTINUE -eq 0 ]]; then |
| 52 | + exit 1 |
| 53 | + fi |
| 54 | + return 1 |
| 55 | + fi |
| 56 | +} |
| 57 | + |
| 58 | +echo "=== CI Checks ===" |
| 59 | +echo "" |
| 60 | + |
| 61 | +# Format check |
| 62 | +if [[ $SKIP_FORMAT -eq 0 ]]; then |
| 63 | + if [[ $FORMAT_FIX -eq 1 ]]; then |
| 64 | + run_check "cargo fmt (fix)" "cargo fmt" |
| 65 | + else |
| 66 | + run_check "cargo fmt --check" "cargo fmt -- --check" |
| 67 | + fi |
| 68 | +fi |
| 69 | + |
| 70 | +# Lint checks |
| 71 | +if [[ $SKIP_LINT -eq 0 ]]; then |
| 72 | + run_check "clippy: default + postgis" "cargo clippy --features pg-type-postgis -- -D warnings" || true |
| 73 | + run_check "clippy: minimal" "cargo clippy --no-default-features -- -D warnings" || true |
| 74 | + run_check "clippy: server-api without tls" "cargo clippy --no-default-features --features server-api -- -D warnings" || true |
| 75 | + run_check "clippy: server-api with ring" "cargo clippy --no-default-features --features server-api-ring -- -D warnings" || true |
| 76 | + run_check "clippy: client-api" "cargo clippy --features client-api-aws-lc-rs -- -D warnings" || true |
| 77 | +fi |
| 78 | + |
| 79 | +# Test checks |
| 80 | +if [[ $SKIP_TEST -eq 0 ]]; then |
| 81 | + echo -e "${YELLOW}Running: cargo test suite${NC}" |
| 82 | + run_check "test: default + postgis" "cargo test --features pg-type-postgis" || true |
| 83 | + run_check "test: minimal" "cargo test --no-default-features" || true |
| 84 | + run_check "test: server-api without tls" "cargo test --no-default-features --features server-api" || true |
| 85 | + run_check "test: server-api with ring" "cargo test --no-default-features --features server-api-ring" || true |
| 86 | + run_check "test: client-api" "cargo test --features client-api-aws-lc-rs" || true |
| 87 | + run_check "check: sqlite example" "cargo check --all-targets --features _sqlite,_bundled" || true |
| 88 | +fi |
| 89 | + |
| 90 | +# MSRV check |
| 91 | +if [[ $SKIP_MSRV -eq 0 ]]; then |
| 92 | + echo -e "${YELLOW}Running: MSRV checks (requires Rust 1.89)${NC}" |
| 93 | + run_check "msrv: build default + postgis" "cargo +1.89 build --features pg-type-postgis" || true |
| 94 | + run_check "msrv: build minimal" "cargo +1.89 build --no-default-features" || true |
| 95 | + run_check "msrv: build server-api" "cargo +1.89 build --no-default-features --features server-api" || true |
| 96 | + run_check "msrv: build server-api-ring" "cargo +1.89 build --no-default-features --features server-api-ring" || true |
| 97 | +fi |
| 98 | + |
| 99 | +# Summary |
| 100 | +echo "" |
| 101 | +echo "=== Summary ===" |
| 102 | +if [[ ${#FAILED_CHECKS[@]} -eq 0 ]]; then |
| 103 | + echo -e "${GREEN}All checks passed!${NC}" |
| 104 | + exit 0 |
| 105 | +else |
| 106 | + echo -e "${RED}Failed checks:${NC}" |
| 107 | + for check in "${FAILED_CHECKS[@]}"; do |
| 108 | + echo " - $check" |
| 109 | + done |
| 110 | + exit 1 |
| 111 | +fi |
0 commit comments