# The topology is defined in podman-compose file and can be spawned in two ways: # 1. podman-compose on a local machine (needs dependencies as defined in the Dockerfile) # 2. pytest in a dedicated container (recommended) SHELL := /bin/bash # Typical workflow: # 1. 'make build' - prepares images # 2. 'make up' - spawns podman-compose # 3. 'make pytest' - run tests inside the gwf-testclient container # 4. 'make down' - once the containers are not needed # # OR just run 'make test' to do it all at once. AUTO_DETECT_MODE := $(shell if test -e ../workflow-pr/workflow-pr; then echo .local; else echo .package; fi) # Default test target test: test_b build_local: AUTO_DETECT_MODE=.local build_local: build build_package: AUTO_DETECT_MODE=.package build_package: build # parse all service images from podman-compose and build them # mode B with pytest in container test_b: AUTO_DETECT_MODE=.local test_b: build up wait_healthy pytest # Complete cycle for CI test-ci: test_b down wait_healthy: @echo "Waiting for services to be healthy..." @echo "Waiting for gitea (max 2m)..." @start_time=$$(date +%s); \ until podman exec gwf-gitea-test curl -f -s http://localhost:3000/api/v1/version >/dev/null 2>&1; do \ current_time=$$(date +%s); \ elapsed=$$((current_time - start_time)); \ if [ $$elapsed -gt 120 ]; then \ echo "ERROR: Gitea failed to start within 2 minutes."; \ echo "--- Troubleshooting Info ---"; \ echo "Diagnostics output (curl):"; \ podman exec gwf-gitea-test curl -v http://localhost:3000/api/v1/version || true; \ echo "--- Container Logs ---"; \ podman logs gwf-gitea-test --tail 20; \ echo "--- Container Status ---"; \ podman inspect gwf-gitea-test --format '{{.State.Status}}'; \ exit 1; \ fi; \ sleep 2; \ done @echo "Waiting for rabbitmq (max 2m)..." @start_time=$$(date +%s); \ until podman exec gwf-rabbitmq-test rabbitmq-diagnostics check_running -q >/dev/null 2>&1; do \ current_time=$$(date +%s); \ elapsed=$$((current_time - start_time)); \ if [ $$elapsed -gt 120 ]; then \ echo "ERROR: RabbitMQ failed to start within 2 minutes."; \ echo "--- Troubleshooting Info ---"; \ echo "Diagnostics output:"; \ podman exec gwf-rabbitmq-test rabbitmq-diagnostics check_running || true; \ echo "--- Container Logs ---"; \ podman logs gwf-rabbitmq-test --tail 20; \ echo "--- Container Status ---"; \ podman inspect gwf-rabbitmq-test --format '{{.State.Status}}'; \ exit 1; \ fi; \ sleep 2; \ done @echo "All services are healthy!" pytest: podman-compose exec gwf-testclient pytest -v -s tests 2>&1 | tee logs/make_pytest.log; exit $${PIPESTATUS[0]} build: podman pull docker.io/library/rabbitmq:3.13.7-management for i in $$(grep -A 1000 services: podman-compose.yml | grep -oE '^ [^: ]+'); do GIWTF_IMAGE_SUFFIX=$(AUTO_DETECT_MODE) podman-compose build $$i || exit 1; done # this will spawn prebuilt containers up: podman-compose up -d # tear down down: podman-compose down # mode A up-bots-package: GIWTF_IMAGE_SUFFIX=.package podman-compose up -d # mode B up-bots-local: GIWTF_IMAGE_SUFFIX=.local podman-compose up -d clean: down rm -rf gitea-data/ gitea-logs/ rabbitmq-data/ workflow-pr-repos/ logs/*.log distclean: clean CONTAINERS=`podman images|grep -P 'localhost/.*gwf-.*'|awk '{print $$1}'`;\ [ -n "$$CONTAINERS" ] && \ podman rmi -f $$CONTAINERS || \ true podman image prune -f