Hash :
fa5824e8
Author :
Thomas de Grivel
Date :
2023-02-15T22:39:25
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 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
#!/bin/sh
set -e
# shpkg
: ${SHPKG_DIR:=~/shpkg}
. "${SHPKG_DIR}/etc/shpkg/profile"
. "${SHPKG_DIR}/share/shpkg/shpkg.subr"
shpkg_config
verbose 2 shpkg_lock shpkg_ci.lock
verbose 2 shpkg_upgrade
if [ "x$1" = "x--upgrade" ]; then
exit
fi
log_status () {
STATUS_FILE="$(log_status_file "$1")"
if [ -f "${STATUS_FILE}" ]; then
cat "${STATUS_FILE}"
else
#echo "unknown"
echo "unknown(${STATUS_FILE})"
fi
}
log_status_file () {
echo "${SHPKG_CI_STATUS_DIR}/$(basename "$1" .log).status"
}
log2html () {
{
TITLE="$(echo "$1" | ansi2html)"
STATUS="$(log_status "$1")"
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="128x128" href="/_images/status_${STATUS}.128.png">
<link rel="icon" type="image/png" sizes="64x64" href="/_images/status_${STATUS}.64.png">
<link rel="icon" type="image/png" sizes="32x32" href="/_images/status_${STATUS}.32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/_images/status_${STATUS}.16.png">
</head>
<body>
<h1>
<img src="/_images/status_${STATUS}.128.png" class="status-${STATUS}"/>
${TITLE}
</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}"/*.log; do
STATUS_FILE="$(log_status_file "$F")"
if [ ! -f "$F.html" ] ||
[ "$F" -nt "$F.html" ] ||
[ "${STATUS_FILE}" -nt "$F.html" ] ||
[ "$0" -nt "$F.html" ]; then
verbose 2 log2html "$F"
fi
done
}
status2png () {
for F in "${SHPKG_CI_STATUS_DIR}"/*.status; do
STATUS="$(cat "$F")"
I="${SHPKG_CI_STATUS_DIR}/$(basename "$F" .status).png"
if ! [ -f "$I" ] ||
[ "$F" -nt "$I" ]; then
cp "${SHPKG_DIR}/share/shpkg/img/status_${STATUS}.64.png" "$I"
fi
done
}
main () {
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
SHPKG_REPO_SRC_DIR="${SHPKG_SRC_DIR}/${SHPKG_REPO_DIR}"
if ! [ -d "${SHPKG_REPO_SRC_DIR}" ]; then
verbose 2 shpkg_clone "${SHPKG_REPO}"
else
verbose 2 shpkg_pull "${SHPKG_REPO}"
fi
SHPKG_REPO_GIT_BRANCH="$(shpkg_git_branch "${SHPKG_REPO}")"
SHPKG_REPO_HASH="$(shpkg_hash "${SHPKG_REPO}")"
verbose 2 shpkg_ci_status "${SHPKG_REPO}.ci.status" running
verbose 2 shpkg_ci_status "${SHPKG_REPO}.ci.branch_${SHPKG_REPO_GIT_BRANCH}.status" running
verbose 2 shpkg_ci_status "${SHPKG_REPO}.ci.commit_${SHPKG_REPO_HASH}.status" running
verbose 2 shpkg_tag_log "${SHPKG_REPO}.ci.log"
verbose 2 shpkg_tag_log "${SHPKG_REPO}.ci.branch_${SHPKG_REPO_GIT_BRANCH}.log"
verbose 2 shpkg_tag_log "${SHPKG_REPO}.ci.commit_${SHPKG_REPO_HASH}.log"
SHPKG_REPO_BUILD_DIR="${SHPKG_CI_BUILD_DIR}/${SHPKG_REPO}"
if ! [ -d "${SHPKG_REPO_BUILD_DIR}" ]; then
# first bootstrap
( verbose 2 shpkg_bootstrap "${SHPKG_REPO_BUILD_DIR}"; )
else
# run shpkg upgrade
( . "${SHPKG_REPO_BUILD_DIR}/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
verbose 2 shpkg_ci_status "${SHPKG_REPO}.ci.branch_${SHPKG_REPO_GIT_BRANCH}.status" ko
verbose 2 shpkg_ci_status "${SHPKG_REPO}.ci.commit_${SHPKG_REPO_HASH}.status" ko
verbose 2 shpkg_ci_status "shpkg_ci.status" ko
fi; )
if verbose 1 cp -p "${SHPKG_REPO_BUILD_DIR}/var/log/shpkg/tags/${SHPKG_REPO}".*.log "${SHPKG_CI_LOG_DIR}"; then
verbose 2 logs2html
verbose 2 status2png
fi
fi
( verbose 2 shpkg_bootstrap -f "${SHPKG_REPO_BUILD_DIR}"; )
( . "${SHPKG_REPO_BUILD_DIR}/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
verbose 2 shpkg_ci_status "${SHPKG_REPO}.ci.branch_${SHPKG_REPO_GIT_BRANCH}.status" ko
verbose 2 shpkg_ci_status "${SHPKG_REPO}.ci.commit_${SHPKG_REPO_HASH}.status" ko
verbose 2 shpkg_ci_status "shpkg_ci.status" ko
fi; )
verbose 2 shpkg_ci_status "${SHPKG_REPO}.ci.status" ok
verbose 2 shpkg_ci_status "${SHPKG_REPO}.ci.branch_${SHPKG_REPO_GIT_BRANCH}.status" ok
verbose 2 shpkg_ci_status "${SHPKG_REPO}.ci.commit_${SHPKG_REPO_HASH}.status" ok
SHPKG_CI_COPY=No
if verbose 1 cp -p "${SHPKG_REPO_BUILD_DIR}/var/log/shpkg/tags/${SHPKG_REPO}".*.log "${SHPKG_CI_LOG_DIR}"; then
SHPKG_CI_COPY=Yes
fi
if verbose 1 cp -p "${SHPKG_DIR}/var/log/shpkg/tags/${SHPKG_REPO}.ci.log" "${SHPKG_DIR}/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
verbose 2 status2png
fi
done
verbose 2 shpkg_ci_status "shpkg_ci.status" ok
verbose 2 logs2html
verbose 2 status2png
}
if [ "x$1" = "x--clean" ]; then
rm -rf "${SHPKG_CI_DIR}"
exit
fi
shpkg_log shpkg_ci main "$@"