From 26c63f85c65a2959af7cb3d03636d9c6c637db38 Mon Sep 17 00:00:00 2001
From: Volker Schukai <volker.schukai@schukai.com>
Date: Mon, 29 Jan 2024 16:42:17 +0100
Subject: [PATCH] fix: test scripts

---
 flake.nix                         | 12 ++----------
 project.nix                       |  1 +
 system/scripts/update-hashes.nix  |  5 ++---
 system/scripts/update-version.nix | 20 +++++++++++++++-----
 4 files changed, 20 insertions(+), 18 deletions(-)

diff --git a/flake.nix b/flake.nix
index 43cf1fd..f55a6ae 100644
--- a/flake.nix
+++ b/flake.nix
@@ -55,14 +55,6 @@
           
             bob = let
               projectDefinition = import ./project.nix;
-
-              projectHash =
-                if (self' ? shortRev)
-                then self'.shortRev
-                else "dirty";
-
-              lastModifiedDate =
-                self'.lastModifiedDate or self'.lastModified or "19700101";
               sourcePath = ./source;
             in
               # https://nixos.wiki/wiki/Go
@@ -79,10 +71,10 @@
                 ldflags = [
                   "-s -w"
                   "-X '${projectDefinition.modulePath}/release.version=${projectDefinition.version}'"
-                  "-X '${projectDefinition.modulePath}/release.commit=${projectHash}'"
+                  "-X '${projectDefinition.modulePath}/release.commit=${projectDefinition.commitHash}'"
                   "-X '${projectDefinition.modulePath}/release.name=${projectDefinition.name}'"
                   "-X '${projectDefinition.modulePath}/release.mnemonic=${projectDefinition.mnemonic}'"
-                  "-X '${projectDefinition.modulePath}/release.buildDate=${lastModifiedDate}'"
+                  "-X '${projectDefinition.modulePath}/release.buildDate=${builtins.date}'"
                 ];
 
                 #vendorHash = null;
diff --git a/project.nix b/project.nix
index 13ba2c4..75cc252 100644
--- a/project.nix
+++ b/project.nix
@@ -7,4 +7,5 @@
   modulePath = "gitlab.schukai.com/oss/bob";
   version = "0.4.11"; ## do not change this line; it will be updated automatically
   vendorHash = null; ## do not change this line; it will be updated automatically
+  commitHash = "f6b8149"; ## do not change this line; it will be updated automatically
 }
diff --git a/system/scripts/update-hashes.nix b/system/scripts/update-hashes.nix
index ad69731..ae4799e 100644
--- a/system/scripts/update-hashes.nix
+++ b/system/scripts/update-hashes.nix
@@ -11,9 +11,10 @@ in ''
   #!${pkgs.bash}/bin/bash
 
   ${common}
-
+  
   defaultHash="${pkgs.lib.fakeHash}"
 
+  echo_step "Reset vendorHash to default value: $defaultHash"
   ${pkgs.gnused}/bin/sed -i "s|vendorHash\s*=\s*null|vendorHash = \"$defaultHash\"|g" ${workingDirectory}/project.nix
   ${pkgs.gnused}/bin/sed -i "s|vendorHash\s*=\s*\"[^\"]\"|vendorHash = \"$defaultHash\"|g" ${workingDirectory}/project.nix
   
@@ -31,8 +32,6 @@ in ''
         fi
 
         echo_ok "No dependencies found and vendorHash is set to null."
-        ${pkgs.git}/bin/git add $filepath/project.nix
-        ${pkgs.git}/bin/git commit -m "chore: Update vendorHash to null" ${workingDirectory}/project.nix
         exit 0
 
     fi
diff --git a/system/scripts/update-version.nix b/system/scripts/update-version.nix
index 2c32c6a..5827fc9 100644
--- a/system/scripts/update-version.nix
+++ b/system/scripts/update-version.nix
@@ -17,10 +17,21 @@ ${common}
 
 cmd=${versionsTool}/bin/version  
 
+echo_step "Getting current commit hash"
+HASH=$(${pkgs.git}/bin/git  -C ${workingDirectory}/ rev-parse --short HEAD)
+echo_ok "Current commit hash is ''${HASH}"
+  
+echo_step "Replacing hash in project.nix"  
+if ! ${pkgs.gnused}/bin/sed -i "s|commitHash\s*=\s*\"[^\"]*\"|commitHash = \"''${HASH}\"|g" ${workingDirectory}/project.nix ; then
+    echo_fail "Hash not replaced"
+    exit 1
+fi
+
+echo_ok "Hash updated"
 
 echo_step "Checking if there is a new version"
 if ! $cmd auto --git --exit-code-if-no-bump ; then
-    echo_step "No version bump"
+    echo_fail "No version jump to a new version"
 fi
 
 VERSION=$($cmd print --git)
@@ -31,15 +42,14 @@ if [[ -z "''${VERSION}" ]]; then
     exit 1
 fi
 
-
-echo_step "Replacing version in project.nix"
+echo_step "Check version in project.nix"
 
 # check if version replaced
 if ! ${pkgs.gnused}/bin/sed -i "s/version\s*=\s*\"[^\"]*\"/version = \"''${VERSION}\"/g" ${workingDirectory}/project.nix; then
     echo_fail "Version not replaced"
-    exit 1
+    exit 1    
 fi
 
-echo_ok "Version replaced"
+echo_ok "Version and hash updated"
 
 ''
-- 
GitLab