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