From 5caa583240d0d54b9771ab1119443aac52d50215 Mon Sep 17 00:00:00 2001 From: Leendert de Borst Date: Mon, 25 Nov 2024 15:41:21 +0100 Subject: [PATCH] Update workflow test to show error if HTTP check fails (#418) --- .github/workflows/docker-compose-build.yml | 109 ++++++++++----------- 1 file changed, 51 insertions(+), 58 deletions(-) diff --git a/.github/workflows/docker-compose-build.yml b/.github/workflows/docker-compose-build.yml index 9b932a89..5c531e0e 100644 --- a/.github/workflows/docker-compose-build.yml +++ b/.github/workflows/docker-compose-build.yml @@ -1,4 +1,3 @@ -# This workflow will test if building the Docker Compose containers from scratch works. name: Docker Compose Build on: @@ -18,6 +17,7 @@ jobs: steps: - uses: actions/checkout@v2 + - name: Set permissions and run install.sh run: | chmod +x install.sh @@ -25,76 +25,69 @@ jobs: - name: Set up Docker Compose run: | - # Change the exposed host port of the SmtpService from 25 to 2525 because port 25 is not allowed in GitHub Actions - sed -i 's/25\:25/2525\:25/g' docker-compose.yml - docker compose -f docker-compose.yml up -d + sed -i 's/25\:25/2525\:25/g' docker-compose.yml + docker compose -f docker-compose.yml up -d - - name: Wait for services to be up - run: | - # Wait for a few seconds - sleep 15 - - name: Test if localhost:443 (WASM app) responds + - name: Test if services are responding uses: nick-fields/retry@v3 with: - timeout_minutes: 2 - max_attempts: 3 + timeout_minutes: 5 + max_attempts: 5 command: | - http_code=$(curl -k -s -o /dev/null -w "%{http_code}" https://localhost:443) - if [ "$http_code" -ne 200 ]; then - echo "Service did not respond with 200 OK. Check if client app and/or nginx is configured correctly." - exit 1 - else - echo "Service responded with 200 OK" - fi + sleep 5 - - name: Test if localhost:443/api (WebApi) responds - uses: nick-fields/retry@v3 - with: - timeout_minutes: 2 - max_attempts: 3 - command: | - http_code=$(curl -k -s -o /dev/null -w "%{http_code}" https://localhost:443/api) - if [ "$http_code" -ne 200 ]; then - echo "Service did not respond with expected 200 OK. Check if WebApi and/or nginx is configured correctly." - exit 1 - else - echo "Service responded with $http_code" - fi + # Array of endpoints to test + declare -A endpoints=( + ["WASM"]="https://localhost:443" + ["WebApi"]="https://localhost:443/api" + ["Admin"]="https://localhost:443/admin/user/login" + ) + + failed=false + + # Test HTTP endpoints + for name in "${!endpoints[@]}"; do + url="${endpoints[$name]}" + echo "Testing $name at $url" + + # Store both response body and HTTP code + response=$(curl -k -s -w "\nHTTP_CODE=%{http_code}" "$url") + http_code=$(echo "$response" | grep "HTTP_CODE=" | cut -d= -f2) + body=$(echo "$response" | sed '$d') # Remove the last line (HTTP_CODE) - - name: Test if localhost:443/admin (Admin) responds - uses: nick-fields/retry@v3 - with: - timeout_minutes: 2 - max_attempts: 3 - command: | - http_code=$(curl -k -s -o /dev/null -w "%{http_code}" https://localhost:443/admin/user/login) if [ "$http_code" -ne 200 ]; then - echo "Service did not respond with expected 200 OK. Check if admin app and/or nginx is configured correctly." - exit 1 + echo "❌ $name failed with HTTP $http_code at $url" + echo "Response body:" + echo "$body" + failed=true else - echo "Service responded with $http_code" + echo "✅ $name responded with HTTP 200" fi + done - - name: Test if localhost:2525 (SmtpService) responds - uses: nick-fields/retry@v3 - with: - timeout_minutes: 2 - max_attempts: 3 - command: | - if ! nc -zv localhost 2525 2>&1 | grep -q 'succeeded'; then - echo "SmtpService did not respond on port 2525. Check if the SmtpService service is running." - exit 1 - else - echo "SmtpService responded on port 2525" - fi + # Test SMTP + echo "Testing SmtpService at localhost:2525" + if ! nc -zv localhost 2525 2>&1 | grep -q 'succeeded'; then + echo "❌ SmtpService failed to respond on port 2525" + failed=true + else + echo "✅ SmtpService responded successfully" + fi + + # Exit with error if any service failed + if [ "$failed" = true ]; then + # Get container logs + echo "Container Logs:" + docker compose logs + exit 1 + fi - name: Test install.sh reset-password output run: | output=$(./install.sh reset-password) if ! echo "$output" | grep -E '.*New admin password: [A-Za-z0-9+/=]{8,}.*'; then - echo "Password reset output format is incorrect. Expected format: 'New admin password: '" - echo "Actual output: $output" + echo "Password reset output format is incorrect" + echo "Expected: 'New admin password: '" + echo "Actual: $output" exit 1 - else - echo "Password reset output format is correct" - fi + fi \ No newline at end of file