diff --git a/Taskfile.yml b/Taskfile.yml index d4f87abf26c9d1801577bf4aa3f8b1f690659677..9e1cbe7a3fb9bb7dabc3bfcc503c887dfe407b8e 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -23,9 +23,11 @@ tasks: - source/**/*.mod - dist/** - update-hashes: - desc: Calculate the nix hash + update-code: + desc: Update the code, calculate hashes and update version aliases: - - ch + - uc cmds: - - update-hashes --file={{.TASKFILE_DIR}} + - update-hashes + - update-version + silent: true diff --git a/flake.nix b/flake.nix index 2d9900017539739f2a82c9d476df9b5671362655..7a0f268e5e485cf5e409d10397118597b93920f8 100644 --- a/flake.nix +++ b/flake.nix @@ -130,10 +130,15 @@ buildRoot = ./.; in { - default = { + default = rec { name = projectDefinition.name; - scripts = { + scripts = let + versionsTool = inputs.versionsTool.defaultPackage."${builtins.currentSystem}"; + + workingDirectory = builtins.getEnv "PWD"; + + in { treefmt.exec = '' ${config.treefmt.build.wrapper}/bin/treefmt ''; @@ -155,11 +160,11 @@ }; update-hashes.exec = import ./system/scripts/update-hashes.nix { - inherit pkgs config buildRoot projectDefinition; + inherit pkgs config buildRoot projectDefinition workingDirectory; }; update-version.exec = import ./system/scripts/update-version.nix { - inherit pkgs config buildRoot projectDefinition versionsTool; + inherit pkgs config buildRoot projectDefinition versionsTool workingDirectory; }; # build-image.exec = import ./system/scripts/build-images.nix { @@ -170,6 +175,9 @@ imports = []; packages = with pkgs; [ + inputs.versionsTool.defaultPackage."${builtins.currentSystem}" + + go-task ]; diff --git a/project.nix b/project.nix index c30baed3a2477a01c95a37dd3a116c3eb06aa768..bb80d5a8db4c8ea7cabf702fc6ab8e262b5258fc 100644 --- a/project.nix +++ b/project.nix @@ -5,6 +5,6 @@ supportedSystems = ["x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin"]; compileForSystems = ["linux/arm64" "linux/amd64" "darwin/amd64" "windows/amd64"]; modulePath = "gitlab.schukai.com/oss/bob"; - version = "0.1.0"; ## do not change this line; it will be updated automatically - vendorHash = "sha256-6zNRYYddNcOx6G9wSKGv89CfSCxrG0qpSDfBStwNdks="; + version = "0.4.10"; ## do not change this line; it will be updated automatically + vendorHash = null; } diff --git a/system/scripts/update-hashes.nix b/system/scripts/update-hashes.nix index 5762c5ac3572802466c2865bf817c741617396f9..ad6973187eaa9ee9f19ce723dcba58d683135f6b 100644 --- a/system/scripts/update-hashes.nix +++ b/system/scripts/update-hashes.nix @@ -2,6 +2,7 @@ pkgs, buildRoot, projectDefinition, + workingDirectory, ... }: let serviceSourcePath = "${buildRoot}/"; @@ -11,33 +12,17 @@ in '' ${common} - for arg in "$@"; do - case $arg in - --file=*) - filepath="''${arg#*=}" - shift - ;; - *) - ;; - esac - done - - if [[ -z "$filepath" ]]; then - echo_fail "No file path provided" - exit 1 - fi - defaultHash="${pkgs.lib.fakeHash}" - ${pkgs.gnused}/bin/sed -i "s|vendorHash\s*=\s*null|vendorHash = \"$defaultHash\"|" $filepath/project.nix - ${pkgs.gnused}/bin/sed -i "s|vendorHash\s*=\s*\".*\"|vendorHash = \"$defaultHash\"|" $filepath/project.nix - + ${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 + RESULT=$(${pkgs.nix}/bin/nix build .#goPkg 2>&1) if [[ $? -ne 0 ]]; then ## check if RESULT contain vendorHash = null; then set to null and rebuild if [[ "$RESULT" == *"vendorHash = null"* ]]; then - ${pkgs.gnused}/bin/sed -i "s|vendorHash\s*=\s*\".*\"|vendorHash = null|" $filepath/project.nix + ${pkgs.gnused}/bin/sed -i "s|vendorHash\s*=\s*\".*\"|vendorHash = null|g" ${workingDirectory}/project.nix RESULT=$(${pkgs.nix}/bin/nix build .#goPkg 2>&1) if [[ $? -ne 0 ]]; then @@ -47,7 +32,7 @@ in '' 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" $filepath/project.nix + ${pkgs.git}/bin/git commit -m "chore: Update vendorHash to null" ${workingDirectory}/project.nix exit 0 fi @@ -57,15 +42,11 @@ in '' HASH=$(echo "$RESULT" | grep 'got:' | awk '{print $2}') if [[ -z "$HASH" ]]; then echo_fail "Could not get the hash" - ${pkgs.gnused}/bin/sed -i 's|vendorHash\s*=\s*".*"|vendorHash = null|' $filepath/project.nix - ${pkgs.git}/bin/git add $filepath/project.nix - ${pkgs.git}/bin/git commit -m "chore: Update vendorHash to null" + ${pkgs.gnused}/bin/sed -i 's|vendorHash\s*=\s*".*"|vendorHash = null|g' ${workingDirectory}/project.nix exit 1 fi - ${pkgs.gnused}/bin/sed -i "s|vendorHash\s*=\s*\".*\"|vendorHash = \"''${HASH}\"|" $filepath/project.nix - ${pkgs.git}/bin/git add $filepath/project.nix - ${pkgs.git}/bin/git commit -m "chore: Update vendorHash to ''${HASH}" + ${pkgs.gnused}/bin/sed -i "s|vendorHash\s*=\s*\".*\"|vendorHash = \"''${HASH}\"|g" ${workingDirectory}/project.nix echo_ok "Hash updated, new hash is ''${HASH}'" diff --git a/system/scripts/update-version.nix b/system/scripts/update-version.nix index 19369dedc683479283343f83bb52b3a1789ccdfe..2c32c6a3462e21dbd1690acc11f2c04b6f560dbb 100644 --- a/system/scripts/update-version.nix +++ b/system/scripts/update-version.nix @@ -3,48 +3,43 @@ buildRoot, projectDefinition, versionsTool, + workingDirectory, ... }: let serviceSourcePath = "${buildRoot}/"; common = import ./common.nix {inherit pkgs;}; + in '' - #!${pkgs.bash}/bin/bash +#!${pkgs.bash}/bin/bash - ${common} +${common} +cmd=${versionsTool}/bin/version - - set -x - echo ${versionsTool} +echo_step "Checking if there is a new version" +if ! $cmd auto --git --exit-code-if-no-bump ; then + echo_step "No version bump" +fi +VERSION=$($cmd print --git) +echo_step "Current version is ''${VERSION}" + +if [[ -z "''${VERSION}" ]]; then + echo_fail "Could not get the current version" + exit 1 +fi -'' -# if [[ -z "$filepath" ]]; then -# echo_fail "No file path provided" -# exit 1 -# fi -# -# for arg in "$@"; do -# case $arg in -# --file=*) -# filepath="''${arg#*=}" -# shift -# ;; -# *) -# ;; -# esac -# done - - -# -# NEWVERSION=$(${version}/bin/version predict --git exit-code-if-no-bump) -# echo_step "No version bump found" -# if [[ -z "''${NEWVERSION}" ]]; then -# echo_fail "Could not get the new version" -# ${pkgs.gnused}/bin/sed -i "s/version\s*=\s*\".*\"/version = \"''${NEWVERSION}\"/" ${buildRoot}/project.nix -# if ! ${pkgs.git}/bin/git commit -m "chore: Bump version to ''${NEWVERSION}" ; then -# if ! ${pkgs.git}/bin/git tag -a "''${NEWVERSION}" -m "chore: Release ''${NEWVERSION} - DO_RELEASE" ; then -# echo_ok "Tag ''${NEWVERSION} created and pushed" +echo_step "Replacing 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 +fi + +echo_ok "Version replaced" + +''