Skip to content

Commit bb2fc52

Browse files
authored
Merge pull request #19 from openSVM/copilot/fix-18
Implement comprehensive Rust SDK for Solana AI Registries
2 parents 971d66e + bbfe870 commit bb2fc52

23 files changed

+7547
-1
lines changed

.github/workflows/README.md

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
# GitHub Actions for Rust SDK
2+
3+
This repository includes automated GitHub Actions workflows for the Rust SDK located in the `rust/` directory.
4+
5+
## Workflows
6+
7+
### 1. Rust CI (`rust-ci.yml`)
8+
9+
**Triggers:**
10+
- Push to `main` or `develop` branches (when Rust SDK files change)
11+
- Pull requests to `main` or `develop` branches (when Rust SDK files change)
12+
13+
**What it does:**
14+
- Tests the SDK on multiple Rust versions (stable and beta)
15+
- Checks code formatting
16+
- Builds with different feature combinations
17+
- Runs comprehensive test suite (89 tests)
18+
- Validates packaging
19+
20+
**Testing Matrix:**
21+
- No default features: Core functionality only
22+
- All features: Full feature set including payment systems
23+
- Individual features: `pyg`, `prepay`, `stream`
24+
25+
### 2. Publish to crates.io (`publish-rust-sdk.yml`)
26+
27+
**Triggers:**
28+
- New GitHub releases
29+
- Tags matching pattern `rust-v*` (e.g., `rust-v0.1.0`, `rust-v1.2.0`)
30+
31+
**What it does:**
32+
- Validates code quality (formatting, building, testing)
33+
- Tests all feature flag combinations
34+
- Packages the crate
35+
- Publishes to crates.io
36+
37+
## Setup Requirements
38+
39+
### Required GitHub Secrets
40+
41+
To enable automatic publishing, you need to configure:
42+
43+
1. **`CRATES_TOKEN`** - Your crates.io API token
44+
- Go to [crates.io/me](https://crates.io/me)
45+
- Generate a new token with publish permissions
46+
- Add as repository secret in GitHub Settings → Secrets and variables → Actions
47+
48+
### Publishing Process
49+
50+
#### Automatic Publishing
51+
52+
1. **For releases:**
53+
```bash
54+
# Create and push a new tag
55+
git tag rust-v0.1.1
56+
git push origin rust-v0.1.1
57+
58+
# Or create a GitHub release with tag rust-v0.1.1
59+
```
60+
61+
2. **For GitHub releases:**
62+
- Create a new release in the GitHub UI
63+
- The workflow will automatically trigger
64+
65+
#### Manual Publishing
66+
67+
For development or testing:
68+
69+
```bash
70+
cd rust
71+
export CRATES_TOKEN=your_token_here
72+
cargo publish
73+
```
74+
75+
## Workflow Features
76+
77+
### Smart Path Filtering
78+
79+
Both workflows only run when Rust SDK files change:
80+
- `rust/**` - Any file in the Rust SDK directory
81+
- `.github/workflows/rust-*.yml` - Workflow configuration changes
82+
83+
### Comprehensive Testing
84+
85+
The CI workflow ensures reliability across:
86+
- Multiple Rust versions (stable, beta)
87+
- All feature flag combinations
88+
- Core functionality without optional features
89+
- Full feature set with payment systems
90+
91+
### Error Handling
92+
93+
The workflows are designed to:
94+
- Fail fast on formatting issues
95+
- Validate all feature combinations
96+
- Ensure package can be built and published
97+
- Provide clear error messages
98+
99+
## Local Development
100+
101+
To run the same checks locally:
102+
103+
```bash
104+
cd rust
105+
106+
# Check formatting
107+
cargo fmt -- --check
108+
109+
# Build and test different feature combinations
110+
cargo build --no-default-features
111+
cargo build --all-features
112+
cargo test --no-default-features
113+
cargo test --all-features
114+
cargo test --features pyg
115+
cargo test --features prepay
116+
cargo test --features stream
117+
118+
# Package validation
119+
cargo package --allow-dirty
120+
```
121+
122+
## Troubleshooting
123+
124+
### Common Issues
125+
126+
1. **Formatting failures:**
127+
```bash
128+
cd rust
129+
cargo fmt
130+
git add .
131+
git commit -m "Fix formatting"
132+
```
133+
134+
2. **Feature flag compilation errors:**
135+
- Check that conditional compilation (`#[cfg(feature = "...")]`) is correct
136+
- Ensure dependencies are properly feature-gated
137+
138+
3. **Publishing failures:**
139+
- Verify `CRATES_TOKEN` secret is configured
140+
- Check that version in `Cargo.toml` hasn't been published before
141+
- Ensure all required metadata is present in `Cargo.toml`
142+
143+
### Workflow Logs
144+
145+
Check workflow execution in:
146+
- GitHub repository → Actions tab
147+
- Look for detailed logs in failed steps
148+
- Review test output for specific failures
149+
150+
## Version Management
151+
152+
The SDK uses semantic versioning:
153+
- `0.x.y` - Pre-1.0 development versions
154+
- `1.x.y` - Stable API versions
155+
156+
When publishing:
157+
1. Update version in `rust/Cargo.toml`
158+
2. Update documentation if needed
159+
3. Create tag with format `rust-vX.Y.Z`
160+
4. Push tag to trigger publishing workflow
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: Publish Rust SDK to crates.io
2+
3+
on:
4+
release:
5+
types: [published]
6+
push:
7+
tags:
8+
- 'rust-v*' # Triggers on tags like rust-v0.1.0, rust-v1.0.0, etc.
9+
10+
env:
11+
CARGO_TERM_COLOR: always
12+
13+
jobs:
14+
publish:
15+
name: Publish to crates.io
16+
runs-on: ubuntu-latest
17+
defaults:
18+
run:
19+
working-directory: ./rust
20+
21+
steps:
22+
- name: Checkout code
23+
uses: actions/checkout@v4
24+
25+
- name: Install Rust toolchain
26+
uses: actions-rs/toolchain@v1
27+
with:
28+
toolchain: stable
29+
profile: minimal
30+
override: true
31+
components: rustfmt, clippy
32+
33+
- name: Cache cargo registry
34+
uses: actions/cache@v3
35+
with:
36+
path: |
37+
~/.cargo/registry
38+
~/.cargo/git
39+
target
40+
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
41+
restore-keys: |
42+
${{ runner.os }}-cargo-
43+
44+
- name: Check formatting
45+
run: cargo fmt -- --check
46+
47+
- name: Build package
48+
run: cargo build --release --all-features
49+
50+
- name: Run tests
51+
run: cargo test --all-features
52+
53+
- name: Run tests without default features
54+
run: cargo test --no-default-features
55+
56+
- name: Run tests with individual features
57+
run: |
58+
cargo test --features pyg
59+
cargo test --features prepay
60+
cargo test --features stream
61+
62+
- name: Package crate
63+
run: cargo package
64+
65+
- name: Publish to crates.io
66+
run: cargo publish --token ${{ secrets.CRATES_TOKEN }}
67+
env:
68+
CARGO_REGISTRY_TOKEN: ${{ secrets.CRATES_TOKEN }}

.github/workflows/rust-ci.yml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: Rust SDK CI
2+
3+
on:
4+
push:
5+
branches: [ main, develop ]
6+
paths:
7+
- 'rust/**'
8+
- '.github/workflows/rust-ci.yml'
9+
pull_request:
10+
branches: [ main, develop ]
11+
paths:
12+
- 'rust/**'
13+
- '.github/workflows/rust-ci.yml'
14+
15+
env:
16+
CARGO_TERM_COLOR: always
17+
18+
jobs:
19+
test:
20+
name: Test Rust SDK
21+
runs-on: ubuntu-latest
22+
defaults:
23+
run:
24+
working-directory: ./rust
25+
26+
strategy:
27+
matrix:
28+
rust: [stable, beta]
29+
30+
steps:
31+
- name: Checkout code
32+
uses: actions/checkout@v4
33+
34+
- name: Install Rust toolchain
35+
uses: actions-rs/toolchain@v1
36+
with:
37+
toolchain: ${{ matrix.rust }}
38+
profile: minimal
39+
override: true
40+
components: rustfmt, clippy
41+
42+
- name: Cache cargo registry
43+
uses: actions/cache@v3
44+
with:
45+
path: |
46+
~/.cargo/registry
47+
~/.cargo/git
48+
target
49+
key: ${{ runner.os }}-${{ matrix.rust }}-cargo-${{ hashFiles('**/Cargo.lock') }}
50+
restore-keys: |
51+
${{ runner.os }}-${{ matrix.rust }}-cargo-
52+
53+
- name: Check formatting
54+
run: cargo fmt -- --check
55+
56+
- name: Build with no features
57+
run: cargo build --no-default-features
58+
59+
- name: Build with all features
60+
run: cargo build --all-features
61+
62+
- name: Test with no features
63+
run: cargo test --no-default-features
64+
65+
- name: Test with all features
66+
run: cargo test --all-features
67+
68+
- name: Test individual features
69+
run: |
70+
cargo test --features pyg
71+
cargo test --features prepay
72+
cargo test --features stream
73+
74+
- name: Check package can be built
75+
run: cargo package --allow-dirty

Cargo.lock

Lines changed: 36 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ members = [
44
"programs/svmai-token",
55
"programs/agent-registry",
66
"programs/mcp-server-registry",
7-
"programs/common"
7+
"programs/common",
8+
"rust"
89
]
910

1011
[workspace.dependencies]
117 KB
Binary file not shown.

0 commit comments

Comments
 (0)