aboutsummaryrefslogtreecommitdiff
path: root/scripts/ci/mail.sh
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/ci/mail.sh')
-rwxr-xr-xscripts/ci/mail.sh33
1 files changed, 33 insertions, 0 deletions
diff --git a/scripts/ci/mail.sh b/scripts/ci/mail.sh
new file mode 100755
index 0000000..d15c5db
--- /dev/null
+++ b/scripts/ci/mail.sh
@@ -0,0 +1,33 @@
+#!/usr/bin/env bash
+set -Eeuo pipefail
+cd "$(dirname "${BASH_SOURCE[0]}")"
+cd ../../
+
+VPS_COMMIT_SHA="${1:-}"
+[[ -z "${VPS_COMMIT_SHA}" ]] && {
+ echo 'Error: missing $VPS_COMMIT_SHA positional argument.'
+ exit 2
+}
+
+SUBJECT="VPS CI run #${JOB_ID} logs"
+ATTACHMENT_PATH='logs.txt'
+BODY=$(cat <<EOF
+CI run for commit ${VPS_COMMIT_SHA}.
+See failed run:
+https://builds.sr.ht/~euandreh/job/${JOB_ID}
+
+Logs are attached.
+
+EOF
+)
+
+cat ./logs/*.txt > "${ATTACHMENT_PATH}"
+
+curl "${MAILGUN_URL}" \
+ -s \
+ --user "${MAILGUN_USER}" \
+ -F from="${MAILGUN_FROM}" \
+ -F to="${MAILGUN_TO}" \
+ -F subject="${SUBJECT}" \
+ -F text="${BODY}" \
+ -F attachment="@${ATTACHMENT_PATH}"