Skip to content

Commit af2c033

Browse files
authored
Merge pull request #1 from qianmoQ/dev
feat (ci): 增加代码检查 CI
2 parents ea73590 + af334a8 commit af2c033

7 files changed

Lines changed: 258 additions & 13 deletions

File tree

.github/workflows/pre-check.yml

Lines changed: 242 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,242 @@
1+
name: Pre Check
2+
3+
on:
4+
push:
5+
branches: [ dev ]
6+
pull_request:
7+
branches: [ dev ]
8+
9+
env:
10+
CARGO_TERM_COLOR: always
11+
NODE_VERSION: '18'
12+
RUST_VERSION: '1.85.0'
13+
PNPM_VERSION: '8'
14+
15+
jobs:
16+
# 前端检查和测试
17+
frontend:
18+
name: Frontend Check
19+
runs-on: ubuntu-latest
20+
21+
steps:
22+
- name: Checkout repository
23+
uses: actions/checkout@v4
24+
25+
- name: Setup Node.js
26+
uses: actions/setup-node@v4
27+
with:
28+
node-version: ${{ env.NODE_VERSION }}
29+
30+
- name: Setup pnpm
31+
uses: pnpm/action-setup@v2
32+
with:
33+
version: ${{ env.PNPM_VERSION }}
34+
35+
- name: Get pnpm store directory
36+
id: pnpm-cache
37+
shell: bash
38+
run: |
39+
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
40+
41+
- name: Setup pnpm cache
42+
uses: actions/cache@v3
43+
with:
44+
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
45+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
46+
restore-keys: |
47+
${{ runner.os }}-pnpm-store
48+
49+
- name: Install dependencies
50+
run: |
51+
if [ -f "pnpm-lock.yaml" ]; then
52+
pnpm install --frozen-lockfile
53+
else
54+
pnpm install
55+
fi
56+
57+
- name: Type check
58+
run: pnpm vue-tsc --noEmit
59+
60+
- name: Build frontend
61+
run: pnpm build
62+
63+
# 后端检查和测试
64+
backend:
65+
name: Backend Check
66+
runs-on: ${{ matrix.platform }}
67+
68+
strategy:
69+
fail-fast: false
70+
matrix:
71+
platform: [ macos-latest, windows-latest ]
72+
73+
steps:
74+
- name: Checkout repository
75+
uses: actions/checkout@v4
76+
77+
- name: Setup Rust
78+
uses: dtolnay/rust-toolchain@stable
79+
with:
80+
toolchain: ${{ env.RUST_VERSION }}
81+
components: rustfmt, clippy
82+
83+
- name: Rust Cache
84+
uses: Swatinem/rust-cache@v2
85+
with:
86+
workspaces: src-tauri
87+
88+
- name: Rust format check
89+
run: cargo fmt --all --manifest-path src-tauri/Cargo.toml -- --check
90+
91+
- name: Rust clippy check
92+
run: cargo clippy --manifest-path src-tauri/Cargo.toml --all-targets --all-features -- -D warnings
93+
94+
- name: Build backend
95+
run: cargo build --manifest-path src-tauri/Cargo.toml
96+
97+
- name: Run backend tests
98+
run: cargo test --manifest-path src-tauri/Cargo.toml
99+
100+
# 完整应用构建测试
101+
build:
102+
name: Build Application
103+
needs: [ frontend, backend ]
104+
runs-on: ${{ matrix.platform }}
105+
106+
strategy:
107+
fail-fast: false
108+
matrix:
109+
platform: [ macos-latest, windows-latest ]
110+
111+
steps:
112+
- name: Checkout repository
113+
uses: actions/checkout@v4
114+
115+
- name: Setup Node.js
116+
uses: actions/setup-node@v4
117+
with:
118+
node-version: ${{ env.NODE_VERSION }}
119+
120+
- name: Setup pnpm
121+
uses: pnpm/action-setup@v2
122+
with:
123+
version: ${{ env.PNPM_VERSION }}
124+
125+
- name: Setup Rust
126+
uses: dtolnay/rust-toolchain@stable
127+
with:
128+
toolchain: ${{ env.RUST_VERSION }}
129+
130+
- name: Rust Cache
131+
uses: Swatinem/rust-cache@v2
132+
with:
133+
workspaces: src-tauri
134+
135+
- name: Install frontend dependencies
136+
run: |
137+
if [ -f "pnpm-lock.yaml" ]; then
138+
pnpm install --frozen-lockfile
139+
else
140+
pnpm install
141+
fi
142+
shell: bash
143+
144+
- name: Build application
145+
run: pnpm tauri build
146+
147+
- name: Upload build artifacts (macOS)
148+
if: matrix.platform == 'macos-latest'
149+
uses: actions/upload-artifact@v4
150+
with:
151+
name: macos-build
152+
path: src-tauri/target/release/bundle/
153+
retention-days: 7
154+
155+
- name: Upload build artifacts (Windows)
156+
if: matrix.platform == 'windows-latest'
157+
uses: actions/upload-artifact@v4
158+
with:
159+
name: windows-build
160+
path: src-tauri/target/release/bundle/
161+
retention-days: 7
162+
163+
# 代码质量检查
164+
quality:
165+
name: Code Quality
166+
runs-on: ubuntu-latest
167+
168+
steps:
169+
- name: Checkout repository
170+
uses: actions/checkout@v4
171+
with:
172+
fetch-depth: 0 # 获取完整历史,用于 SonarCloud
173+
174+
- name: Setup Node.js
175+
uses: actions/setup-node@v4
176+
with:
177+
node-version: ${{ env.NODE_VERSION }}
178+
179+
- name: Setup pnpm
180+
uses: pnpm/action-setup@v2
181+
with:
182+
version: ${{ env.PNPM_VERSION }}
183+
184+
- name: Setup Rust
185+
uses: dtolnay/rust-toolchain@stable
186+
with:
187+
toolchain: ${{ env.RUST_VERSION }}
188+
189+
- name: Install dependencies
190+
run: |
191+
if [ -f "pnpm-lock.yaml" ]; then
192+
pnpm install --frozen-lockfile
193+
else
194+
pnpm install
195+
fi
196+
197+
- name: Generate coverage report
198+
run: |
199+
pnpm vitest run --coverage || true
200+
continue-on-error: true
201+
202+
- name: Check bundle size
203+
run: pnpm build && du -sh dist/
204+
205+
- name: Security audit (npm)
206+
run: pnpm audit || true
207+
continue-on-error: true
208+
209+
- name: Security audit (cargo)
210+
run: |
211+
cargo install cargo-audit
212+
cargo audit --file src-tauri/Cargo.lock || true
213+
continue-on-error: true
214+
215+
# 依赖检查
216+
dependencies:
217+
name: Dependencies Check
218+
runs-on: ubuntu-latest
219+
220+
steps:
221+
- name: Checkout repository
222+
uses: actions/checkout@v4
223+
224+
- name: Setup Node.js
225+
uses: actions/setup-node@v4
226+
with:
227+
node-version: ${{ env.NODE_VERSION }}
228+
229+
- name: Setup pnpm
230+
uses: pnpm/action-setup@v2
231+
with:
232+
version: ${{ env.PNPM_VERSION }}
233+
234+
- name: Check outdated dependencies
235+
run: |
236+
pnpm outdated || true
237+
continue-on-error: true
238+
239+
- name: Check for duplicated dependencies
240+
run: |
241+
pnpm why --recursive || true
242+
continue-on-error: true

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "codeforge",
33
"private": true,
4-
"version": "2025.0.0",
4+
"version": "25.0.0",
55
"type": "module",
66
"scripts": {
77
"dev": "vite",

src-tauri/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src-tauri/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "CodeForge"
3-
version = "2025.0.0"
3+
version = "25.0.0"
44
description = "CodeForge 是一款轻量级、高性能的桌面代码执行器,专为开发者、学生和编程爱好者设计。"
55
authors = ["devlive-community"]
66
edition = "2024"

src-tauri/src/main.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use plugins::{CodeExecutionRequest, ExecutionResult, LanguageInfo, PluginManager
99
use std::fs;
1010
use std::process::{Command, Stdio};
1111
use std::time::{SystemTime, UNIX_EPOCH};
12-
use tauri::{Manager, State};
12+
use tauri::State;
1313
use tokio::sync::Mutex;
1414
use uuid::Uuid;
1515

@@ -22,7 +22,6 @@ async fn execute_code(
2222
request: CodeExecutionRequest,
2323
history: State<'_, ExecutionHistory>,
2424
plugin_manager: State<'_, PluginManagerState>,
25-
app_handle: tauri::AppHandle,
2625
) -> Result<ExecutionResult, String> {
2726
let manager = plugin_manager.lock().await;
2827
let plugin = manager
@@ -152,10 +151,9 @@ async fn get_info(
152151

153152
if let Ok(version_out) = version_output {
154153
if version_out.status.success() {
155-
// 获取路径信息 - 只处理 Python
156154
let path_result = Command::new(cmd)
157155
.arg("-c")
158-
.arg(&plugin.get_path_command())
156+
.arg(plugin.get_path_command())
159157
.output();
160158

161159
let version = String::from_utf8_lossy(&version_out.stdout)
@@ -166,10 +164,10 @@ async fn get_info(
166164
if path_out.status.success() {
167165
String::from_utf8_lossy(&path_out.stdout).trim().to_string()
168166
} else {
169-
format!("Command found but path unavailable")
167+
"Command found but path unavailable".to_string()
170168
}
171169
} else {
172-
format!("Path detection failed")
170+
"Path detection failed".to_string()
173171
};
174172

175173
return Ok(LanguageInfo {

src-tauri/src/plugins/manager.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::{python2::Python2Plugin, python3::Python3Plugin, LanguagePlugin};
1+
use super::{LanguagePlugin, python2::Python2Plugin, python3::Python3Plugin};
22
use std::collections::HashMap;
33

44
pub struct PluginManager {
@@ -15,26 +15,30 @@ impl PluginManager {
1515
Self { plugins }
1616
}
1717

18-
pub fn get_plugin(&self, language: &str) -> Option<&Box<dyn LanguagePlugin>> {
19-
self.plugins.get(language)
18+
pub fn get_plugin(&self, language: &str) -> Option<&dyn LanguagePlugin> {
19+
self.plugins.get(language).map(|plugin| plugin.as_ref())
2020
}
2121

2222
pub fn get_supported_languages(&self) -> Vec<String> {
2323
self.plugins.keys().cloned().collect()
2424
}
2525

26+
#[allow(dead_code)]
2627
pub fn register_plugin(&mut self, language: String, plugin: Box<dyn LanguagePlugin>) {
2728
self.plugins.insert(language, plugin);
2829
}
2930

31+
#[allow(dead_code)]
3032
pub fn unregister_plugin(&mut self, language: &str) -> Option<Box<dyn LanguagePlugin>> {
3133
self.plugins.remove(language)
3234
}
3335

36+
#[allow(dead_code)]
3437
pub fn is_language_supported(&self, language: &str) -> bool {
3538
self.plugins.contains_key(language)
3639
}
3740

41+
#[allow(dead_code)]
3842
pub fn get_plugin_info(&self, language: &str) -> Option<PluginInfo> {
3943
self.get_plugin(language).map(|plugin| PluginInfo {
4044
name: plugin.get_language_name().to_string(),
@@ -47,6 +51,7 @@ impl PluginManager {
4751
})
4852
}
4953

54+
#[allow(dead_code)]
5055
pub fn get_all_plugin_info(&self) -> Vec<PluginInfo> {
5156
self.plugins
5257
.values()

src-tauri/tauri.conf.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"$schema": "https://schema.tauri.app/config/2",
33
"productName": "CodeForge",
4-
"version": "2025.0.0",
4+
"version": "25.0.0",
55
"identifier": "org.devlive.codeforge",
66
"build": {
77
"beforeDevCommand": "pnpm dev",

0 commit comments

Comments
 (0)