Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
180 changes: 114 additions & 66 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Rocketmq Rust CI
name: RocketMQ Rust CI

permissions:
contents: read
Expand All @@ -14,130 +14,178 @@ env:
RUST_BACKTRACE: full
CI: true

# ===== RocksDB / build cache =====
CARGO_TARGET_DIR: target
ROCKSDB_DISABLE_JEMALLOC: 1

jobs:
# Format and lint checks
# =========================
# Format + Clippy
# =========================
check:
name: Check (fmt + clippy)
runs-on: ubuntu-latest

steps:
- name: Checkout code
- name: Checkout
uses: actions/checkout@v4

- name: Install dependencies (ubuntu-latest)
- name: Install system dependencies (Ubuntu)
run: |
sudo apt-get install protobuf-compiler
sudo apt-get update
sudo apt-get install -y \
clang llvm libclang-dev \
cmake make ninja-build pkg-config \
protobuf-compiler \
libsnappy-dev liblz4-dev libzstd-dev zlib1g-dev

echo "CC=clang" >> $GITHUB_ENV
echo "CXX=clang++" >> $GITHUB_ENV

LIBCLANG_DIR=$(ls -d /usr/lib/llvm-*/lib | head -n 1)
echo "LIBCLANG_PATH=$LIBCLANG_DIR" >> $GITHUB_ENV

- name: Set up Rust nightly
uses: dtolnay/rust-toolchain@nightly
with:
components: rustfmt, clippy

- name: Cache Rust dependencies
- name: Cache Rust + RocksDB
uses: Swatinem/rust-cache@v2
with:
shared-key: rust-ci

- name: Install dependencies
run: |
rustup component add rustfmt
rustup component add clippy
shared-key: rocketmq-rust-ubuntu
workspaces: |
.
env-vars: |
CC
CXX
LIBCLANG_PATH
ROCKSDB_DISABLE_JEMALLOC

- name: Format check
run: cargo fmt --all -- --check

- name: Clippy check (other packages)
run: cargo clippy --all-targets --workspace --exclude rocketmq-controller --all-features -- -D warnings
- name: Clippy (all features)
run: cargo clippy --workspace --all-targets --all-features -- -D warnings

- name: Clippy check (controller without rocksdb)
run: cargo clippy --all-targets -p rocketmq-controller --no-default-features --features storage-file,metrics,debug -- -D warnings

# Build and test on multiple platforms
# =========================
# Build + Test
# =========================
build-test:
name: Build & Test (${{ matrix.os }})
runs-on: ${{ matrix.os }}
needs: check
runs-on: ${{ matrix.os }}

strategy:
fail-fast: true
fail-fast: false
matrix:
os: [ ubuntu-latest, macos-latest, windows-latest ]

steps:
- name: Checkout code
- name: Checkout
uses: actions/checkout@v4

- if: matrix.os == 'ubuntu-latest'
name: Install dependencies (ubuntu-latest)
# ---------- Ubuntu ----------
- name: Install system dependencies (Ubuntu)
if: matrix.os == 'ubuntu-latest'
run: |
sudo apt-get install protobuf-compiler
- if: matrix.os == 'macos-latest'
name: Install dependencies (macos-latest)
sudo apt-get update
sudo apt-get install -y \
clang llvm libclang-dev \
cmake make ninja-build pkg-config \
protobuf-compiler \
libsnappy-dev liblz4-dev libzstd-dev zlib1g-dev

echo "CC=clang" >> $GITHUB_ENV
echo "CXX=clang++" >> $GITHUB_ENV
LIBCLANG_DIR=$(ls -d /usr/lib/llvm-*/lib | head -n 1)
echo "LIBCLANG_PATH=$LIBCLANG_DIR" >> $GITHUB_ENV

# ---------- macOS ----------
- name: Install system dependencies (macOS)
if: matrix.os == 'macos-latest'
run: |
FILENAME="protoc-3.20.3-osx-x86_64.zip"
URL=https://github.com/protocolbuffers/protobuf/releases/download/v3.20.3/protoc-3.20.3-osx-x86_64.zip
echo "Detected arch: $ARCH, downloading $FILENAME"
curl -LO "$URL"

sudo unzip -o "$FILENAME" -d /usr/local
protoc --version

- if: matrix.os == 'windows-latest'
name: Install dependencies (windows-latest)
brew update
brew install cmake protobuf snappy lz4 zstd
Comment on lines +105 to +109
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Missing compiler and LIBCLANG_PATH configuration on macOS.

Unlike Ubuntu (lines 99-102), the macOS step does not set CC, CXX, or LIBCLANG_PATH environment variables. This creates inconsistency across platforms and may lead to:

  • Different compilers being used (system default vs. explicitly specified)
  • Potential build failures if bindgen or other tools expect LIBCLANG_PATH
🔎 Suggested fix to align macOS configuration
       - name: Install system dependencies (macOS)
         if: matrix.os == 'macos-latest'
         run: |
           brew update
           brew install cmake protobuf snappy lz4 zstd
+
+          echo "CC=clang" >> $GITHUB_ENV
+          echo "CXX=clang++" >> $GITHUB_ENV
+          # macOS ships with LLVM/clang in a standard location
+          echo "LIBCLANG_PATH=/usr/local/opt/llvm/lib" >> $GITHUB_ENV

Note: Verify the actual LLVM path on macos-latest runners if using Homebrew LLVM.


# ---------- Windows ----------
- name: Install system dependencies (Windows)
if: matrix.os == 'windows-latest'
run: |
choco install protoc
choco install cmake ninja protoc -y

- name: Set up Rust nightly
uses: dtolnay/rust-toolchain@nightly

- name: Cache Rust dependencies
- name: Cache Rust + RocksDB
uses: Swatinem/rust-cache@v2
with:
shared-key: rust-ci

- name: Build (other packages)
run: cargo build --verbose --workspace --exclude rocketmq-controller --all-features

- name: Build (controller without rocksdb)
run: cargo build --verbose -p rocketmq-controller --no-default-features --features storage-file,metrics,debug

- name: Run tests (other packages)
run: cargo test --verbose --workspace --exclude rocketmq-controller --all-features

- name: Run tests (controller without rocksdb)
run: cargo test --verbose -p rocketmq-controller --no-default-features --features storage-file,metrics,debug

# Code coverage (only on Ubuntu)
shared-key: rocketmq-rust-${{ matrix.os }}
workspaces: |
.
env-vars: |
CC
CXX
LIBCLANG_PATH
ROCKSDB_DISABLE_JEMALLOC
Comment on lines +120 to +130
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Cache env-vars include variables not set on all platforms.

The cache configuration lists CC, CXX, and LIBCLANG_PATH in env-vars (lines 127-129), but:

  • These variables are only set on Ubuntu (lines 99-102)
  • macOS does not set them (lines 105-109)
  • Windows does not set them (lines 112-115)

This can lead to suboptimal cache behavior, as the cache key will differ when these variables are unset vs. set, potentially causing cache misses or inconsistencies across platforms.

Recommended fix: Either set these variables consistently across all platforms, or make the cache env-vars platform-specific. Alternatively, if these variables are not relevant for non-Ubuntu platforms, document why they're included.
</review_comment_end>

🤖 Prompt for AI Agents
.github/workflows/ci.yaml lines 120-130: the cache step currently lists CC, CXX,
and LIBCLANG_PATH in env-vars even though those are only defined on Ubuntu,
causing inconsistent cache keys across macOS/Windows; fix by making the cached
env-vars platform-specific (e.g., move CC/CXX/LIBCLANG_PATH into the Ubuntu
job's cache step or use a conditional matrix key so only Ubuntu includes them),
or alternatively ensure the variables are defined (set sensible defaults or
empty values) on macOS/Windows before the cache step so the key is stable across
runners.


- name: Build (all features)
run: cargo build --workspace --all-features --verbose

- name: Test (all features)
run: cargo test --workspace --all-features --verbose

# =========================
# Coverage (Ubuntu only)
# =========================
coverage:
name: Code Coverage
runs-on: ubuntu-latest
needs: check
runs-on: ubuntu-latest

steps:
- name: Checkout code
- name: Checkout
uses: actions/checkout@v4

- name: Install dependencies (ubuntu-latest)
run: sudo apt-get install protobuf-compiler
- name: Install system dependencies (Ubuntu)
run: |
sudo apt-get update
sudo apt-get install -y \
clang llvm libclang-dev \
cmake make ninja-build pkg-config \
protobuf-compiler \
libsnappy-dev liblz4-dev libzstd-dev zlib1g-dev

echo "CC=clang" >> $GITHUB_ENV
echo "CXX=clang++" >> $GITHUB_ENV
LIBCLANG_DIR=$(ls -d /usr/lib/llvm-*/lib | head -n 1)
echo "LIBCLANG_PATH=$LIBCLANG_DIR" >> $GITHUB_ENV
Comment on lines +150 to +162
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion | 🟠 Major

Third instance of duplicated dependency installation logic.

This Ubuntu dependency installation block is identical to the ones in the check job (lines 33-46) and build-test job (lines 88-103). Consider extracting this into a reusable composite action to reduce duplication and ensure consistency.

Benefits:

  • Single source of truth for dependency versions and configuration
  • Easier maintenance when updating LLVM versions or adding new dependencies
  • Consistent LIBCLANG_PATH detection logic across all jobs

Example composite action structure:

Create .github/actions/setup-ubuntu-deps/action.yml:

name: 'Setup Ubuntu Dependencies'
description: 'Install system dependencies for RocketMQ Rust on Ubuntu'
runs:
  using: 'composite'
  steps:
    - name: Install system dependencies
      shell: bash
      run: |
        sudo apt-get update
        sudo apt-get install -y \
          clang llvm libclang-dev \
          cmake make ninja-build pkg-config \
          protobuf-compiler \
          libsnappy-dev liblz4-dev libzstd-dev zlib1g-dev
        
        echo "CC=clang" >> $GITHUB_ENV
        echo "CXX=clang++" >> $GITHUB_ENV
        LIBCLANG_DIR=$(ls -d /usr/lib/llvm-*/lib | sort -V | tail -n 1)
        echo "LIBCLANG_PATH=$LIBCLANG_DIR" >> $GITHUB_ENV

Then replace each Ubuntu installation block with:

      - name: Setup Ubuntu dependencies
        uses: ./.github/actions/setup-ubuntu-deps

</review_comment_end>

🤖 Prompt for AI Agents
.github/workflows/ci.yaml around lines 150 to 162: this Ubuntu dependency
installation block is duplicated across three jobs; extract it into a reusable
composite action (e.g., .github/actions/setup-ubuntu-deps/action.yml) that runs
the apt-get update/install commands and sets CC/CXX and LIBCLANG_PATH, then
replace each inline block in the check, build-test, and this job with a single
step that uses the composite action (uses: ./.github/actions/setup-ubuntu-deps)
to centralize maintenance and ensure consistent LIBCLANG_PATH detection.


- name: Set up Rust nightly
uses: dtolnay/rust-toolchain@nightly

- name: Cache Rust dependencies
- name: Cache Rust + RocksDB
uses: Swatinem/rust-cache@v2
with:
shared-key: rust-ci
shared-key: rocketmq-rust-coverage
workspaces: |
.
env-vars: |
CC
CXX
LIBCLANG_PATH
ROCKSDB_DISABLE_JEMALLOC

- name: Install cargo-llvm-cov
uses: taiki-e/install-action@cargo-llvm-cov

- name: Generate code coverage (other packages)
run: |
cargo llvm-cov --workspace --exclude rocketmq-controller --all-features --lcov --output-path lcov-other.info
cargo llvm-cov -p rocketmq-controller --no-default-features --features storage-file,metrics,debug --lcov --output-path lcov-controller.info
cat lcov-other.info lcov-controller.info > lcov.info
- name: Generate coverage (all features)
run: cargo llvm-cov --workspace --all-features --lcov --output-path lcov.info

- name: Upload coverage to Codecov
- name: Upload to Codecov
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: lcov.info
fail_ci_if_error: false
verbose: true
verbose: true
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion rocketmq-controller/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ tokio-util = { workspace = true }

# Raft consensus algorithm - MIGRATING TO OPENRAFT
# Old raft for legacy code (temporary until migration completes)
raft = { git = "https://github.com/tikv/raft-rs.git", branch = "master" }
raft = { git = "https://github.com/tikv/raft-rs.git", rev = "1fd05e0" }
protobuf = "2.28"
# New openraft implementation
openraft = { git = "https://github.com/databendlabs/openraft.git", branch = "release-0.10", features = ["serde", "tokio-rt"] }
Expand Down