-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.yml
More file actions
171 lines (154 loc) · 5.41 KB
/
action.yml
File metadata and controls
171 lines (154 loc) · 5.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
name: "RustMail Action"
description: "Start a RustMail SMTP catcher and assert on captured emails in CI"
author: "rustmailapp"
branding:
icon: "mail"
color: "orange"
inputs:
mode:
description: "Action mode: 'start' to launch the server, 'assert' to check captured emails"
required: true
default: "start"
smtp-port:
description: "SMTP port to listen on"
required: false
default: "1025"
http-port:
description: "HTTP/API port"
required: false
default: "8025"
assert-count:
description: "Minimum number of matching emails (assert mode)"
required: false
default: "1"
assert-subject:
description: "Filter by subject substring (assert mode)"
required: false
assert-sender:
description: "Filter by sender address (assert mode)"
required: false
assert-recipient:
description: "Filter by recipient address (assert mode)"
required: false
version:
description: "RustMail version to use (e.g., v0.1.0). Defaults to latest."
required: false
default: "latest"
outputs:
http-port:
description: "HTTP port the server is listening on"
value: ${{ steps.start.outputs.http-port }}
smtp-port:
description: "SMTP port the server is listening on"
value: ${{ steps.start.outputs.smtp-port }}
runs:
using: "composite"
steps:
- name: Validate mode
shell: bash
env:
MODE: ${{ inputs.mode }}
run: |
if [ "$MODE" != "start" ] && [ "$MODE" != "assert" ]; then
echo "::error::Invalid mode '${MODE}'. Must be 'start' or 'assert'."
exit 1
fi
- name: Determine platform
id: platform
if: inputs.mode == 'start'
shell: bash
run: |
case "$(uname -s)-$(uname -m)" in
Linux-x86_64) target="x86_64-unknown-linux-gnu" ;;
Linux-aarch64) target="aarch64-unknown-linux-gnu" ;;
Linux-armv7l) target="armv7-unknown-linux-gnueabihf" ;;
Darwin-x86_64) target="x86_64-apple-darwin" ;;
Darwin-arm64) target="aarch64-apple-darwin" ;;
*) echo "::error::Unsupported platform: $(uname -s)-$(uname -m)"; exit 1 ;;
esac
echo "target=$target" >> "$GITHUB_OUTPUT"
- name: Download RustMail
if: inputs.mode == 'start'
shell: bash
env:
RUSTMAIL_VERSION: ${{ inputs.version }}
RUSTMAIL_TARGET: ${{ steps.platform.outputs.target }}
run: |
bin_dir="${RUNNER_TEMP}/rustmail-bin"
mkdir -p "$bin_dir"
if [ "$RUSTMAIL_VERSION" = "latest" ]; then
url="https://github.com/rustmailapp/rustmail/releases/latest/download/rustmail-${RUSTMAIL_TARGET}"
else
url="https://github.com/rustmailapp/rustmail/releases/download/${RUSTMAIL_VERSION}/rustmail-${RUSTMAIL_TARGET}"
fi
curl -fsSL "$url" -o "${bin_dir}/rustmail"
chmod +x "${bin_dir}/rustmail"
echo "${bin_dir}" >> "$GITHUB_PATH"
- name: Start RustMail server
id: start
if: inputs.mode == 'start'
shell: bash
env:
SMTP_PORT: ${{ inputs.smtp-port }}
HTTP_PORT: ${{ inputs.http-port }}
run: |
rustmail serve \
--ephemeral \
--bind 127.0.0.1 \
--smtp-port "$SMTP_PORT" \
--http-port "$HTTP_PORT" &
RUSTMAIL_PID=$!
for i in $(seq 1 30); do
if ! kill -0 "$RUSTMAIL_PID" 2>/dev/null; then
echo "::error::RustMail process exited unexpectedly"
exit 1
fi
if curl -sf "http://127.0.0.1:${HTTP_PORT}/api/v1/messages" > /dev/null 2>&1; then
echo "RustMail is ready (PID $RUSTMAIL_PID)"
echo "http-port=${HTTP_PORT}" >> "$GITHUB_OUTPUT"
echo "smtp-port=${SMTP_PORT}" >> "$GITHUB_OUTPUT"
echo "RUSTMAIL_PID=$RUSTMAIL_PID" >> "$GITHUB_ENV"
echo "RUSTMAIL_HTTP_PORT=${HTTP_PORT}" >> "$GITHUB_ENV"
exit 0
fi
sleep 1
done
kill "$RUSTMAIL_PID" 2>/dev/null || true
echo "::error::RustMail failed to start within 30 seconds"
exit 1
- name: Assert emails
if: inputs.mode == 'assert'
shell: bash
env:
ASSERT_COUNT: ${{ inputs.assert-count }}
ASSERT_SUBJECT: ${{ inputs.assert-subject }}
ASSERT_SENDER: ${{ inputs.assert-sender }}
ASSERT_RECIPIENT: ${{ inputs.assert-recipient }}
HTTP_PORT: ${{ inputs.http-port }}
run: |
if ! [[ "$ASSERT_COUNT" =~ ^[0-9]+$ ]]; then
echo "::error::assert-count must be a positive integer, got '${ASSERT_COUNT}'"
exit 1
fi
port="${RUSTMAIL_HTTP_PORT:-$HTTP_PORT}"
url="http://127.0.0.1:${port}/api/v1/assert/count?min=${ASSERT_COUNT}"
urlencode() {
python3 -c "import urllib.parse, sys; print(urllib.parse.quote(sys.stdin.read().strip()))" <<< "$1"
}
if [ -n "$ASSERT_SUBJECT" ]; then
url="${url}&subject=$(urlencode "$ASSERT_SUBJECT")"
fi
if [ -n "$ASSERT_SENDER" ]; then
url="${url}&sender=$(urlencode "$ASSERT_SENDER")"
fi
if [ -n "$ASSERT_RECIPIENT" ]; then
url="${url}&recipient=$(urlencode "$ASSERT_RECIPIENT")"
fi
echo "Asserting: $url"
if curl -fsS "$url"; then
echo ""
echo "Assertion passed"
else
echo "::error::Email assertion failed: expected at least ${ASSERT_COUNT} matching email(s)"
exit 1
fi