diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..fa688ed --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,98 @@ +name: Test Template + +on: + push: + branches: [ main, master ] + pull_request: + branches: [ main, master ] + +jobs: + test: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.12", "3.13"] + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + + - name: Install UV + run: | + curl -LsSf https://astral.sh/uv/install.sh | sh + echo "$HOME/.cargo/bin" >> $GITHUB_PATH + + - name: Install cookiecutter + run: | + uv tool install cookiecutter + + - name: Generate project from template + run: | + uv tool run cookiecutter . --no-input \ + project_name="Test App" \ + project_slug="test-app" \ + author_name="Test Author" \ + author_email="test@example.com" \ + description="A test app" + + - name: Install project dependencies + working-directory: ./test-app + run: | + uv sync + + - name: Run pytest tests + working-directory: ./test-app + run: | + uv run pytest -v + + - name: Run type checking with mypy + working-directory: ./test-app + run: | + uv run mypy src + + - name: Start application in background + working-directory: ./test-app + run: | + uv run uvicorn src.main:app --host 0.0.0.0 --port 8000 & + echo $! > app.pid + + - name: Wait for application to start + run: | + timeout 30 bash -c 'until curl -f http://localhost:8000/ > /dev/null 2>&1; do sleep 1; done' + + - name: Test application with curl + run: | + # Test homepage + response=$(curl -s -w "%{http_code}" http://localhost:8000/) + echo "Response: $response" + + # Check if response contains expected content + if ! curl -s http://localhost:8000/ | grep -q "Hello"; then + echo "Error: Homepage doesn't contain expected 'Hello' text" + exit 1 + fi + + echo "✓ Homepage is accessible and contains expected content" + + - name: Test static files + run: | + # Test if static files endpoint is accessible + response_code=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8000/static/) + if [ "$response_code" != "404" ] && [ "$response_code" != "200" ]; then + echo "Unexpected response code for static endpoint: $response_code" + exit 1 + fi + echo "✓ Static files endpoint is configured" + + - name: Stop application + if: always() + working-directory: ./test-app + run: | + if [ -f app.pid ]; then + kill $(cat app.pid) || true + fi