Skip to content

Commit 76b8d2f

Browse files
Merge pull request #21 from hongjr03/master
build: add ci workflow for building and testing with rust and wasm
2 parents 0a8af37 + 31c7b37 commit 76b8d2f

File tree

5 files changed

+318
-1
lines changed

5 files changed

+318
-1
lines changed

.github/workflows/ci.yml

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [master]
6+
pull_request:
7+
branches: [master]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v4
15+
16+
- name: Install Rust
17+
uses: dtolnay/rust-toolchain@stable
18+
19+
- name: Install wasm32 target
20+
run: rustup target add wasm32-unknown-unknown
21+
22+
- name: Install wasm-pack
23+
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
24+
25+
- name: Setup Node.js
26+
uses: actions/setup-node@v4
27+
with:
28+
node-version: "20"
29+
cache: "npm"
30+
cache-dependency-path: frontend/package-lock.json
31+
32+
- name: Cache Cargo registry
33+
uses: actions/cache@v4
34+
with:
35+
path: ~/.cargo/registry
36+
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
37+
restore-keys: |
38+
${{ runner.os }}-cargo-registry-
39+
40+
- name: Cache Cargo index
41+
uses: actions/cache@v4
42+
with:
43+
path: ~/.cargo/git
44+
key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}
45+
restore-keys: |
46+
${{ runner.os }}-cargo-index-
47+
48+
- name: Cache target directory
49+
uses: actions/cache@v4
50+
with:
51+
path: target
52+
key: ${{ runner.os }}-target-${{ hashFiles('**/Cargo.lock') }}
53+
restore-keys: |
54+
${{ runner.os }}-target-
55+
56+
- name: Install frontend dependencies
57+
run: cd frontend && npm ci
58+
59+
- name: Build frontend
60+
run: cd frontend && npm run build
61+
62+
- name: Run tests
63+
run: cargo test
64+
65+
- name: Test WASM functionality
66+
run: wasm-pack test --node --no-default-features
67+
68+
- name: Build for WASM
69+
run: wasm-pack build --target web --no-default-features --out-dir pkg
70+
71+
- name: Upload WASM package
72+
uses: actions/upload-artifact@v4
73+
with:
74+
name: oxdraw-wasm-package
75+
path: pkg/
76+
77+
- name: Upload Rust binary
78+
uses: actions/upload-artifact@v4
79+
with:
80+
name: oxdraw-binary
81+
path: target/debug/oxdraw
82+
83+
- name: Upload frontend build
84+
uses: actions/upload-artifact@v4
85+
with:
86+
name: frontend-build
87+
path: frontend/out/

Cargo.lock

Lines changed: 169 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: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ keywords = ["diagram", "svg", "visualization", "mermaid", "render"]
1818

1919
[lib]
2020
name = "oxdraw"
21+
crate-type = ["cdylib", "rlib"]
2122
path = "src/lib.rs"
2223

2324
[[bin]]
@@ -48,6 +49,9 @@ default = ["server"]
4849
server = ["axum", "tokio", "tower-http", "tower"]
4950

5051
[dev-dependencies]
51-
assert_cmd = "2"
52+
wasm-bindgen-test = "0.3"
53+
54+
[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies]
55+
assert_cmd = { version = "2", default-features = false }
5256
predicates = "3"
5357
tempfile = "3"

tests/cli.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![cfg(not(target_arch = "wasm32"))]
2+
13
use std::fs;
24
use std::path::PathBuf;
35

0 commit comments

Comments
 (0)