feat: 添加 CI/CD 工作流配置

This commit is contained in:
ViperEkura 2026-03-29 12:26:40 +08:00
parent dd47f9db3d
commit 7da142fccb
3 changed files with 116 additions and 6 deletions

99
.github/workflows/ci.yml vendored Normal file
View File

@ -0,0 +1,99 @@
name: CI
on:
push:
branches: [ main, master ]
pull_request:
branches: [ main, master ]
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.12']
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e .[test]
# Install frontend dependencies for potential frontend tests (optional)
cd frontend && npm ci && cd ..
# 统一配置生成,用于后端测试(与前端构建共享相同配置)
- name: Create config.yml for CI
run: |
cat > config.yml << 'EOF'
backend_port: 3000
frontend_port: 4000
max_iterations: 5
sub_agent:
max_iterations: 3
max_tokens: 4096
max_agents: 5
max_concurrency: 3
models:
- id: dummy
name: Dummy
api_url: https://api.example.com
api_key: dummy-key
default_model: dummy
db_type: sqlite
db_sqlite_file: ":memory:"
workspace_root: ./workspaces
EOF
- name: Run tests with pytest
run: |
python -m pytest tests/ -v
- name: Upload coverage to Codecov (optional)
uses: codecov/codecov-action@v3
if: matrix.python-version == '3.10' && github.event_name == 'push'
with:
file: ./coverage.xml
fail_ci_if_error: false
build-frontend:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install frontend dependencies
run: |
cd frontend && npm ci
# 统一配置生成,用于前端构建(与后端测试共享相同配置)
- name: Create config.yml for frontend build
run: |
cat > config.yml << 'EOF'
backend_port: 3000
frontend_port: 4000
max_iterations: 5
sub_agent:
max_iterations: 3
max_tokens: 4096
max_agents: 5
max_concurrency: 3
models:
- id: dummy
name: Dummy
api_url: https://api.example.com
api_key: dummy-key
default_model: dummy
db_type: sqlite
db_sqlite_file: ":memory:"
workspace_root: ./workspaces
EOF
- name: Build frontend
run: |
cd frontend && npm run build

3
.gitignore vendored
View File

@ -28,3 +28,6 @@
!frontend/src/**/*.css !frontend/src/**/*.css
!frontend/public/ !frontend/public/
!frontend/public/** !frontend/public/**
# CI / CD
!.github/workflows/*

View File

@ -8,17 +8,25 @@ import { dirname, resolve } from 'path'
const __filename = fileURLToPath(import.meta.url) const __filename = fileURLToPath(import.meta.url)
const __dirname = dirname(__filename) const __dirname = dirname(__filename)
const config = yaml.load( const configPath = resolve(__dirname, '..', 'config.yml');
fs.readFileSync(resolve(__dirname, '..', 'config.yml'), 'utf-8') let config = {};
) try {
config = yaml.load(fs.readFileSync(configPath, 'utf-8'));
} catch (e) {
console.warn(`Config file not found at ${configPath}, using defaults.`);
config = {};
}
const frontend_port = process.env.VITE_FRONTEND_PORT || config.frontend_port || 4000;
const backend_port = process.env.VITE_BACKEND_PORT || config.backend_port || 3000;
export default defineConfig({ export default defineConfig({
plugins: [vue()], plugins: [vue()],
server: { server: {
port: config.frontend_port, port: frontend_port,
proxy: { proxy: {
'/api': { '/api': {
target: `http://localhost:${config.backend_port}`, target: `http://localhost:${backend_port}`,
changeOrigin: true, changeOrigin: true,
}, },
}, },