Hash :
a4538bc6
Author :
Thomas de Grivel
Date :
2023-02-14T18:45:42
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 136 137 138 139 140 141 142 143 144 145 146 147
#!/bin/sh
set -e
# shpkg
. ~/shpkg/etc/shpkg/profile
. ~/shpkg/share/shpkg/shpkg.subr
verbose 2 shpkg_config
verbose 2 shpkg_lock shpkg_ci.lock
# Configuration
: ${SHPKG_CI_DIR:=~/shpkg_ci}
SHPKG_CI_LOG_DIR="${SHPKG_CI_DIR}/log/${SHPKG_OS_}/${SHPKG_TARGET}"
SHPKG_CI_STATUS_DIR="${SHPKG_CI_DIR}/status/${SHPKG_OS_}/${SHPKG_TARGET}"
log2html () {
{
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>
EOF
cat <<EOF
</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="128x128" href="/_images/ci.128.png">
<link rel="icon" type="image/png" sizes="64x64" href="/_images/ci.64.png">
<link rel="icon" type="image/png" sizes="32x32" href="/_images/ci.32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/_images/ci.16.png">
</head>
<body>
<h1>
EOF
echo "$1" | ansi2html
cat <<EOF
</h1>
<pre><code>
EOF
ansi2html < "$1"
cat <<EOF
</code></pre>
<div class="footer">
<a href="https://git.kmx.io/kmx.io/shpkg">shpkg_ci</a>
</div>
</body>
</html>
EOF
} > "$1.html.tmp"
mv "$1.html.tmp" "$1.html"
}
logs2html () {
for F in "${SHPKG_CI_LOG_DIR}"/"${SHPKG_REPO}".*.log; do
if ! [ -f "$F.html" ] || [ "$F" -nt "$F.html" ] || [ "$0" -nt "$F.html" ]; then
verbose 2 log2html "$F"
fi
done
}
# state machine :
# any -> running
# running -> ko, ok
# additionaly status will be changed to ko if aborted while running
shpkg_ci_status () {
if [ "x$2" = "xrunning" ]; then
echo "$2" > "${SHPKG_CI_STATUS_DIR}/$1"
trap "shpkg_ci_status_trap $1" EXIT
elif [ "x$(< "${SHPKG_CI_STATUS_DIR}/$1")" = "xrunning" ]; then
echo "$2" > "${SHPKG_CI_STATUS_DIR}/$1"
fi
}
shpkg_ci_status_trap () {
if [ "x$(< "${SHPKG_CI_STATUS_DIR}/$1")" = "xrunning" ]; then
echo ko > "${SHPKG_CI_STATUS_DIR}/$1"
fi
}
main () {
if ! [ -d "${SHPKG_CI_LOG_DIR}" ]; then
verbose 1 mkdir -p "${SHPKG_CI_LOG_DIR}"
fi
if ! [ -d "${SHPKG_CI_STATUS_DIR}" ]; then
verbose 1 mkdir -p "${SHPKG_CI_STATUS_DIR}"
fi
verbose 2 shpkg_ci_status "shpkg_ci.status" running
for SHPKG_REPO; do
SHPKG_REPO_DIR="$(shpkg_dir "${SHPKG_REPO}")"
if [ "x${SHPKG_REPO_DIR}" = "x" ]; then
err 1 "shpkg_ci: unknown repo: $SHPKG_REPO"
fi
verbose 2 shpkg_tag_log "${SHPKG_REPO}.ci.log"
verbose 2 shpkg_ci_status "${SHPKG_REPO}.ci.status" running
# first bootstrap
if ! [ -d ~/"shpkg_${SHPKG_REPO}" ]; then
( verbose 2 shpkg_bootstrap ~/"shpkg_${SHPKG_REPO}"; )
else
# check upgrade
( . ~/"shpkg_${SHPKG_REPO}/etc/shpkg/profile"
verbose 2 shpkg_ci_status "${SHPKG_REPO}.upgrade.status" running
if verbose 2 shpkg upgrade "${SHPKG_REPO}"; then
verbose 2 shpkg_ci_status "${SHPKG_REPO}.upgrade.status" ok
else
verbose 2 shpkg_ci_status "${SHPKG_REPO}.upgrade.status" ko
verbose 2 shpkg_ci_status "${SHPKG_REPO}.ci.status" ko
fi; )
if verbose 1 cp -p ~/"shpkg_${SHPKG_REPO}/var/log/shpkg/tags/${SHPKG_REPO}".*.log "${SHPKG_CI_LOG_DIR}"; then
verbose 2 logs2html
fi
fi
( verbose 2 shpkg_bootstrap -f ~/"shpkg_${SHPKG_REPO}"; )
( . ~/"shpkg_${SHPKG_REPO}/etc/shpkg/profile"
verbose 2 shpkg_ci_status "${SHPKG_REPO}.install.status" running
if verbose 2 shpkg install "${SHPKG_REPO}"; then
verbose 2 shpkg_ci_status "${SHPKG_REPO}.install.status" ok
else
verbose 2 shpkg_ci_status "${SHPKG_REPO}.install.status" ko
verbose 2 shpkg_ci_status "${SHPKG_REPO}.ci.status" ko
fi; )
SHPKG_CI_COPY=No
if verbose 1 cp -p ~/"shpkg_${SHPKG_REPO}/var/log/shpkg/tags/${SHPKG_REPO}".*.log "${SHPKG_CI_LOG_DIR}"; then
SHPKG_CI_COPY=Yes
fi
if verbose 1 cp -p ~/"shpkg/var/log/shpkg/tags/${SHPKG_REPO}.ci.log" "${SHPKG_CI_LOG_DIR}"; then
SHPKG_CI_COPY=Yes
fi
if [ "x${SHPKG_CI_COPY}" = "xYes" ]; then
verbose 2 logs2html
fi
verbose 2 shpkg_ci_status "${SHPKG_REPO}.ci.status" ok
done
verbose 2 shpkg_ci_status "shpkg_ci.status" ok
}
shpkg_log shpkg_ci main "$@"
exit ${SHPKG_CI_STATUS}