From a6c1c4ce9b2596b932d9047e30648f9525ea22de Mon Sep 17 00:00:00 2001 From: luitvm <38038189+eltee1@users.noreply.github.com> Date: Mon, 2 Mar 2026 12:57:18 +0100 Subject: [PATCH 1/4] add functions specific for getting the git hash for database-build and database-modules to Utillity.rb and use those new functions for logging these git-hashes in the system.constants table by additions to the function add_build_constants. --- bin/ScriptCommands.rb | 2 ++ bin/Utility.rb | 45 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/bin/ScriptCommands.rb b/bin/ScriptCommands.rb index 213fa3d..87fc6db 100644 --- a/bin/ScriptCommands.rb +++ b/bin/ScriptCommands.rb @@ -440,6 +440,8 @@ def add_build_constants(schema = 'system') add_constant 'CURRENT_DATABASE_VERSION', get_version(), schema unless $version.nil? add_constant 'CURRENT_DATABASE_PRODUCT', $product.to_s, schema unless $product.nil? add_constant 'CURRENT_GIT_REVISION', Utility.get_git_hash, schema if !$vcs.nil? && $vcs == :git + add_constant 'DATABASE_MODULES_GIT_REVISION', Utility.get_git_hash_modules, schema if !$vcs.nil? && $vcs == :git + add_constant 'DATABASE_BUILD_GIT_REVISION', Utility.get_git_hash_build, schema if !$vcs.nil? && $vcs == :git add_constant 'CURRENT_SVN_REVISION', Utility.get_svn_head_revision, schema if !$vcs.nil? && $vcs == :svn add_constant 'CURRENT_DATABASE_BUILD_DATE', Time.now.strftime('%d-%m-%Y %H:%M:%S'), schema add_constant 'CURRENT_DATABASE_BUILD_USER', Etc.getlogin, schema rescue nil diff --git a/bin/Utility.rb b/bin/Utility.rb index 19fa959..a442998 100644 --- a/bin/Utility.rb +++ b/bin/Utility.rb @@ -101,6 +101,51 @@ def self.get_git_hash raise "Could not read GIT hash with command: #{cmd}" end + + def self.get_git_hash_modules + raise 'Git bin path not set ($git_bin_path)' if $git_bin_path.nil? + raise "Git bin path not found ($git_bin_path = \"#{$git_bin_path}\")" unless ((File.exist?($git_bin_path) && File.directory?($git_bin_path)) || ($git_bin_path.empty?)) + + curr_dir = Dir.pwd + Dir.chdir($database_modules_sql_path) + cmd = "\"#{$git_bin_path}git\" log -1 --pretty=format:%h" + socket = IO.popen(cmd) + begin + if line = socket.gets then + line = line.strip + raise "Illegal git hash found: #{line}" if line.length > 10 + return line + end + ensure + socket.close + Dir.chdir(curr_dir) + end + raise "Could not read GIT hash with command: #{cmd}" + end + + + def self.get_git_hash_build + raise 'Git bin path not set ($git_bin_path)' if $git_bin_path.nil? + raise "Git bin path not found ($git_bin_path = \"#{$git_bin_path}\")" unless ((File.exist?($git_bin_path) && File.directory?($git_bin_path)) || ($git_bin_path.empty?)) + + curr_dir = Dir.pwd + Dir.chdir($database_build_sql_path) + cmd = "\"#{$git_bin_path}git\" log -1 --pretty=format:%h" + socket = IO.popen(cmd) + begin + if line = socket.gets then + line = line.strip + raise "Illegal git hash found: #{line}" if line.length > 10 + return line + end + ensure + socket.close + Dir.chdir(curr_dir) + end + raise "Could not read GIT hash with command: #{cmd}" + end + + def self.get_svn_head_revision raise 'SVN bin path not set ($svn_bin_path)' if $svn_bin_path.nil? raise "SVN bin path not found ($svn_bin_path = \"#{$svn_bin_path}\")" unless ((File.exist?($svn_bin_path) && File.directory?($svn_bin_path)) || ($svn_bin_path.empty?)) From ff396dfa9bb9374e6e7daca48704167421aa21c0 Mon Sep 17 00:00:00 2001 From: luitvm <38038189+eltee1@users.noreply.github.com> Date: Tue, 3 Mar 2026 09:16:38 +0100 Subject: [PATCH 2/4] make git hash check generic by adding a parameter to the function. Add function that checks for uncommitted code and fails the build if finds any. Todo: implement the call of that function. --- bin/ScriptCommands.rb | 11 ++++++----- bin/Utility.rb | 42 ++++++++++-------------------------------- 2 files changed, 16 insertions(+), 37 deletions(-) diff --git a/bin/ScriptCommands.rb b/bin/ScriptCommands.rb index 87fc6db..9faa6ce 100644 --- a/bin/ScriptCommands.rb +++ b/bin/ScriptCommands.rb @@ -20,7 +20,7 @@ def has_any_build_flag(*flag) def set_database_name(database_name) database_name = database_name.to_s database_name = database_name.gsub('#', Utility.get_svn_head_revision) if database_name.include?('#') && $vcs == :svn - database_name = database_name.gsub('#', Utility.get_git_hash) if database_name.include?('#') && $vcs == :git + database_name = database_name.gsub('#', Utility.get_git_hash($product_sql_path)) if database_name.include?('#') && $vcs == :git $database_name = database_name $logger.writeln "Database name = #{$database_name}" end @@ -41,7 +41,7 @@ def default_database_name(database_name) def set_version(version) version = version.to_s version = version.gsub('#', Utility.get_svn_head_revision) if version.include?('#') && $vcs == :svn - version = version.gsub('#', Utility.get_git_hash) if version.include?('#') && $vcs == :git + version = version.gsub('#', Utility.get_git_hash($product_sql_path)) if version.include?('#') && $vcs == :git $version = version $logger.writeln "Version = #{$version}" set_database_name($database_name_prefix + '-' + $product.to_s + '-' + $version) if $database_name.nil? @@ -439,14 +439,15 @@ def add_build_constants(schema = 'system') add_constant 'CURRENT_DATABASE_NAME', get_database_name(), schema add_constant 'CURRENT_DATABASE_VERSION', get_version(), schema unless $version.nil? add_constant 'CURRENT_DATABASE_PRODUCT', $product.to_s, schema unless $product.nil? - add_constant 'CURRENT_GIT_REVISION', Utility.get_git_hash, schema if !$vcs.nil? && $vcs == :git - add_constant 'DATABASE_MODULES_GIT_REVISION', Utility.get_git_hash_modules, schema if !$vcs.nil? && $vcs == :git - add_constant 'DATABASE_BUILD_GIT_REVISION', Utility.get_git_hash_build, schema if !$vcs.nil? && $vcs == :git + add_constant 'CURRENT_GIT_REVISION', Utility.get_git_hash($product_sql_path), schema if !$vcs.nil? && $vcs == :git + add_constant 'DATABASE_MODULES_GIT_REVISION', Utility.get_git_hash($database_modules_sql_path), schema if !$vcs.nil? && $vcs == :git + add_constant 'DATABASE_BUILD_GIT_REVISION', Utility.get_git_hash($database_build_sql_path), schema if !$vcs.nil? && $vcs == :git add_constant 'CURRENT_SVN_REVISION', Utility.get_svn_head_revision, schema if !$vcs.nil? && $vcs == :svn add_constant 'CURRENT_DATABASE_BUILD_DATE', Time.now.strftime('%d-%m-%Y %H:%M:%S'), schema add_constant 'CURRENT_DATABASE_BUILD_USER', Etc.getlogin, schema rescue nil add_constant 'CURRENT_DATABASE_BUILD_NODE', Etc.uname[:nodename], schema rescue nil add_constant 'CURRENT_DATABASE_BUILD_VERSION', get_database_build_version(), schema + add_constant 'TEST', Utility.get_git_status($database_build_sql_path), schema if !$vcs.nil? && $vcs == :git end def cluster_tables diff --git a/bin/Utility.rb b/bin/Utility.rb index a442998..6d886d0 100644 --- a/bin/Utility.rb +++ b/bin/Utility.rb @@ -80,56 +80,35 @@ def self.get_last_cmd_output(lines) return lines.last(lastnum).join("") end - def self.get_git_hash - raise 'Git bin path not set ($git_bin_path)' if $git_bin_path.nil? - raise "Git bin path not found ($git_bin_path = \"#{$git_bin_path}\")" unless ((File.exist?($git_bin_path) && File.directory?($git_bin_path)) || ($git_bin_path.empty?)) - - curr_dir = Dir.pwd - Dir.chdir($product_sql_path) - cmd = "\"#{$git_bin_path}git\" log -1 --pretty=format:%h" - socket = IO.popen(cmd) - begin - if line = socket.gets then - line = line.strip - raise "Illegal git hash found: #{line}" if line.length > 10 - return line - end - ensure - socket.close - Dir.chdir(curr_dir) - end - raise "Could not read GIT hash with command: #{cmd}" - end - - def self.get_git_hash_modules + def self.get_git_status(gitpath) raise 'Git bin path not set ($git_bin_path)' if $git_bin_path.nil? raise "Git bin path not found ($git_bin_path = \"#{$git_bin_path}\")" unless ((File.exist?($git_bin_path) && File.directory?($git_bin_path)) || ($git_bin_path.empty?)) curr_dir = Dir.pwd - Dir.chdir($database_modules_sql_path) - cmd = "\"#{$git_bin_path}git\" log -1 --pretty=format:%h" + Dir.chdir(gitpath) + cmd = "\"#{$git_bin_path}git\" status -s" socket = IO.popen(cmd) begin - if line = socket.gets then - line = line.strip - raise "Illegal git hash found: #{line}" if line.length > 10 + line = socket.gets + if line != nil + raise "Uncommitted code detected!: #{line}" return line + else return end ensure socket.close Dir.chdir(curr_dir) end - raise "Could not read GIT hash with command: #{cmd}" + raise "Could not read GIT status with command: #{cmd}" end - - def self.get_git_hash_build + def self.get_git_hash(gitpath) raise 'Git bin path not set ($git_bin_path)' if $git_bin_path.nil? raise "Git bin path not found ($git_bin_path = \"#{$git_bin_path}\")" unless ((File.exist?($git_bin_path) && File.directory?($git_bin_path)) || ($git_bin_path.empty?)) curr_dir = Dir.pwd - Dir.chdir($database_build_sql_path) + Dir.chdir(gitpath) cmd = "\"#{$git_bin_path}git\" log -1 --pretty=format:%h" socket = IO.popen(cmd) begin @@ -145,7 +124,6 @@ def self.get_git_hash_build raise "Could not read GIT hash with command: #{cmd}" end - def self.get_svn_head_revision raise 'SVN bin path not set ($svn_bin_path)' if $svn_bin_path.nil? raise "SVN bin path not found ($svn_bin_path = \"#{$svn_bin_path}\")" unless ((File.exist?($svn_bin_path) && File.directory?($svn_bin_path)) || ($svn_bin_path.empty?)) From f0ff4c3975300227415a974c4e0d077e0231341f Mon Sep 17 00:00:00 2001 From: luitvm <38038189+eltee1@users.noreply.github.com> Date: Tue, 3 Mar 2026 09:56:37 +0100 Subject: [PATCH 3/4] add function check_uncommitted_code to ScriptCommands, is called in the load.rb of the product. --- bin/ScriptCommands.rb | 6 +++++- bin/Utility.rb | 1 - 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/bin/ScriptCommands.rb b/bin/ScriptCommands.rb index 9faa6ce..ab1444f 100644 --- a/bin/ScriptCommands.rb +++ b/bin/ScriptCommands.rb @@ -120,6 +120,11 @@ def create_database(*params) end end + def check_uncommited_code(repo) + $logger.writeln "Checking for uncommitted code in repo #{repo}..." + Utility.get_git_status(repo) + end + def clear_log $logger.clear end @@ -447,7 +452,6 @@ def add_build_constants(schema = 'system') add_constant 'CURRENT_DATABASE_BUILD_USER', Etc.getlogin, schema rescue nil add_constant 'CURRENT_DATABASE_BUILD_NODE', Etc.uname[:nodename], schema rescue nil add_constant 'CURRENT_DATABASE_BUILD_VERSION', get_database_build_version(), schema - add_constant 'TEST', Utility.get_git_status($database_build_sql_path), schema if !$vcs.nil? && $vcs == :git end def cluster_tables diff --git a/bin/Utility.rb b/bin/Utility.rb index 6d886d0..2f289fe 100644 --- a/bin/Utility.rb +++ b/bin/Utility.rb @@ -80,7 +80,6 @@ def self.get_last_cmd_output(lines) return lines.last(lastnum).join("") end - def self.get_git_status(gitpath) raise 'Git bin path not set ($git_bin_path)' if $git_bin_path.nil? raise "Git bin path not found ($git_bin_path = \"#{$git_bin_path}\")" unless ((File.exist?($git_bin_path) && File.directory?($git_bin_path)) || ($git_bin_path.empty?)) From ac73ecd5f548be6152fa78122ac80fa99d6c90e7 Mon Sep 17 00:00:00 2001 From: luitvm <38038189+eltee1@users.noreply.github.com> Date: Tue, 3 Mar 2026 11:31:19 +0100 Subject: [PATCH 4/4] relocated the registering of the git-hash for database-build en database-modules from ScriptCommands.rb to load.rb in Monitor. --- bin/ScriptCommands.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/bin/ScriptCommands.rb b/bin/ScriptCommands.rb index ab1444f..6244255 100644 --- a/bin/ScriptCommands.rb +++ b/bin/ScriptCommands.rb @@ -445,8 +445,6 @@ def add_build_constants(schema = 'system') add_constant 'CURRENT_DATABASE_VERSION', get_version(), schema unless $version.nil? add_constant 'CURRENT_DATABASE_PRODUCT', $product.to_s, schema unless $product.nil? add_constant 'CURRENT_GIT_REVISION', Utility.get_git_hash($product_sql_path), schema if !$vcs.nil? && $vcs == :git - add_constant 'DATABASE_MODULES_GIT_REVISION', Utility.get_git_hash($database_modules_sql_path), schema if !$vcs.nil? && $vcs == :git - add_constant 'DATABASE_BUILD_GIT_REVISION', Utility.get_git_hash($database_build_sql_path), schema if !$vcs.nil? && $vcs == :git add_constant 'CURRENT_SVN_REVISION', Utility.get_svn_head_revision, schema if !$vcs.nil? && $vcs == :svn add_constant 'CURRENT_DATABASE_BUILD_DATE', Time.now.strftime('%d-%m-%Y %H:%M:%S'), schema add_constant 'CURRENT_DATABASE_BUILD_USER', Etc.getlogin, schema rescue nil