Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
125 changes: 125 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
name: CI

on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main, develop ]

jobs:
# 端到端测试
e2e-test:
name: End-to-End Tests
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.10'

- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install -y jq curl

- name: Install Python dependencies
run: |
pip install --upgrade pip
pip install -r requirements.txt

- name: Run end-to-end tests
run: |
cd tests
make test-all

- name: Upload test logs on failure
if: failure()
uses: actions/upload-artifact@v4
with:
name: test-logs
path: test-logs/
retention-days: 7

# Python代码质量检查
code-quality:
name: Code Quality
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.10'

- name: Install dependencies
run: |
pip install --upgrade pip
pip install flake8 black

- name: Run flake8
continue-on-error: true
run: |
# 检查Python语法错误和未定义的名称
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# 警告复杂度和其他问题
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics

- name: Check code formatting with black
continue-on-error: true
run: |
black --check --diff .

# 多Python版本兼容性测试
compatibility:
name: Python ${{ matrix.python-version }} Compatibility
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ['3.9', '3.10', '3.11', '3.12']

steps:
- name: Checkout code
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: |
pip install --upgrade pip
pip install -r requirements.txt

- name: Test imports
run: |
python -c "import flask; import celery; import redis; print('All imports successful')"

- name: Verify client script
run: |
python client/submit.py --help || echo "Client script loaded successfully"

# Docker镜像构建测试
docker-build:
name: Docker Build Test
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Build test Docker image
run: |
docker build -f tests/Dockerfile.test -t remoteci-test:latest .

- name: Verify image
run: |
docker images | grep remoteci-test
2 changes: 1 addition & 1 deletion client/test-workspace-isolation.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ workspace2 = generate_workspace_name('myproject', use_uuid=True)

print(f'UUID 1: {workspace1}')
print(f'UUID 2: {workspace2}')
print(f'唯一性: {"✓ 通过" if workspace1 != workspace2 else "✗ 失败"}')
print(f'唯一性: {\"✓ 通过\" if workspace1 != workspace2 else \"✗ 失败\"}')
"
echo

Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

# 核心框架
Flask==3.0.0
celery[redis]==5.3.4
redis==5.0.1
celery[redis]==5.5.3
redis==5.0.1 # celery 5.5.3 支持 redis >=4.5.2,<6.5 (排除4.5.5和5.0.2)

# 任务监控
flower==2.0.1
Expand Down
56 changes: 56 additions & 0 deletions tests/Dockerfile.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Remote CI 测试环境 Dockerfile
FROM python:3.10-slim

# 安装系统依赖
RUN apt-get update && apt-get install -y \
git \
curl \
rsync \
build-essential \
&& rm -rf /var/lib/apt/lists/*

# 设置工作目录
WORKDIR /opt/remote-ci

# 复制项目文件
COPY server/ ./server/
COPY requirements.txt ./
COPY .env.example ./.env

# 安装Python依赖
RUN pip install --no-cache-dir -r requirements.txt

# 创建必要的目录
RUN mkdir -p /var/lib/remote-ci/logs \
/var/lib/remote-ci/uploads \
/var/ci-workspace \
/tmp/remote-ci

# 设置环境变量
ENV PYTHONUNBUFFERED=1

# 创建启动脚本
RUN echo '#!/bin/bash\n\
set -e\n\
\n\
echo "========================================"\n\
echo "Remote CI Test Server Starting..."\n\
echo "========================================"\n\
echo "API: http://0.0.0.0:5000"\n\
echo "Token: $CI_API_TOKEN"\n\
echo "========================================"\n\
\n\
# 启动Celery Worker(后台)\n\
cd /opt/remote-ci\n\
celery -A server.celery_app worker --loglevel=info --concurrency=2 &\n\
\n\
# 等待一秒让Worker启动\n\
sleep 1\n\
\n\
# 启动Flask API(前台)\n\
python3 -m server.app\n\
' > /opt/remote-ci/start.sh && chmod +x /opt/remote-ci/start.sh

EXPOSE 5000

CMD ["/opt/remote-ci/start.sh"]
79 changes: 79 additions & 0 deletions tests/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Remote CI Makefile - 测试和开发辅助工具

.PHONY: help test-e2e test-start test-stop test-logs test-clean test-all

# 默认目标
help:
@echo "Remote CI 测试工具"
@echo ""
@echo "可用命令:"
@echo " make test-all - 运行完整的端到端测试(推荐)"
@echo " make test-start - 启动测试环境"
@echo " make test-e2e - 运行端到端测试"
@echo " make test-logs - 查看容器日志"
@echo " make test-stop - 停止测试环境"
@echo " make test-clean - 清理测试环境和数据"
@echo " make test-shell - 进入远程CI容器shell"
@echo ""

# 运行完整测试
test-all: test-clean
@echo "=========================================="
@echo "运行完整的端到端测试套件"
@echo "=========================================="
@chmod +x test-e2e.sh
@./test-e2e.sh

# 启动测试环境
test-start:
@echo "启动测试环境..."
@docker compose -f docker-compose.test.yml up -d --build
@echo "等待服务就绪..."
@sleep 5
@curl -s http://localhost:15000/api/health | jq . || echo "服务未就绪"

# 运行端到端测试(不重启环境)
test-e2e:
@echo "运行端到端测试..."
@chmod +x test-e2e.sh
@./test-e2e.sh

# 查看日志
test-logs:
@docker compose -f docker-compose.test.yml logs -f

# 停止测试环境
test-stop:
@echo "停止测试环境..."
@docker compose -f docker-compose.test.yml down

# 清理测试环境和数据
test-clean:
@echo "清理测试环境..."
@docker compose -f docker-compose.test.yml down -v 2>/dev/null || true
@rm -rf ../test-workspace ../test-logs
@echo "清理完成"

# 进入容器shell
test-shell:
@docker exec -it remoteCI-test-server bash

# 检查环境
test-check:
@echo "检查Docker环境..."
@docker --version
@docker compose version
@echo ""
@echo "检查Python依赖..."
@python3 --version
@pip3 list | grep requests || echo "⚠️ 需要安装: pip3 install requests"
@which jq > /dev/null || echo "⚠️ 需要安装jq: brew install jq (macOS) 或 apt install jq (Linux)"

# 快速验证
test-quick: test-start
@sleep 3
@echo "快速验证远程CI服务..."
@curl -s http://localhost:15000/api/health | jq .
@echo ""
@echo "服务已启动,访问: http://localhost:15000"
@echo "停止服务: make test-stop"
Loading
Loading