Skip to content

Commit 0728619

Browse files
authored
Merge pull request #3 from AstraBert/chore/add-tests
chore: tests and CI
2 parents 81f7a00 + 40c822c commit 0728619

24 files changed

+816
-72
lines changed

.github/workflows/build.yaml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: CI - Build
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- src/*.rs
7+
- Cargo.toml
8+
9+
env:
10+
CARGO_TERM_COLOR: always
11+
12+
jobs:
13+
build:
14+
name: Build
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v4
19+
20+
- name: Set up Rust
21+
uses: dtolnay/rust-toolchain@stable
22+
23+
- name: Cache cargo registry
24+
uses: actions/cache@v4
25+
with:
26+
path: ~/.cargo/registry
27+
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
28+
29+
- name: Cache cargo index
30+
uses: actions/cache@v4
31+
with:
32+
path: ~/.cargo/git
33+
key: ${{ runner.os }}-cargo-git-${{ hashFiles('**/Cargo.lock') }}
34+
35+
- name: Cache cargo build
36+
uses: actions/cache@v4
37+
with:
38+
path: target
39+
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}
40+
41+
- name: Build
42+
run: make build

.github/workflows/lint.yaml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Lint
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- src/*.rs
7+
- Cargo.toml
8+
env:
9+
CARGO_TERM_COLOR: always
10+
11+
jobs:
12+
clippy:
13+
name: Clippy
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v4
18+
19+
- name: Install Rust toolchain
20+
uses: dtolnay/rust-toolchain@stable
21+
with:
22+
components: clippy
23+
24+
- name: Cache cargo registry
25+
uses: actions/cache@v4
26+
with:
27+
path: |
28+
~/.cargo/registry
29+
~/.cargo/git
30+
target
31+
key: ${{ runner.os }}-cargo-clippy-${{ hashFiles('**/Cargo.lock') }}
32+
33+
- name: Install protoc
34+
uses: taiki-e/install-action@protoc
35+
36+
- name: Run clippy
37+
run: make clippy
38+
39+
format:
40+
name: Format
41+
runs-on: ubuntu-latest
42+
steps:
43+
- name: Checkout code
44+
uses: actions/checkout@v4
45+
46+
- name: Install Rust toolchain
47+
uses: dtolnay/rust-toolchain@stable
48+
with:
49+
components: rustfmt
50+
51+
- name: Check formatting
52+
run: make format-check

.github/workflows/publish.yaml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Publish
2+
on:
3+
push:
4+
tags:
5+
- "v*"
6+
7+
permissions:
8+
contents: read # for checkout
9+
10+
jobs:
11+
release:
12+
name: Release
13+
runs-on: ubuntu-latest
14+
permissions:
15+
contents: write # to be able to publish a GitHub release
16+
issues: write # to be able to comment on released issues
17+
pull-requests: write # to be able to comment on released pull requests
18+
id-token: write # to enable use of OIDC for npm provenance
19+
steps:
20+
- name: Checkout
21+
uses: actions/checkout@v4
22+
with:
23+
fetch-depth: 0
24+
25+
- name: Install Rust toolchain
26+
uses: dtolnay/rust-toolchain@stable
27+
28+
- name: Cache cargo registry
29+
uses: actions/cache@v4
30+
with:
31+
path: |
32+
~/.cargo/registry
33+
~/.cargo/git
34+
target
35+
key: ${{ runner.os }}-cargo-clippy-${{ hashFiles('**/Cargo.lock') }}
36+
37+
- name: Login to cargo
38+
run: cargo login <<< $CARGO_API_TOKEN
39+
env:
40+
CARGO_API_TOKEN: ${{ secrets.CARGO_API_TOKEN }}
41+
42+
- name: Publish to crates
43+
run: cargo publish
44+
env:
45+
CARGO_API_TOKEN: ${{ secrets.CARGO_API_TOKEN }}

.github/workflows/test.yaml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Test
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- src/*.rs
7+
- Cargo.toml
8+
9+
env:
10+
CARGO_TERM_COLOR: always
11+
12+
jobs:
13+
test:
14+
name: Test on ${{ matrix.os }}
15+
runs-on: ${{ matrix.os }}
16+
strategy:
17+
matrix:
18+
os: [ubuntu-latest, windows-latest, macos-latest]
19+
rust: [stable]
20+
21+
steps:
22+
- name: Checkout code
23+
uses: actions/checkout@v4
24+
25+
- name: Install Rust toolchain
26+
uses: dtolnay/rust-toolchain@master
27+
with:
28+
toolchain: ${{ matrix.rust }}
29+
30+
- name: Cache cargo registry
31+
uses: actions/cache@v4
32+
with:
33+
path: |
34+
~/.cargo/registry
35+
~/.cargo/git
36+
target
37+
key: ${{ runner.os }}-cargo-test-${{ hashFiles('**/Cargo.lock') }}
38+
restore-keys: |
39+
${{ runner.os }}-cargo-
40+
41+
- name: Install protoc
42+
uses: taiki-e/install-action@protoc
43+
44+
- name: Run tests
45+
run: make test

Cargo.lock

Lines changed: 2 additions & 1 deletion
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
@@ -1,6 +1,6 @@
11
[package]
22
name = "rag-rs"
3-
version = "0.2.0-alpha"
3+
version = "0.2.1"
44
edition = "2024"
55
license-file = "LICENSE"
66
readme = "README.md"
@@ -28,3 +28,4 @@ tower-http = {version = "0.6.2", features = ["fs", "cors"]}
2828
async-openai = { version = "0.32.3", features = ["responses", "chat-completion"] }
2929
pdf-extract = "0.10.0"
3030
cacache = { version = "13.1.0", features = ["tokio-runtime", "mmap"], default-features = false }
31+
tower = "0.5.3"

Makefile

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
.PHONY: build test clippy clippy-fix format format-check version-bump npm-publish
2+
3+
build:
4+
cargo build --target-dir target/
5+
6+
test:
7+
$(info ****************** running tests ******************)
8+
rm -rf .rag-rs-cache/ && cargo test
9+
10+
clippy:
11+
$(info ****************** running clippy in check mode ******************)
12+
cargo clippy
13+
14+
clippy-fix:
15+
$(info ****************** running clippy in fix mode ******************)
16+
cargo clippy --fix --bin "rag-rs"
17+
18+
format:
19+
$(info ****************** running rustfmt in fix mode ******************)
20+
cargo fmt
21+
22+
format-check:
23+
$(info ****************** running rustfmt in check mode ******************)
24+
cargo fmt --check
25+
26+
version-bump:
27+
$(info ****************** bumping version in package.json and Cargo.toml ******************)
28+
python3 scripts/version_bump.py
29+
30+
npm-publish:
31+
$(info ****************** login and publish to npm ******************)
32+
$(info ****************** meant for manual usage ******************)
33+
bash scripts/login_and_publish_to_npm.sh

README.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ Install with cargo:
2727
cargo install rag-rs
2828
```
2929

30+
Install with npm:
31+
32+
```bash
33+
npm install @cle-does-things/rag-rs@latest
34+
```
35+
3036
### `load` command
3137

3238
Parse, chunk and embed the documents in a given directory, and upload them to a vector store.
@@ -125,7 +131,10 @@ rag-rs --qdrant-url http://localhost:6334 \
125131
To reach the first stable version, this software will first:
126132

127133
- [X] Add a caching layer (v0.2.0-alpha)
128-
- [ ] Introduce thorough testing
129-
- [ ] Add a programmatic API along with the CLI app, possibly both in Rust and Python
130-
- [ ] Add an NPM-installable version
131-
- [ ] Add support for more text-based file formats, and possibly for more unstructured file formats
134+
- [X] Introduce thorough testing (v0.2.1)
135+
- [X] Add an NPM-installable version (v0.2.1)
136+
137+
Moreover, for future releases, there will be:
138+
139+
- [ ] A programmatic API along with the CLI app, possibly both in Rust and Python
140+
- [ ] Support for more text-based file formats, and possibly for more unstructured file formats

package.json

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"name": "@cle-does-things/rag-rs",
3+
"version": "0.2.1",
4+
"description": "A Rust-native implementation of the RAG stack",
5+
"main": "start.js",
6+
"directories": {
7+
"test": "tests"
8+
},
9+
"scripts": {
10+
"test": "echo \"Error: no test specified\" && exit 1",
11+
"postinstall": "node ./pre-install.js",
12+
"uninstall": "node ./uninstall.js"
13+
},
14+
"repository": {
15+
"type": "git",
16+
"url": "https://github.com/AstraBert/rag-rs.git"
17+
},
18+
"keywords": [
19+
"rag",
20+
"llm",
21+
"ai",
22+
"rust"
23+
],
24+
"license": "ISC",
25+
"bugs": {
26+
"url": "https://github.com/AstraBert/rag-rs/issues"
27+
},
28+
"files": [
29+
"pre-install.js",
30+
"start.js",
31+
"uninstall.js",
32+
"README.md",
33+
"LICENSE"
34+
],
35+
"publishConfig": {
36+
"access": "public"
37+
}
38+
}

pre-install.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/usr/bin/env node
2+
3+
const fs = require("fs");
4+
const path = require("path");
5+
const { exec } = require("child_process");
6+
const { homedir } = require("os");
7+
8+
const cargoDir = path.join(homedir(), ".cargo");
9+
10+
// check if directory exists
11+
if (fs.existsSync(cargoDir)) {
12+
// console.log("Cargo found.");
13+
} else {
14+
const setCargo = 'PATH="/$HOME/.cargo/bin:${PATH}"';
15+
console.log("Installing deps [cargo].");
16+
17+
exec(
18+
`curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y && ${setCargo}`,
19+
(error) => {
20+
if (error) {
21+
console.log(
22+
"curl failed! Curl may not be installed on the OS. View https://curl.se/download.html to install.",
23+
);
24+
console.log(error);
25+
}
26+
},
27+
);
28+
}
29+
30+
const features = process.env.npm_config_features
31+
? `--features ${process.env.npm_config_features.replace(",", " ")}`
32+
: "";
33+
34+
console.log(`Installing and compiling rag-rs 0.2.1 ${features} ...`);
35+
exec(
36+
`cargo install rag-rs --vers 0.2.1 ${features}`,
37+
(error, stdout, stderr) => {
38+
console.log(stdout);
39+
if (error || stderr) {
40+
console.log(error || stderr);
41+
} else {
42+
console.log("install finished!");
43+
}
44+
},
45+
);

0 commit comments

Comments
 (0)