Skip to content

Commit 5915027

Browse files
committed
ci: add unit test ci
1 parent 45cf4e2 commit 5915027

File tree

1 file changed

+74
-61
lines changed

1 file changed

+74
-61
lines changed

.github/workflows/ci.yml

+74-61
Original file line numberDiff line numberDiff line change
@@ -175,77 +175,90 @@ jobs:
175175
- name: Prepare sidecar and resources
176176
run: pnpm check
177177

178-
- name: Build Tauri
179-
run: pnpm tauri build
178+
- name: Build Backend
179+
run: cargo build --release --manifest-path backend/Cargo.toml
180180
env:
181181
NODE_OPTIONS: '--max_old_space_size=4096'
182-
# 以后完善了新的测试套件后再添加
183-
# test_unit:
184-
# name: Unit Test
185-
# needs: lint
186-
# # we want to run on the latest linux environment
187-
# runs-on: ubuntu-latest
188182

189-
# # the steps our job runs **in order**
190-
# steps:
191-
# # checkout the code on the workflow runner
192-
# - uses: actions/checkout@v4
183+
test_unit:
184+
name: Unit Test
185+
needs: lint
186+
# we want to run on the latest linux environment
187+
strategy:
188+
matrix:
189+
os:
190+
- ubuntu-latest
191+
- macos-latest
192+
- windows-latest
193+
runs-on: ${{ matrix.os }}
193194

194-
# # install system dependencies that Tauri needs to compile on Linux.
195-
# # note the extra dependencies for `tauri-driver` to run which are: `webkit2gtk-driver` and `xvfb`
196-
# - name: Tauri dependencies
197-
# run: >-
198-
# sudo apt-get update &&
199-
# sudo apt-get install -y
200-
# libgtk-3-dev
201-
# libayatana-appindicator3-dev
202-
# libwebkit2gtk-4.0-dev
203-
# webkit2gtk-driver
204-
# xvfb
195+
# the steps our job runs **in order**
196+
steps:
197+
# checkout the code on the workflow runner
198+
- uses: actions/checkout@v4
205199

206-
# # install the latest Rust stable
207-
# - name: Rust stable
208-
# run: rustup toolchain install stable --profile minimal && rustup default stable
209-
# - uses: Swatinem/rust-cache@v2
210-
# with:
211-
# workspaces: "./backend/"
212-
# prefix-key: "rust-stable"
213-
# shared-key: "ci"
214-
# save-if: ${{ github.ref == 'refs/heads/main' || github.ref == 'refs/heads/dev' }}
200+
# install system dependencies that Tauri needs to compile on Linux.
201+
# note the extra dependencies for `tauri-driver` to run which are: `webkit2gtk-driver` and `xvfb`
202+
- name: Tauri dependencies
203+
if: startsWith(matrix.os, 'ubuntu-')
204+
run: >-
205+
sudo apt-get update &&
206+
sudo apt-get install -y
207+
libgtk-3-dev
208+
libayatana-appindicator3-dev
209+
libwebkit2gtk-4.1-dev
210+
librsvg2-dev
211+
libxdo-dev
212+
webkit2gtk-driver
213+
xvfb
215214
216-
# - name: Install Node.js
217-
# uses: actions/setup-node@v4
218-
# with:
219-
# node-version: 20
215+
- uses: maxim-lobanov/setup-xcode@v1
216+
if: startsWith(matrix.os, 'macos-')
217+
with:
218+
xcode-version: 'latest-stable'
220219

221-
# - uses: pnpm/action-setup@v2
222-
# name: Install pnpm
223-
# with:
224-
# version: 8
225-
# run_install: false
220+
- name: Install Node.js
221+
uses: actions/setup-node@v4
222+
with:
223+
node-version: 22
226224

227-
# - name: Get pnpm store directory
228-
# shell: bash
229-
# run: |
230-
# echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
225+
- uses: actions/cache@v4
226+
name: Cache Rust dependencies
227+
with:
228+
path: |
229+
~/.cargo/bin/
230+
~/.cargo/registry/index/
231+
~/.cargo/registry/cache/
232+
~/.cargo/git/db/
233+
target/
234+
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
231235

232-
# - uses: actions/cache@v4
233-
# name: Setup pnpm cache
234-
# with:
235-
# path: ${{ env.STORE_PATH }}
236-
# key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
237-
# restore-keys: |
238-
# ${{ runner.os }}-pnpm-store-
236+
- uses: pnpm/action-setup@v4
237+
name: Install pnpm
238+
with:
239+
run_install: false
239240

240-
# - name: Install dependencies
241-
# run: pnpm install
242-
# - name: Prepare fronend
243-
# run: pnpm web:build # Build frontend
244-
# - name: Prepare sidecar and resources
245-
# run: pnpm check
246-
# - name: Test
247-
# # run: pnpm test:unit && pnpm test:backend
248-
# run: pnpm test:backend
241+
- name: Get pnpm store directory
242+
shell: bash
243+
run: |
244+
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
245+
246+
- uses: actions/cache@v4
247+
name: Setup pnpm cache
248+
with:
249+
path: ${{ env.STORE_PATH }}
250+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
251+
restore-keys: |
252+
${{ runner.os }}-pnpm-store-
253+
254+
- name: Install dependencies
255+
run: pnpm install --no-frozen-lockfile
256+
257+
- name: Prepare sidecar and resources
258+
run: pnpm check
259+
260+
- name: Test
261+
run: pnpm test
249262

250263
# test_e2e:
251264
# # the display name of the test job

0 commit comments

Comments
 (0)