diff --git a/flake.nix b/flake.nix index 43cf1fda9392d0c8684317e0be55a53596be09ce..f55a6aec5884c26c15c36344d620169914900074 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 13ba2c4686ef4c1fed0b5c656763b26acf791a5a..75cc2527a76926bf6a1455e9fb69a7d2a7a6d298 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 ad6973187eaa9ee9f19ce723dcba58d683135f6b..ae4799e9a490494c776e8e769d3a791ceabdb04c 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 2c32c6a3462e21dbd1690acc11f2c04b6f560dbb..5827fc932883c66a3895c785dba8f6439234cbda 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" ''