-
Volker Schukai authoredVolker Schukai authored
update-version.nix 1.39 KiB
{
pkgs,
buildRoot,
projectDefinition,
versionsTool,
workingDirectory,
...
}: let
serviceSourcePath = "${buildRoot}/";
common = import ./common.nix {inherit pkgs;};
in ''
#!${pkgs.bash}/bin/bash
${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_fail "No version jump to a new version"
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
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
fi
${pkgs.git}/bin/git -C ${workingDirectory}/ commit -m "chore: Version and hash updated to $VERSION, $HASH" ${workingDirectory}/project.nix
echo_ok "Version and hash updated"
''