xref: /plugin/smtp/_test/pretest.sh (revision 8f9f7168582dd10127fb688c7ad7e9116bc5c67b)
1#!/bin/bash
2#
3# Pre-test hook executed by the DokuWiki test workflow before PHPUnit runs.
4#
5# It starts a Mailpit SMTP server so IntegrationTest can deliver a real mail
6# through the plugin and verify it via Mailpit's HTTP API. The connection details
7# are exported to the PHPUnit step through $GITHUB_ENV. Setting MAILPIT_HOST is what
8# enables the test - it then requires Mailpit to be reachable or fails.
9#
10set -e
11
12# start Mailpit: SMTP on 1025, HTTP API/web UI on 8025
13docker run -d --name mailpit -p 1025:1025 -p 8025:8025 axllent/mailpit:latest
14
15# wait until Mailpit is ready to accept connections
16echo "Waiting for Mailpit to become ready..."
17ready=0
18for _ in $(seq 1 30); do
19    if curl -sf http://127.0.0.1:8025/readyz >/dev/null 2>&1; then
20        ready=1
21        break
22    fi
23    sleep 1
24done
25if [ "$ready" -ne 1 ]; then
26    echo "Mailpit did not become ready in time" >&2
27    docker logs mailpit || true
28    exit 1
29fi
30echo "Mailpit is ready"
31
32# expose the connection details to the PHPUnit step
33{
34    echo "MAILPIT_HOST=127.0.0.1"
35    echo "MAILPIT_SMTP_PORT=1025"
36    echo "MAILPIT_HTTP_PORT=8025"
37} >> "$GITHUB_ENV"
38