Skip to content

Add comprehensive unit tests for zip compression tool API #7

Add comprehensive unit tests for zip compression tool API

Add comprehensive unit tests for zip compression tool API #7

Workflow file for this run

name: CI/CD Pipeline
on:
push:
branches:
- main
- master
pull_request:
branches:
- main
- master
workflow_dispatch:
schedule:
- cron: '0 0 * * 0' # 每週日 00:00 執行
jobs:
lint-and-test:
name: Code Quality & Testing
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.11'
cache: 'pip'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install flake8 pytest pytest-cov
- name: Run linting (flake8)
run: |
# Stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# Exit-zero treats all errors as warnings
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Run tests
run: |
# 如果沒有測試文件,創建一個基本的測試
if [ ! -d "tests" ]; then
mkdir -p tests
echo "def test_placeholder():" > tests/test_basic.py
echo " assert True" >> tests/test_basic.py
fi
pytest --cov=. --cov-report=term-missing
- name: Validate template files
run: |
# 檢查 templates 目錄中的 HTML 文件
if [ -d "templates" ] && [ -f "templates/index.html" ]; then
echo "✓ Template files validated"
else
echo "✗ Required template files not found"
exit 1
fi
docker-build:
name: Docker Build Test
needs: lint-and-test
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build Docker image
run: |
if [ -f "Dockerfile" ]; then
docker build -t zip-compressor:test .
echo "✓ Docker image built successfully"
else
echo "⚠ No Dockerfile found, skipping Docker build"
fi
security-scan:
name: Security Vulnerability Scan
needs: lint-and-test
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.11'
- name: Install safety
run: |
pip install safety
- name: Run security scan
run: |
# 掃描已知的安全漏洞
pip install -r requirements.txt
safety check --json || echo "⚠ Security vulnerabilities found, please review"
- name: Deployment Info
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master')
run: |
echo "✓ CI/CD checks passed"
echo "→ Zeabur will automatically deploy via Git connection"