chore(tests): add wasm tests to CI (#83) #55
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: PR Check | |
on: | |
pull_request: | |
push: | |
branches: [main] | |
jobs: | |
fmt: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Rust | |
uses: actions-rs/toolchain@v1 | |
with: | |
profile: minimal | |
toolchain: stable | |
components: rustfmt | |
override: true | |
- name: Check formatting | |
run: cargo fmt --check | |
clippy: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Rust | |
uses: actions-rs/toolchain@v1 | |
with: | |
profile: minimal | |
toolchain: stable | |
components: clippy | |
override: true | |
- name: Cache | |
uses: Swatinem/rust-cache@v2 | |
- name: Lint with Clippy | |
run: cargo clippy --workspace --all-features -- -D warnings -A clippy::needless_lifetimes | |
test: | |
strategy: | |
matrix: | |
crate: | |
[pubky, pubky-common, pubky-homeserver, pubky-testnet, http-relay] | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Rust | |
uses: actions-rs/toolchain@v1 | |
with: | |
profile: minimal | |
toolchain: stable | |
override: true | |
- name: Install Nextest | |
uses: taiki-e/install-action@nextest | |
- name: Cache | |
uses: Swatinem/rust-cache@v2 | |
- name: Run doctests and nextest | |
run: | | |
set -e | |
# nextest does not support doctests yet. | |
cargo test --doc -p ${{ matrix.crate }} --all-features | |
if cargo nextest run \ | |
-p ${{ matrix.crate }} \ | |
--all-features \ | |
--test-threads num-cpus \ | |
--retries 2 \ | |
--no-fail-fast \ | |
--verbose; then | |
echo "Tests passed for ${{ matrix.crate }}" | |
else | |
if [ $? -eq 4 ]; then | |
echo "No tests found for ${{ matrix.crate }}" | |
exit 0 | |
else | |
echo "Tests failed for ${{ matrix.crate }}" | |
exit 1 | |
fi | |
fi | |
wasm-test: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Setup Rust | |
uses: actions-rs/toolchain@v1 | |
with: | |
profile: minimal | |
toolchain: stable | |
target: wasm32-unknown-unknown | |
override: true | |
- name: Setup Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: "22" | |
- name: Install wasm-pack | |
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh | |
- name: Cache | |
uses: Swatinem/rust-cache@v2 | |
- name: Build WASM | |
working-directory: pubky/pkg | |
run: | | |
npm install | |
npm run build | |
- name: Run the testnet | |
working-directory: pubky/pkg | |
run: npm run testnet > testnet.log 2>&1 & | |
- name: Wait for testnet homeserver | |
run: | | |
until nc -zv 127.0.0.1 6286; do | |
echo "Waiting for testnet homeserver to be ready..." | |
sleep 1 | |
done | |
- name: Run Tests (only node-js) | |
working-directory: pubky/pkg | |
# runing only `test-nodjs` and not browser because of weird `exit` behavior | |
run: npm run test-nodejs | |
- name: Show testnet logs if tests fail | |
working-directory: pubky/pkg | |
if: failure() | |
run: cat testnet.log |