From e5c0113d03bb40b894c62028c69dcf799c2667b6 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Fri, 7 Feb 2020 10:03:29 +0000 Subject: [PATCH] build.sh: Send an email when a nightly build has finished Signed-off-by: Michael Tremer --- build.sh | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) diff --git a/build.sh b/build.sh index 231e1a7..a3e5a60 100755 --- a/build.sh +++ b/build.sh @@ -34,6 +34,63 @@ extract_installer_from_iso() { rm -rf "${tmpdir}" } +uriencode() { + local path="${1}" + + local IFS="/" + + local s + local segments=() + for s in ${path}; do + s="${s//'%'/%25}" + s="${s//' '/%20}" + s="${s//'"'/%22}" + s="${s//'#'/%23}" + s="${s//'$'/%24}" + s="${s//'&'/%26}" + s="${s//'+'/%2B}" + s="${s//','/%2C}" + s="${s//'/'/%2F}" + s="${s//':'/%3A}" + s="${s//';'/%3B}" + s="${s//'='/%3D}" + s="${s//'?'/%3F}" + s="${s//'@'/%40}" + s="${s//'['/%5B}" + s="${s//']'/%5D}" + + segments+=( "${s}" ) + done + + echo "${segments[*]}" +} + +send_email() { + local status="${1}" + local target="${2}" + local branch="${3}" + local commit="${4}" + local build="${5}" + + sendmail -ti < +To: Nightly Builds List +Subject: [${status^^}] Nightly Build of ${branch} (${commit:0:7}) for ${target} on ${HOSTNAME} +Date: $(date --rfc-2822) +MIME-Version: 1.0 +Content-Type: text/plain; charset="us-ascii" +Content-Transfer-Encoding: 7bit + +https://nightly.ipfire.org$(uriencode "${build:${#UPLOAD_DIR}}") + +$(git log -1 "${commit}") + +https://git.ipfire.org/?p=ipfire-2.x.git;a=shortlog;h=${commit} + +$(<"${build}/build.log") +END +} + build() { local dir="${1}" shift @@ -75,6 +132,7 @@ build() { for target in ${targets}; do local build_path="${UPLOAD_DIR}/${branch}/${now}-${commit_new:0:8}" local build="${build_path}/${target}" + local status="failed" # Ready for build ./make.sh --target="${target}" clean @@ -95,12 +153,18 @@ build() { # Save the result if [ "${ret}" = "0" ]; then + status="success" + touch "${build}/.success" + + # Copy images mv -v *.iso *.img.gz *.img.xz *.tar.bz2 *.md5 packages/ "${build}" extract_installer_from_iso "${build}" - touch "${build}/.success" fi mv -v log/ "${build}" + # Send an email notification + send_email "${status}" "${target}" "${branch}" "${commit_new}" "${build}" + # Cleanup the build environment ./make.sh --target="${target}" clean -- 2.47.3