]> git.ipfire.org Git - people/ms/nightly-builds.git/commitdiff
build.sh: Send an email when a nightly build has finished
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 7 Feb 2020 10:03:29 +0000 (10:03 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 7 Feb 2020 10:03:29 +0000 (10:03 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
build.sh

index 231e1a779724f3c118d7b08d452288c5ed5db218..a3e5a60bc274d693c22e2135fe05442b5d8c127e 100755 (executable)
--- 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 <<END
+From: IPFire Nightly Builder <nightly-builds@ipfire.org>
+To: Nightly Builds List <nightly-builds@lists.ipfire.org>
+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