From 1e50c9de100fdc9116ed9c0e4c6192b99be3a9c1 Mon Sep 17 00:00:00 2001 From: Kirill Date: Sun, 22 Mar 2026 16:55:55 +0300 Subject: [PATCH] ci: update pipline to run api tests and build docker --- .forgejo/workflows/demo.yaml | 72 +++++++++++++++++++++++++++++++++++- 1 file changed, 71 insertions(+), 1 deletion(-) diff --git a/.forgejo/workflows/demo.yaml b/.forgejo/workflows/demo.yaml index bd22bfb..ece67d3 100644 --- a/.forgejo/workflows/demo.yaml +++ b/.forgejo/workflows/demo.yaml @@ -43,11 +43,81 @@ jobs: export FLASK_APP=app.py export FLASK_ENV=development flask run --host 0.0.0.0 --debug & - + + - name: Wait for Flask app to start + run: | + echo "Waiting for Flask app to start..." + for i in {1..10}; do + if curl -f http://localhost:80/health 2>/dev/null; then + echo "✅ Flask app is running" + exit 0 + fi + echo "Attempt $i: Flask app not ready yet..." + sleep 2 + done + echo "❌ Flask app failed to start" + exit 1 + + - name: Install test dependencies + run: | + . venv/bin/activate + pip install requests pytest pytest-cov + + - name: Run API tests with coverage + run: | + . venv/bin/activate + echo "Running API tests..." + python test_api.py + echo "✅ API tests completed" + + - name: Run additional pytest tests (if exist) + run: | + . venv/bin/activate + if [ -d tests ] && [ "$(ls -A tests)" ]; then + pytest tests/ -v --tb=short + else + echo "No pytest tests found, skipping" + fi + - name: Install release dependencies run: | + . venv/bin/activate pip install gunicorn - name: Release build (simulated) run: | + . venv/bin/activate gunicorn --check-config app:app + echo "✅ Gunicorn configuration is valid" + + - name: Build Docker image + run: | + if [ -f Dockerfile ]; then + echo "🐳 Building Docker image..." + docker build -t PVH:${{ github.sha }} -t PVH:latest . + docker images | grep PVH + echo "✅ Docker image built successfully" + + # Проверяем, что образ создался + docker run --rm PVH:latest python -c "import sys; print('Python version:', sys.version)" || true + fi + + - name: Test Docker image + run: | + echo "Testing Docker image..." + docker run -d -p 5001:5000 --name flask-test-container flask-app:latest + sleep 5 + curl -f http://localhost:5001/health || (docker logs flask-test-container && exit 1) + docker stop flask-test-container + docker rm flask-test-container + echo "✅ Docker image test passed" + + - name: Stop Flask app + if: always() + run: | + pkill -f "flask run" || pkill -f "python app.py" || true + + - name: Cleanup Docker + if: always() + run: | + docker system prune -f || true