Hash :
d34d8637
Author :
Thomas de Grivel
Date :
2023-02-17T16:48:22
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
#!/bin/sh
set -e
# shpkg
: ${SHPKG_DIR:=~/shpkg}
. "${SHPKG_DIR}/etc/shpkg/profile"
. "${SHPKG_DIR}/share/shpkg/shpkg.subr"
verbose 2 shpkg_config
verbose 2 shpkg_lock shpkg_ci_mux.lock
# Configuration
: ${SHPKG_CI_DIR:=${SHPKG_DIR}/ci}
shpkg_ci_remote () {
verbose 1 ssh "$1" sh -c "\"shpkg/bin/shpkg_ci '$2' >/dev/null\""
if [ "x$2" == "x--clean" ]; then
rm -rf "${SHPKG_CI_DIR}"
else
if [ "x$2" != "x--upgrade" ]; then
verbose 1 rsync -a "$1":shpkg/ci/. "${SHPKG_CI_DIR}/"
fi
fi
}
shpkg_ci_status2png () {
for F in "${SHPKG_CI_DIR}/status"/*.status; do
STATUS="$(cat "$F")"
I="${SHPKG_CI_DIR}/log/$(basename "$F" .status).png"
if ! [ -f "$I" ] ||
[ "$F" -nt "$I" ]; then
verbose 1 cp "${SHPKG_DIR}/share/shpkg/img/status_${STATUS}.64.png" "$I"
fi
done
}
usage () {
echo "Usage: $0 [OPTION] PKG REMOTE1 REMOTE2 ..."
echo "Options :"
echo " --no-remote Do not run remote commands, only mux files."
echo " --upgrade Upgrade."
echo " --clean Remove CI files."
exit $1
}
main () {
if [ "x$1" = "x--help" ] || [ "x$1" = "x-h" ]; then
usage 0
fi
SHPKG_REPO="$1"
shift
if [ "x${SHPKG_REPO}" != "x--no-remote" ]; then
for SHPKG_CI_MUX_HOST; do
shpkg_ci_remote "${SHPKG_CI_MUX_HOST}" "${SHPKG_REPO}" &
done
for SHPKG_CI_MUX_HOST; do
wait
done
if [ "x${SHPKG_REPO}" == "x--upgrade" ]; then
verbose 2 shpkg_upgrade
exit
fi
if [ "x${SHPKG_REPO}" == "x--clean" ]; then
exit
fi
fi
( cd "${SHPKG_CI_DIR}/status" &&
for I in $(ls */*/*.status | cut -d / -f 3 | sort -u); do
{
if grep -q running */*/"$I"; then
echo running
elif grep -q ko */*/"$I"; then
echo ko
else
echo ok
fi
} > "${SHPKG_CI_DIR}/status/$I"
done; )
( cd "${SHPKG_CI_DIR}/log" &&
for I in $(ls */*/*.log | cut -d / -f 3 | sort -u); do
TITLE="$I"
STATUS="$(cat "${SHPKG_CI_DIR}/status/$(basename "$I" .log).status" || echo unknown)"
IMG="$(basename "$I" .log).png"
{
cat <<EOF
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>${TITLE}</title>
<link rel="stylesheet" href="/_assets/app.css">
<script defer type="text/javascript" src="/_assets/app.js"></script>
<link rel="icon" type="image/png" sizes="64x64" href="${IMG}">
</head>
<body>
<div class="ci-header">
<a href="./"><i class="fas fa-asterisk"></i> All logs</a>
</div>
<h1>
<img src="${IMG}" class="status-${STATUS}"/>
${TITLE}
</h1>
<ul class="list-group">
EOF
for F in */*/"$I"; do
F_STATUS="$(cat "${SHPKG_CI_DIR}/status/$(echo "$F" | sed -e 's/[.]log$/.status/')" || echo unknown)"
F_IMG="$(echo "$F" | sed -e 's/[.]log$/.png/')"
cat <<EOF
<li class="list-group-item">
<a href="$F.html">
<img src="${F_IMG}" class="status-${F_STATUS}"/>
$F.html
</a>
</li>
EOF
done
cat <<EOF
</ul>
</body>
</html>
EOF
} > "${SHPKG_CI_DIR}/log/$I.html"
done; )
verbose 2 shpkg_ci_status2png
}
shpkg_log shpkg_ci_mux main "$@"