18f9f7168SAndreas Gohr#!/bin/bash 28f9f7168SAndreas Gohr# 38f9f7168SAndreas Gohr# Pre-test hook executed by the DokuWiki test workflow before PHPUnit runs. 48f9f7168SAndreas Gohr# 58f9f7168SAndreas Gohr# It starts a Mailpit SMTP server so IntegrationTest can deliver a real mail 68f9f7168SAndreas Gohr# through the plugin and verify it via Mailpit's HTTP API. The connection details 78f9f7168SAndreas Gohr# are exported to the PHPUnit step through $GITHUB_ENV. Setting MAILPIT_HOST is what 88f9f7168SAndreas Gohr# enables the test - it then requires Mailpit to be reachable or fails. 98f9f7168SAndreas Gohr# 10*30b0aec1SAndreas Gohr# Mailpit is started with an auto-generated self-signed certificate (the "sans:" 11*30b0aec1SAndreas Gohr# syntax) so it offers STARTTLS. The smtp_allow_insecure test needs this and fails 12*30b0aec1SAndreas Gohr# (it does not skip) when the server does not speak TLS. 13*30b0aec1SAndreas Gohr# 148f9f7168SAndreas Gohrset -e 158f9f7168SAndreas Gohr 16*30b0aec1SAndreas Gohr# start Mailpit: SMTP on 1025, HTTP API/web UI on 8025, STARTTLS with a self-signed cert 17*30b0aec1SAndreas Gohrdocker run -d --name mailpit -p 1025:1025 -p 8025:8025 axllent/mailpit:latest \ 18*30b0aec1SAndreas Gohr --smtp-tls-cert sans:localhost --smtp-tls-key sans:localhost 198f9f7168SAndreas Gohr 208f9f7168SAndreas Gohr# wait until Mailpit is ready to accept connections 218f9f7168SAndreas Gohrecho "Waiting for Mailpit to become ready..." 228f9f7168SAndreas Gohrready=0 238f9f7168SAndreas Gohrfor _ in $(seq 1 30); do 248f9f7168SAndreas Gohr if curl -sf http://127.0.0.1:8025/readyz >/dev/null 2>&1; then 258f9f7168SAndreas Gohr ready=1 268f9f7168SAndreas Gohr break 278f9f7168SAndreas Gohr fi 288f9f7168SAndreas Gohr sleep 1 298f9f7168SAndreas Gohrdone 308f9f7168SAndreas Gohrif [ "$ready" -ne 1 ]; then 318f9f7168SAndreas Gohr echo "Mailpit did not become ready in time" >&2 328f9f7168SAndreas Gohr docker logs mailpit || true 338f9f7168SAndreas Gohr exit 1 348f9f7168SAndreas Gohrfi 358f9f7168SAndreas Gohrecho "Mailpit is ready" 368f9f7168SAndreas Gohr 378f9f7168SAndreas Gohr# expose the connection details to the PHPUnit step 388f9f7168SAndreas Gohr{ 398f9f7168SAndreas Gohr echo "MAILPIT_HOST=127.0.0.1" 408f9f7168SAndreas Gohr echo "MAILPIT_SMTP_PORT=1025" 418f9f7168SAndreas Gohr echo "MAILPIT_HTTP_PORT=8025" 428f9f7168SAndreas Gohr} >> "$GITHUB_ENV" 43