diff --git a/.github/workflows/test-suite.yml b/.github/workflows/test-suite.yml index 9acf021..3f4d421 100644 --- a/.github/workflows/test-suite.yml +++ b/.github/workflows/test-suite.yml @@ -55,31 +55,22 @@ jobs: with: python-version: "${{ matrix.python-version }}" - # Install Docker Compose if it's not available by default - - name: Set up Docker Compose - run: sudo apt-get install docker-compose -y - # Start Pulsar using Docker Compose - name: Start Pulsar - run: docker-compose up -d pulsar + run: "scripts/start_pulsar" - - name: Wait for Pulsar - run: | - timeout 300 bash -c ' - until curl -s http://localhost:8080/admin/v2/brokers/healthcheck; do - echo "Waiting for Pulsar to be ready..." - sleep 5 - done - echo "pulsar is ready" - ' + run: "scripts/wait_for_pulsar" - name: "Install dependencies" run: "scripts/install" + # - name: "Run linting checks" # run: "scripts/check" + - name: "Build package & docs" run: "scripts/build" + - name: "Run tests" run: "scripts/test" @@ -88,4 +79,5 @@ jobs: # Stop the Pulsar container after all tests are complete - name: Stop Pulsar - run: docker-compose down + if: always() # This ensures the step runs even if previous steps fail + run: "scripts/stop_pulsar" diff --git a/scripts/start_pulsar b/scripts/start_pulsar new file mode 100755 index 0000000..1c84646 --- /dev/null +++ b/scripts/start_pulsar @@ -0,0 +1,16 @@ +#!/bin/bash + +# Install Docker Compose if it's not available +if ! command -v docker-compose &> /dev/null; then + echo "Docker Compose not found. Installing..." + sudo apt-get update + sudo apt-get install -y docker-compose +else + echo "Docker Compose is already installed." +fi + +# Start Pulsar using Docker Compose +echo "Starting Pulsar..." +docker-compose up -d pulsar + +echo "Pulsar startup complete." diff --git a/scripts/stop_pulsar b/scripts/stop_pulsar new file mode 100755 index 0000000..f2abca5 --- /dev/null +++ b/scripts/stop_pulsar @@ -0,0 +1,17 @@ +#!/bin/bash + + +echo "Stopping Pulsar container..." + +# Stop and remove containers defined in docker-compose.yml +if docker-compose down; then + echo "Pulsar container have been stopped and removed successfully." +else + echo "Error: Failed to stop Pulsar containers. Please check Docker Compose configuration." + exit 1 +fi + +# Optional: Remove volumes +# docker-compose down -v + +echo "Cleanup complete." diff --git a/scripts/wait_for_pulsar b/scripts/wait_for_pulsar new file mode 100755 index 0000000..fc3801b --- /dev/null +++ b/scripts/wait_for_pulsar @@ -0,0 +1,19 @@ +#!/bin/bash + +MAX_RETRIES=60 +RETRY_INTERVAL=5 +HEALTH_CHECK_URL="http://localhost:8080/admin/v2/brokers/healthcheck" + +echo "Waiting for Pulsar to be ready..." + +for i in $(seq 1 $MAX_RETRIES); do + if curl -s "$HEALTH_CHECK_URL" > /dev/null; then + echo "Pulsar is ready!" + exit 0 + fi + echo "Attempt $i/$MAX_RETRIES: Pulsar is not ready yet. Retrying in $RETRY_INTERVAL seconds..." + sleep $RETRY_INTERVAL +done + +echo "Error: Pulsar did not become ready within the allocated time." +exit 1