|
| 1 | +name: CI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [master] |
| 6 | + pull_request: |
| 7 | + branches: [master] |
| 8 | + |
| 9 | +env: |
| 10 | + CARGO_TERM_COLOR: always |
| 11 | + |
| 12 | +jobs: |
| 13 | + lint: |
| 14 | + name: Lint & Format |
| 15 | + runs-on: ubuntu-latest |
| 16 | + steps: |
| 17 | + - uses: actions/checkout@v4 |
| 18 | + - uses: dtolnay/rust-toolchain@stable |
| 19 | + with: |
| 20 | + components: rustfmt, clippy |
| 21 | + - uses: Swatinem/rust-cache@v2 |
| 22 | + - run: cargo fmt -- --check |
| 23 | + - run: cargo clippy -- -D warnings |
| 24 | + |
| 25 | + test-linux: |
| 26 | + name: Test (Linux + Redis) |
| 27 | + runs-on: ubuntu-latest |
| 28 | + needs: lint |
| 29 | + strategy: |
| 30 | + matrix: |
| 31 | + rust: ['1.82', 'stable'] |
| 32 | + redis-mode: ['standalone', 'cluster'] |
| 33 | + |
| 34 | + services: |
| 35 | + redis: |
| 36 | + image: redis:alpine |
| 37 | + ports: [6379:6379] |
| 38 | + options: --health-cmd "redis-cli ping" --health-interval 10s --health-timeout 5s --health-retries 5 |
| 39 | + |
| 40 | + steps: |
| 41 | + - uses: actions/checkout@v4 |
| 42 | + - uses: dtolnay/rust-toolchain@stable |
| 43 | + with: |
| 44 | + toolchain: ${{ matrix.rust }} |
| 45 | + - uses: Swatinem/rust-cache@v2 |
| 46 | + |
| 47 | + - name: Setup Redis Cluster |
| 48 | + if: matrix.redis-mode == 'cluster' |
| 49 | + run: | |
| 50 | + sudo apt-get update && sudo apt-get install -y redis-server redis-tools |
| 51 | + mkdir -p /tmp/redis-cluster/{7000,7001,7002,7003,7004,7005} |
| 52 | + |
| 53 | + # Create cluster nodes |
| 54 | + for port in 7000 7001 7002 7003 7004 7005; do |
| 55 | + cat > /tmp/redis-cluster/$port/redis.conf <<EOF |
| 56 | + port $port |
| 57 | + cluster-enabled yes |
| 58 | + cluster-config-file nodes-$port.conf |
| 59 | + cluster-node-timeout 5000 |
| 60 | + appendonly yes |
| 61 | + bind 0.0.0.0 |
| 62 | + protected-mode no |
| 63 | + EOF |
| 64 | + redis-server /tmp/redis-cluster/$port/redis.conf --daemonize yes --dir /tmp/redis-cluster/$port/ |
| 65 | + done |
| 66 | + |
| 67 | + sleep 10 |
| 68 | + echo "yes" | redis-cli --cluster create 127.0.0.1:{7000,7001,7002,7003,7004,7005} --cluster-replicas 1 |
| 69 | +
|
| 70 | + - name: Build and Test |
| 71 | + run: | |
| 72 | + cargo build --all-features |
| 73 | + cargo test --lib |
| 74 | + |
| 75 | + - name: Run Integration Tests |
| 76 | + env: |
| 77 | + REDIS_AVAILABLE: ${{ matrix.redis-mode == 'standalone' }} |
| 78 | + REDIS_URL: redis://127.0.0.1:6379 |
| 79 | + REDIS_CLUSTER_AVAILABLE: ${{ matrix.redis-mode == 'cluster' }} |
| 80 | + REDIS_CLUSTER_PUBSUB_NODE: redis://127.0.0.1:7000 |
| 81 | + RUST_LOG: debug |
| 82 | + run: | |
| 83 | + if [ "${{ matrix.redis-mode }}" = "standalone" ]; then |
| 84 | + echo "Running Standalone Redis Tests" |
| 85 | + echo "Redis URL: $REDIS_URL" |
| 86 | + echo "Note: Cluster-specific tests will be skipped" |
| 87 | + echo "" |
| 88 | + # Run all non-ignored tests (cluster tests are marked with #[ignore]) |
| 89 | + cargo test --lib |
| 90 | + elif [ "${{ matrix.redis-mode }}" = "cluster" ]; then |
| 91 | + echo "Running Redis Cluster Tests" |
| 92 | + echo "PubSub Node: $REDIS_CLUSTER_PUBSUB_NODE" |
| 93 | + echo "Note: All instances MUST use the SAME node for PubSub" |
| 94 | + echo "" |
| 95 | + echo "Checking cluster status..." |
| 96 | + redis-cli -p 7000 cluster nodes || echo "Warning: Could not get cluster status" |
| 97 | + echo "" |
| 98 | + echo "Running all tests including cluster-specific tests..." |
| 99 | + # Run all tests including ignored ones (cluster tests) |
| 100 | + timeout 300s cargo test --lib -- --include-ignored --nocapture |
| 101 | + fi |
| 102 | +
|
| 103 | + - name: Security Audit |
| 104 | + if: matrix.rust == 'stable' |
| 105 | + run: | |
| 106 | + cargo install cargo-audit |
| 107 | + cargo audit |
| 108 | +
|
| 109 | + test-cross-platform: |
| 110 | + name: Test (${{ matrix.os }}) |
| 111 | + runs-on: ${{ matrix.os }} |
| 112 | + needs: lint |
| 113 | + strategy: |
| 114 | + matrix: |
| 115 | + os: [windows-latest, macos-latest] |
| 116 | + rust: ['1.82', 'stable'] |
| 117 | + |
| 118 | + steps: |
| 119 | + - uses: actions/checkout@v4 |
| 120 | + - uses: dtolnay/rust-toolchain@stable |
| 121 | + with: |
| 122 | + toolchain: ${{ matrix.rust }} |
| 123 | + - uses: Swatinem/rust-cache@v2 |
| 124 | + - run: cargo build --all-features |
| 125 | + - run: cargo test --lib |
0 commit comments