Skip to content

Commit

Permalink
build: add CI for bruno-cli api tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vtshly committed Jan 2, 2025
1 parent 807e31e commit 45e0aa0
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 2 deletions.
3 changes: 2 additions & 1 deletion cms/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
"@types/node": "^20",
"@types/react": "^18",
"@types/react-dom": "^18",
"typescript": "^5"
"typescript": "^5",
"@usebruno/cli": "^1.36.3"
},
"engines": {
"node": ">=18.0.0 <=22.x.x",
Expand Down
57 changes: 57 additions & 0 deletions cms/run-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/bin/bash

# Constants
HEALTH_CHECK_URL="http://localhost:1337/_health"
API_COLLECTION_PATH="../bruno-church-api-collection"
WAIT_FOR_START=20
MAX_RETRIES=30
RETRY_INTERVAL=4

# Function to run tests based on environment
run_tests() {
echo "Running tests in $NODE_ENV mode..."
cd $API_COLLECTION_PATH

if [ "$NODE_ENV" == "development" ]; then
bru run --env local-environment
elif [ "$NODE_ENV" == "production" ]; then
bru run --env prod-environment
else
echo "NODE_ENV is not set or has an invalid value. Please set it to 'development' or 'production'."
exit 1
fi
}

# Function to check health container
check_health() {
local retry_count=0

while [ $retry_count -lt $MAX_RETRIES ]; do
if curl -f $HEALTH_CHECK_URL &>/dev/null; then
echo "Health check passed"
return 0
fi

echo "Waiting for service to be healthy... (Attempt $((retry_count + 1))/$MAX_RETRIES)"
sleep $RETRY_INTERVAL
retry_count=$((retry_count + 1))
done

echo "Health check failed after $MAX_RETRIES attempts"
return 1
}

# Main execution
echo "Current NODE_ENV: $NODE_ENV"

if [ "$1" == "docker" ]; then
echo "Docker mode detected, performing health check..."
sleep $WAIT_FOR_START
if check_health; then
run_tests
else
exit 1
fi
else
run_tests
fi
2 changes: 1 addition & 1 deletion dev-config/Dockerfile.cms
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ RUN echo "ls -la"
RUN ls -la /usr/app

RUN bash -c "chmod 777 run.sh;"
CMD ./run.sh
CMD bash -c "./run.sh & ./run-tests.sh docker"

0 comments on commit 45e0aa0

Please sign in to comment.