Commit b4dd2c7e919af9874228d88340b57e4b7d788022

Thomas de Grivel 2023-02-14T18:34:45

wip shpkg_ci

diff --git a/bin/shpkg_ci b/bin/shpkg_ci
index 19fad65..3ff0e94 100755
--- a/bin/shpkg_ci
+++ b/bin/shpkg_ci
@@ -20,7 +20,7 @@ SHPKG_CI_STATUS_DIR="${SHPKG_CI_DIR}/status/${SHPKG_OS_}/${SHPKG_TARGET}"
 
 log2html () {
     {
-        echo <<EOF
+        cat <<EOF
 <!DOCTYPE html>
 <html lang="en">
   <head>
@@ -29,7 +29,7 @@ log2html () {
     <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
     <title>
 EOF
-        echo <<EOF
+        cat <<EOF
 </title>
     <link rel="stylesheet" href="/_assets/app.css">
     <script defer type="text/javascript" src="/_assets/app.js"></script>
@@ -42,18 +42,21 @@ EOF
     <h1>
 EOF
         echo "$1" | ansi2html
-        echo <<EOF
+        cat <<EOF
 </h1>
+    <code>
 EOF
         ansi2html < "$1"
-        echo <<EOF
+        cat <<EOF
+</code>
     <div class="footer">
       <a href="https://git.kmx.io/kmx.io/shpkg">shpkg_ci</a>
     </div>
   </body>
 </html>
 EOF
-    } > "$1.html"
+    } > "$1.html.tmp"
+    mv "$1.html.tmp" "$1.html"
 }
 
 logs2html () {
diff --git a/share/shpkg/shpkg.subr b/share/shpkg/shpkg.subr
index eee390e..2299498 100644
--- a/share/shpkg/shpkg.subr
+++ b/share/shpkg/shpkg.subr
@@ -290,9 +290,9 @@ shpkg_clone () {
                   verbose 1 git submodule init &&
                   verbose 1 git submodule update
             )
-            SHPKG_REPO_VERSION="$(shpkg_version "${SHPKG_REPO}")"
+            SHPKG_REPO_HASH="$(shpkg_hash "${SHPKG_REPO}")"
             ( verbose 2 shpkg_tag_log "${SHPKG_REPO}.tree_${SHPKG_REPO_GIT_BRANCH}.log"; )
-            ( verbose 2 shpkg_tag_log "${SHPKG_REPO}.version_${SHPKG_REPO_VERSION}.log"; )
+            ( verbose 2 shpkg_tag_log "${SHPKG_REPO}.commit_${SHPKG_REPO_HASH}.log"; )
         fi
     done
 }
@@ -344,6 +344,18 @@ shpkg_clean_sources () {
     done
 }
 
+shpkg_hash () {
+    SHPKG_REPO_DIR="$(shpkg_dir "$1")"
+    if [ "x${SHPKG_REPO_DIR}" = "x" ]; then
+        err 1 "shpkg_version: unknown repo: $SHPKG_REPO"
+    fi
+    SHPKG_REPO_SRC_DIR="${SHPKG_SRC_DIR}/${SHPKG_REPO_DIR}"
+    if [ -d "${SHPKG_REPO_SRC_DIR}/.git" ]; then
+        SHPKG_REPO_HASH="$(git -C "${SHPKG_REPO_SRC_DIR}" show-ref --head HEAD | cut -d ' ' -f 1 | head -n 1)"
+        echo "${SHPKG_REPO_HASH}"
+    fi
+}
+
 shpkg_version () {
     SHPKG_REPO_DIR="$(shpkg_dir "$1")"
     if [ "x${SHPKG_REPO_DIR}" = "x" ]; then