Skip to content

Commit 35b8dd4

Browse files
committed
Add CI workflow and improve microservices docs
Introduces a GitHub Actions CI workflow for checking, formatting, and linting Rust example projects. Adds detailed module-level documentation to microservices-advanced order, product, and registry services to clarify features, endpoints, and usage.
1 parent 4c571c2 commit 35b8dd4

File tree

8 files changed

+248
-2
lines changed

8 files changed

+248
-2
lines changed

.github/workflows/ci.yml

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main, master]
6+
pull_request:
7+
branches: [main, master]
8+
9+
env:
10+
CARGO_TERM_COLOR: always
11+
RUSTFLAGS: -Dwarnings
12+
13+
jobs:
14+
check:
15+
name: Check Examples
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v4
19+
20+
- name: Install Rust toolchain
21+
uses: dtolnay/rust-action@stable
22+
with:
23+
components: clippy, rustfmt
24+
25+
- name: Cache cargo registry
26+
uses: actions/cache@v4
27+
with:
28+
path: |
29+
~/.cargo/registry
30+
~/.cargo/git
31+
target
32+
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.toml') }}
33+
restore-keys: |
34+
${{ runner.os }}-cargo-
35+
36+
- name: Check all examples compile
37+
run: |
38+
echo "🔍 Checking all examples..."
39+
40+
EXAMPLES=(
41+
"hello-world"
42+
"crud-api"
43+
"auth-api"
44+
"cors-test"
45+
"sqlx-crud"
46+
"event-sourcing"
47+
"graphql-api"
48+
"mcp-server"
49+
"microservices"
50+
"microservices-advanced"
51+
"middleware-chain"
52+
"phase11-demo"
53+
"rate-limit-demo"
54+
"templates"
55+
"toon-api"
56+
"websocket"
57+
"proof-of-concept"
58+
)
59+
60+
FAILED=()
61+
62+
for example in "${EXAMPLES[@]}"; do
63+
echo ""
64+
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
65+
echo "📦 Checking: $example"
66+
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
67+
68+
if cd "$example" && cargo check --quiet 2>&1; then
69+
echo "✅ $example: OK"
70+
else
71+
echo "❌ $example: FAILED"
72+
FAILED+=("$example")
73+
fi
74+
cd ..
75+
done
76+
77+
echo ""
78+
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
79+
echo "📊 Summary"
80+
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
81+
82+
if [ ${#FAILED[@]} -eq 0 ]; then
83+
echo "✅ All ${#EXAMPLES[@]} examples passed!"
84+
exit 0
85+
else
86+
echo "❌ ${#FAILED[@]} example(s) failed:"
87+
for f in "${FAILED[@]}"; do
88+
echo " - $f"
89+
done
90+
exit 1
91+
fi
92+
93+
# Serverless Lambda uses different runtime, check separately
94+
- name: Check serverless-lambda
95+
run: |
96+
echo "📦 Checking: serverless-lambda (AWS Lambda runtime)"
97+
cd serverless-lambda && cargo check --quiet
98+
echo "✅ serverless-lambda: OK"
99+
100+
fmt:
101+
name: Format Check
102+
runs-on: ubuntu-latest
103+
steps:
104+
- uses: actions/checkout@v4
105+
106+
- name: Install Rust toolchain
107+
uses: dtolnay/rust-action@stable
108+
with:
109+
components: rustfmt
110+
111+
- name: Check formatting
112+
run: |
113+
echo "🎨 Checking code formatting..."
114+
115+
EXAMPLES=(
116+
"hello-world"
117+
"crud-api"
118+
"auth-api"
119+
"cors-test"
120+
"sqlx-crud"
121+
"event-sourcing"
122+
"graphql-api"
123+
"mcp-server"
124+
"microservices"
125+
"microservices-advanced"
126+
"middleware-chain"
127+
"phase11-demo"
128+
"rate-limit-demo"
129+
"serverless-lambda"
130+
"templates"
131+
"toon-api"
132+
"websocket"
133+
"proof-of-concept"
134+
)
135+
136+
for example in "${EXAMPLES[@]}"; do
137+
echo "Checking format: $example"
138+
cd "$example" && cargo fmt -- --check && cd ..
139+
done
140+
141+
echo "✅ All formatting checks passed!"
142+
143+
clippy:
144+
name: Clippy Lint
145+
runs-on: ubuntu-latest
146+
steps:
147+
- uses: actions/checkout@v4
148+
149+
- name: Install Rust toolchain
150+
uses: dtolnay/rust-action@stable
151+
with:
152+
components: clippy
153+
154+
- name: Cache cargo registry
155+
uses: actions/cache@v4
156+
with:
157+
path: |
158+
~/.cargo/registry
159+
~/.cargo/git
160+
target
161+
key: ${{ runner.os }}-cargo-clippy-${{ hashFiles('**/Cargo.toml') }}
162+
restore-keys: |
163+
${{ runner.os }}-cargo-clippy-
164+
165+
- name: Run Clippy on examples
166+
run: |
167+
echo "🔎 Running Clippy lints..."
168+
169+
# Quick clippy check on a few key examples
170+
for example in hello-world crud-api auth-api middleware-chain; do
171+
echo "Linting: $example"
172+
cd "$example" && cargo clippy --quiet -- -D warnings && cd ..
173+
done
174+
175+
echo "✅ Clippy checks passed!"

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
/serverless-lambda/target
22
/serverless-lambda/target
33
/serverless-lambda
4+
/microservices/target

cors-test/target/flycheck0/stderr

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
Blocking waiting for file lock on package cache
21
error: failed to get `rustapi-macros` as a dependency of package `cors-test v0.1.0 (C:\Users\tunay\Documents\GitHub\rustapi-rs-examples\cors-test)`
32

43
Caused by:

mcp-server/target/flycheck2/stderr

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
Blocking waiting for file lock on package cache
21
error: failed to get `rustapi-rs` as a dependency of package `mcp-server v0.1.0 (C:\Users\tunay\Documents\GitHub\rustapi-rs-examples\mcp-server)`
32

43
Caused by:

microservices-advanced/src/order.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,31 @@
1+
//! # Order Service
2+
//!
3+
//! Microservice for order processing with service discovery.
4+
//!
5+
//! ## Features
6+
//!
7+
//! - Order creation with product price lookup
8+
//! - Dynamic service discovery via Registry
9+
//! - Client-side load balancing (round-robin ready)
10+
//! - Self-registration with heartbeat
11+
//!
12+
//! ## Endpoints
13+
//!
14+
//! - `POST /orders` - Create a new order
15+
//!
16+
//! ## Service Discovery Flow
17+
//!
18+
//! 1. Order service receives create request
19+
//! 2. Queries Registry for Product Service instances
20+
//! 3. Fetches product price from discovered instance
21+
//! 4. Creates order with calculated total
22+
//!
23+
//! ## Run
24+
//!
25+
//! ```bash
26+
//! cargo run --bin order
27+
//! ```
28+
129
use reqwest::Client;
230
use rustapi_rs::prelude::*;
331
use serde::{Deserialize, Serialize};

microservices-advanced/src/product.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
1+
//! # Product Service
2+
//!
3+
//! Microservice for product catalog management.
4+
//!
5+
//! ## Features
6+
//!
7+
//! - Product listing and retrieval
8+
//! - Self-registration with Service Registry
9+
//! - Automatic heartbeat for health checking
10+
//!
11+
//! ## Endpoints
12+
//!
13+
//! - `GET /products` - List all products
14+
//! - `GET /products/{id}` - Get product by ID
15+
//!
16+
//! ## Run
17+
//!
18+
//! ```bash
19+
//! cargo run --bin product
20+
//! ```
21+
122
use rustapi_rs::prelude::*;
223
use serde::{Deserialize, Serialize};
324
use std::env;

microservices-advanced/src/registry.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
//! # Service Registry
2+
//!
3+
//! Central service registry for microservices discovery pattern.
4+
//!
5+
//! ## Features
6+
//!
7+
//! - Service registration with heartbeat
8+
//! - Service discovery by name
9+
//! - Automatic stale instance cleanup
10+
//! - Thread-safe concurrent access with DashMap
11+
//!
12+
//! ## Endpoints
13+
//!
14+
//! - `POST /register` - Register a service instance
15+
//! - `GET /discover/{name}` - Discover instances of a service
16+
//!
17+
//! ## Run
18+
//!
19+
//! ```bash
20+
//! cargo run --bin registry
21+
//! ```
22+
123
use dashmap::DashMap;
224
use rustapi_rs::prelude::*;
325
use serde::{Deserialize, Serialize};

microservices/target/flycheck3/stderr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
Blocking waiting for file lock on package cache
12
Updating crates.io index
23
error: failed to get `rustapi-rs` as a dependency of package `microservices v0.1.0 (C:\Users\tunay\Documents\GitHub\rustapi-rs-examples\microservices)`
34

0 commit comments

Comments
 (0)