ci(test): update workflow #15
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Test | |
| on: | |
| push: | |
| branches: | |
| - main | |
| - dev | |
| - release-* | |
| - feat-* | |
| - ci-* | |
| - refactor-* | |
| - fix-* | |
| - test-* | |
| paths: | |
| - '.github/workflows/test.yml' | |
| - '**/Cargo.toml' | |
| - '**/*.rs' | |
| - '**/*.hurl' | |
| - 'run_tests.sh' | |
| pull_request: | |
| branches: [ main ] | |
| env: | |
| CARGO_TERM_COLOR: always | |
| RUST_BACKTRACE: 1 | |
| jobs: | |
| test: | |
| name: Test Suite | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| rust: [1.90.0] | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v5 | |
| - name: Start httpbin | |
| run: | | |
| # Use official httpbin image | |
| docker run -d \ | |
| --name httpbin \ | |
| -p 8888:80 \ | |
| kennethreitz/httpbin:latest | |
| # Wait for service to be ready | |
| echo "Waiting for httpbin to be ready..." | |
| for i in {1..30}; do | |
| if curl -f http://localhost:8888/get > /dev/null 2>&1; then | |
| echo "✅ httpbin is ready!" | |
| break | |
| fi | |
| if [ $i -eq 30 ]; then | |
| echo "❌ httpbin failed to start" | |
| docker logs httpbin | |
| exit 1 | |
| fi | |
| sleep 2 | |
| done | |
| - name: Start json-server | |
| run: | | |
| # Use Node.js official image to run json-server | |
| docker run -d \ | |
| --name json-api \ | |
| -p 8889:3000 \ | |
| -v ${{ github.workspace }}/tests/mock-data:/data:ro \ | |
| -w /data \ | |
| node:18-alpine \ | |
| sh -c "npm install -g [email protected] && json-server --host 0.0.0.0 --port 3000 db.json" | |
| # Wait for service to be ready | |
| echo "Waiting for json-api to be ready..." | |
| for i in {1..60}; do | |
| if curl -f http://localhost:8889/posts > /dev/null 2>&1; then | |
| echo "✅ json-api is ready!" | |
| break | |
| fi | |
| if [ $i -eq 60 ]; then | |
| echo "❌ json-api failed to start" | |
| docker logs json-api | |
| exit 1 | |
| fi | |
| sleep 2 | |
| done | |
| - name: Start WebSocket echo server | |
| run: | | |
| # Use simple Python WebSocket echo server | |
| cat > ws-echo.py << 'EOF' | |
| import asyncio | |
| import websockets | |
| async def echo(websocket, path): | |
| async for message in websocket: | |
| await websocket.send(message) | |
| async def main(): | |
| async with websockets.serve(echo, "0.0.0.0", 8890): | |
| await asyncio.Future() | |
| if __name__ == "__main__": | |
| asyncio.run(main()) | |
| EOF | |
| docker run -d \ | |
| --name ws-echo \ | |
| -p 8890:8890 \ | |
| -v ${{ github.workspace }}/ws-echo.py:/ws-echo.py:ro \ | |
| python:3.11-alpine \ | |
| sh -c "pip install websockets && python /ws-echo.py" | |
| # Wait for service to be ready - WebSocket service starts quickly | |
| echo "Waiting for ws-echo to be ready..." | |
| sleep 10 | |
| # Check if container is running | |
| if docker ps | grep -q ws-echo; then | |
| echo "✅ ws-echo container is running!" | |
| else | |
| echo "❌ ws-echo container failed to start" | |
| docker logs ws-echo | |
| exit 1 | |
| fi | |
| - name: Install Rust-stable | |
| uses: actions-rust-lang/setup-rust-toolchain@v1 | |
| with: | |
| toolchain: ${{ matrix.rust }} | |
| - name: Cache Rust dependencies | |
| uses: Swatinem/rust-cache@v2 | |
| with: | |
| cache-on-failure: true | |
| - name: Install Hurl | |
| run: | | |
| VERSION="5.0.1" | |
| curl -LO https://github.com/Orange-OpenSource/hurl/releases/download/${VERSION}/hurl_${VERSION}_amd64.deb | |
| sudo dpkg -i hurl_${VERSION}_amd64.deb | |
| - name: Install SQLite | |
| run: sudo apt-get update && sudo apt-get install -y sqlite3 | |
| - name: Verify services are running | |
| run: | | |
| echo "Checking httpbin..." | |
| curl -f http://localhost:8888/get | |
| echo "Checking json-api..." | |
| curl -f http://localhost:8889/posts | |
| echo "Checking ws-echo (WebSocket service - checking port)..." | |
| if timeout 5 bash -c 'cat < /dev/null > /dev/tcp/localhost/8890'; then | |
| echo "✅ ws-echo port 8890 is listening" | |
| else | |
| echo "❌ ws-echo port 8890 is not accessible" | |
| docker logs ws-echo | |
| exit 1 | |
| fi | |
| - name: Run tests | |
| env: | |
| USE_DOCKER_SERVICES: false # Services already running via GitHub Actions | |
| run: | | |
| chmod +x run_tests.sh | |
| ./run_tests.sh | |
| - name: Upload test results | |
| if: failure() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: test-logs | |
| path: | | |
| *.log | |
| sessions.db | |
| - name: Cleanup test services | |
| if: always() | |
| run: | | |
| docker stop httpbin || true | |
| docker rm httpbin || true | |
| docker stop json-api || true | |
| docker rm json-api || true | |
| docker stop ws-echo || true | |
| docker rm ws-echo || true |