Hash :
e3eab53f
Author :
Thomas de Grivel
Date :
2023-02-15T01:38:01
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
#!/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.lock
verbose 2 shpkg_upgrade
# Configuration
: ${SHPKG_CI_DIR:=${SHPKG_DIR}/ci}
SHPKG_CI_BUILD_DIR="${SHPKG_CI_DIR}/build"
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 () {
{
TITLE="$(echo "$1" | ansi2html)"
STATUS="$(< "${SHPKG_CI_STATUS_DIR}/$(basename "$1" .log).status")"
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}"/"${SHPKG_REPO}".*.log; do
if ! [ -f "$F.html" ] || [ "$F" -nt "$F.html" ] || [ "$0" -nt "$F.html" ]; then
verbose 2 log2html "$F"
fi
done
}
shpkg_build_status () {
shpkg_ci_status "$1.build.status" "$2"
}
# 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
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_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"
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
SHPKG_REPO_BUILD_DIR="${SHPKG_CI_BUILD_DIR}/${SHPKG_REPO}"
# first bootstrap
if ! [ -d "${SHPKG_REPO_BUILD_DIR}" ]; then
( verbose 2 shpkg_bootstrap "${SHPKG_REPO_BUILD_DIR}"; )
else
# check 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
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; )
if verbose 1 cp -p "${SHPKG_REPO_BUILD_DIR}/var/log/shpkg/tags/${SHPKG_REPO}".*.log "${SHPKG_CI_LOG_DIR}" ||
verbose 1 cp -p "${SHPKG_DIR}/var/log/shpkg/tags/${SHPKG_REPO}.ci.log" "${SHPKG_CI_LOG_DIR}"; then
verbose 2 logs2html
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
done
verbose 2 shpkg_ci_status "shpkg_ci.status" ok
}
if [ "x$1" = "x--clean" ]; then
rm -rf "${SHPKG_CI_DIR}"
exit
fi
shpkg_log shpkg_ci main "$@"