summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorbill-auger <mr.j.spam.me@gmail.com>2024-03-22 17:05:14 -0400
committerbill-auger <mr.j.spam.me@gmail.com>2024-03-28 23:14:22 -0400
commit542693f810d0afa8f063f1b8d2a9a0c2075f5305 (patch)
tree3880d55118dcb5f3c60792a11e8a4df92c873282 /src
parent16ed450578aa66a4018bbe3493f1e7d58e71b0d6 (diff)
notifications.sh: rework and add tests
The previous implementation reported locally-staged packages; but did not account for files which were already staged on the repo server. That would be the case when the `-u` option is used, or sometimes due to error. This implementation reports what was actually published per `db-update`.
Diffstat (limited to 'src')
-rwxr-xr-xsrc/abslibre-tools/librerelease24
-rw-r--r--src/lib/notifications.sh48
2 files changed, 40 insertions, 32 deletions
diff --git a/src/abslibre-tools/librerelease b/src/abslibre-tools/librerelease
index a94c166..9c48ac7 100755
--- a/src/abslibre-tools/librerelease
+++ b/src/abslibre-tools/librerelease
@@ -202,7 +202,7 @@ release() {
local dbupdate_log="$(mktemp -t ${0##*/}_log.XXXXXXXXXX)"
local mkdir_cmd="mkdir -p -- ${TIER0_STAGING@Q} && cd ${TIER0_STAGING@Q} && xargs -0r mkdir -pv --"
local dbupdate_cmd="STAGING=${TIER0_STAGING@Q} DBSCRIPTS_CONFIG=${DBSCRIPTS_CONFIG@Q} db-update"
- local upload_size
+ local upload_size pbotsay_msg pbotsay_cmd
trap "rm -f -- ${file_list@Q} ${dbupdate_log@Q}" INT RETURN TERM
@@ -263,7 +263,20 @@ release() {
## publish ##
msg "Running db-update on repos"
- if ${SSH_CMD[*]} "${dbupdate_cmd}"; then # eg: ssh -p 1863 autobuilder@repo.parabola.nu STAGING='staging/' DBSCRIPTS_CONFIG='/etc/dbscripts/config.local.parabola' db-update
+ (
+ # this contraption allows detecting `db-update` exit failure,
+ # while logging output both to file and to the local shell in real-time,
+ # while preserving (restoring) colors lost in the pipeline
+ set -o pipefail ; ${SSH_CMD[*]} "$dbupdate_cmd" | tee "$dbupdate_log" |
+ while read line ; do ( [[ "$line" =~ ^==\> ]] && msg "${line#==\> }" ) ||
+ ( [[ "$line" =~ ^\ *-\> ]] && msg2 "${line#*\> }" ) ||
+ echo "$line" ; done
+ )
+
+ if grep -Eq "^==> Updating \[" "$dbupdate_log"; then
+ pbotsay_msg=$(release_notification "${TIER0_LOGIN:-${LIBREUSER}}" < "$dbupdate_log")
+ pbotsay_cmd="if type pbot-say &>/dev/null ; then pbot-say ${pbotsay_msg@Q} ; fi"
+
if [[ -n $HOOKPOSTRELEASE ]]; then
msg "Running HOOKPOSTRELEASE..."
(
@@ -273,11 +286,10 @@ release() {
fi
# notify pbot of the excellent work that we have done today
- notify_release ${SSH_CMD[*]} < $file_list
-
- return $EXIT_SUCCESS
+ msg2 "$(_ "Notifying pbot:")" ; print " $pbotsay_msg" ;
+ ${SSH_CMD[*]} "$pbotsay_cmd" &> /dev/null || :
else
- return $EXIT_FAILURE
+ msg2 "Nothing was published"
fi
}
diff --git a/src/lib/notifications.sh b/src/lib/notifications.sh
index 2457dbd..0c3b947 100644
--- a/src/lib/notifications.sh
+++ b/src/lib/notifications.sh
@@ -1,29 +1,25 @@
-# process librerelease::$file_list via STDIN
-notify_release() # ( ssh_cmd* ) file_list->STDIN
+# parse `librerelease` `db-update` log via STDIN,
+# and emit formatted notification message
+release_notification() # ( hacker ) dbupdate_log->STDIN
{
- local ssh_cmd=( $* )
- local repo_user=${REPOUSER:-${LIBREUSER:-somebody}}
- local select_rx='\.pkg\.tar\.[^\.]+$'
- local reject_rx='-debug-'
- # example "selected" $file_list entry, to be fed through $filename_rx:
- # libre/gst-plugins-bad-1.22.8-1.parabola1-x86_64.pkg.tar.zst
- # (repo )/(pkgname )- : (pkgver )- -(arch )
- local filename_rx="^([a-z-]+)/([0-9A-Za-z\._@\+\-]+)-([0-9]+:)?([0-9A-Za-z\._]+)-[^/-]+-([0-9a-z_]+)${select_rx}"
- local filename_subst='(\2 \4)->\1/\5' # eg: (iceweasel 121.0.1)->libre/x86_64
- local filename_sed="s|${filename_rx}|${filename_subst}|"
- local filename
- local releases=( $(while read -r -d '' # process librerelease::$file_list via STDIN
- do filename="$REPLY"
- [[ "${filename}" =~ ${select_rx} ]] || continue
- [[ "${filename}" =~ ${reject_rx} ]] && continue || :
+ local hacker=${1:-somebody}
+ # (pkgname )- : (pkgver )- -(arch )
+ local filename_rx="^([0-9A-Za-z\._@\+\-]+)-([0-9]+:)?([0-9A-Za-z\._]+)-[^/-]+-([0-9a-z_]+)\.pkg\.tar\.[^\.]+$"
+ local repo pkg arch pkgname pkgver
- sed -E "${filename_sed}" <<< ${filename} || :
- done | sort -u | xargs || :) )
- local pbotsay_msg="$(printf "%s just published:" ${repo_user}) ${releases[@]}"
- local pbotsay_cmd="which pbot-say &> /dev/null && pbot-say '${pbotsay_msg}'"
-
- if [[ ${ssh_cmd[0]} == ssh ]] && (( ${#releases[@]} )); then
- msg2 "$(_ "Notifying pbot:")" ; print " ${pbotsay_msg}" ;
- ${ssh_cmd[*]} "${pbotsay_cmd}" &> /dev/null || :
- fi
+ printf "${hacker} just published: "
+ grep -E "^==> Updating |^ -> [^ ]+ \([^ )]+\)" |
+ while read line
+ do if [[ "${line}" =~ ^==\>\ Updating\ \[([^\]]+)\]...$ ]]
+ then repo=${BASH_REMATCH[1]}
+ elif [[ "${line}" =~ ^\ *-\>\ ([^\ ]+)\ \(([^\ ]+)\)$ ]]
+ then pkg=${BASH_REMATCH[1]} arch=${BASH_REMATCH[2]}
+ if [[ "${pkg}" =~ ${filename_rx} ]]
+ then pkgname=${BASH_REMATCH[1]} pkgver=${BASH_REMATCH[3]}
+ if [[ ! "${pkg}" =~ '-debug-' ]]
+ then echo "(${pkgname} ${pkgver})->${repo}/${arch}"
+ fi
+ fi
+ fi
+ done | LANG=C sort -u | xargs
}