diff --git a/bin/shpkg_ci b/bin/shpkg_ci
index e643e5b..32eb7dc 100755
--- a/bin/shpkg_ci
+++ b/bin/shpkg_ci
@@ -34,141 +34,4 @@ elif [ "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")"
- IMG="$(basename "$1" .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>
- <pre><code>
-EOF
- ansi2html < "$1"
- cat <<EOF
-</code></pre>
- <div class="ci-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"
- verbose 2 shpkg_ci_changed_file "$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
-}
-
-main () {
- echo -n > "${SHPKG_CI_CHANGED_FILES}"
- 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
- verbose -n 2 shpkg upgrade "${SHPKG_REPO}"
- if shpkg upgrade "${SHPKG_REPO}"; then
- verbose 2 shpkg_ci_status "${SHPKG_REPO}.upgrade.status" ok
- else
- exit 1
- 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 shpkg_ci_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
- verbose -n 2 shpkg install "${SHPKG_REPO}"
- if shpkg install "${SHPKG_REPO}"; then
- verbose 2 shpkg_ci_status "${SHPKG_REPO}.install.status" ok
- else
- exit 1
- 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 shpkg_ci_status2png
- fi
- done
- verbose 2 shpkg_ci_status "shpkg_ci.status" ok
- verbose 2 logs2html
- verbose 2 shpkg_ci_status2png
-}
-
-shpkg_log shpkg_ci main "$@"
+shpkg_log shpkg_ci shpkg_ci_main "$@"
diff --git a/share/shpkg/shpkg.subr b/share/shpkg/shpkg.subr
index 733744d..158df70 100644
--- a/share/shpkg/shpkg.subr
+++ b/share/shpkg/shpkg.subr
@@ -90,7 +90,8 @@ shpkg_log () {
SHPKG_NAME="$1"
shift
shpkg_start_logging "${SHPKG_NAME}"
- shpkg_redirect_err "$@" | tee -a "${SHPKG_LOG}"
+ { shpkg_redirect_err "$@"; RESULT=$?; } | tee -a "${SHPKG_LOG}"
+ return $RESULT
}
shpkg_redirect_err () {
@@ -430,8 +431,7 @@ shpkg_build () {
if shpkg__tag_is_absent build-done; then
verbose 2 shpkg_ci_status "${SHPKG_REPO}.build.status" running
( if ! verbose 2 shpkg_configure "${SHPKG_REPO}"; then
- verbose 2 shpkg_ci_status "${SHPKG_REPO}.build.status" ko
- false
+ exit 1
fi; )
( verbose 2 shpkg_tag_log "${SHPKG_REPO}.build.log"; )
SHPKG_REPO_VERSION="$(shpkg_version "${SHPKG_REPO}")"
@@ -441,14 +441,14 @@ shpkg_build () {
verbose 2 shpkg_ci_status "${SHPKG_REPO}.build.status" ok
else
verbose 2 shpkg_ci_status "${SHPKG_REPO}.build.status" ko
- false
+ exit 1
fi ; )
elif [ -f "${SHPKG_SRC_DIR}/${SHPKG_REPO_DIR}/CMakeLists.txt" ]; then
if verbose 1 cmake -j "${SHPKG_NCPU}" --build "${SHPKG_REPO_OBJ_DIR}"; then
verbose 2 shpkg_ci_status "${SHPKG_REPO}.build.status" ok
else
verbose 2 shpkg_ci_status "${SHPKG_REPO}.build.status" ko
- false
+ exit 1
fi
fi
shpkg__tag_write build-done
@@ -846,6 +846,143 @@ shpkg_ci_changed_file () {
cut_prefix "${SHPKG_CI_DIR}" "$1" >> "${SHPKG_CI_CHANGED_FILES}"
}
+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")"
+ IMG="$(basename "$1" .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>
+ <pre><code>
+EOF
+ ansi2html < "$1"
+ cat <<EOF
+</code></pre>
+ <div class="ci-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"
+ verbose 2 shpkg_ci_changed_file "$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
+}
+
+shpkg_ci_main () {
+ echo -n > "${SHPKG_CI_CHANGED_FILES}"
+ 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
+ verbose -n 2 shpkg upgrade "${SHPKG_REPO}"
+ if shpkg upgrade "${SHPKG_REPO}"; then
+ verbose 2 shpkg_ci_status "${SHPKG_REPO}.upgrade.status" ok
+ else
+ exit 1
+ 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 shpkg_ci_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
+ verbose -n 2 shpkg install "${SHPKG_REPO}"
+ if shpkg install "${SHPKG_REPO}"; then
+ verbose 2 shpkg_ci_status "${SHPKG_REPO}.install.status" ok
+ else
+ exit 1
+ 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 shpkg_ci_status2png
+ fi
+ done
+ verbose 2 shpkg_ci_status "shpkg_ci.status" ok
+ verbose 2 logs2html
+ verbose 2 shpkg_ci_status2png
+}
+
# state machine :
# any -> running
# running -> ko, ok