Skip to content
Snippets Groups Projects
Verified Commit d36f2787 authored by Volker Schukai's avatar Volker Schukai :alien:
Browse files

chore: update scripts

parent 562eff45
No related branches found
No related tags found
No related merge requests found
......@@ -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
......@@ -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
];
......
......@@ -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;
}
......@@ -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}'"
......
......@@ -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"
''
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment