git.lirion.de

Of git, get, and gud

summaryrefslogtreecommitdiffstats
path: root/scripts/config_version-lirion.rb
diff options
context:
space:
mode:
authormail_redacted_for_web 2025-08-15 07:21:01 +0200
committermail_redacted_for_web 2025-08-15 07:21:01 +0200
commitd2221daeb81ad9f627d2499fa7817ea1cf3379c5 (patch)
treef815df477601390809f06204ab50b98626f02325 /scripts/config_version-lirion.rb
parent565607dc6b2cbab99e0c9a66ea361757678b5fb7 (diff)
downloadcontrol-repo-template-config_version_lirion.tar.bz2
+ config_version implementations with commit messageconfig_version_lirion
Diffstat (limited to 'scripts/config_version-lirion.rb')
-rwxr-xr-xscripts/config_version-lirion.rb73
1 files changed, 73 insertions, 0 deletions
diff --git a/scripts/config_version-lirion.rb b/scripts/config_version-lirion.rb
new file mode 100755
index 0000000..6edfe09
--- /dev/null
+++ b/scripts/config_version-lirion.rb
@@ -0,0 +1,73 @@
+#!/usr/bin/ruby
+# frozen_string_literal: true
+
+begin
+ require 'rugged'
+ require 'socket'
+rescue LoadError
+ t = Time.new
+ puts t.to_i
+else
+ environment = ARGV[0]
+ environmentpaths = if (defined? ARGV[1]) && !ARGV[1].nil?
+ ARGV[1]
+ else
+ [
+ # The actual code directory. In case of PE, you may want to adapt -
+ # since PE 2023.x, they have introduced an internal git deployer between
+ # the code pulled from git repos and what is then deployed to the agents,
+ # for reasons unknown and for raised complexity.
+ # If the directory does not exist, this will be ignored.
+ '/etc/puppetlabs/code/environments',
+ # PE originally staged here - if you stage, too, check this directory.
+ # If it doesn't exist, it will be ignored.
+ '/etc/puppetlabs/code-staging'
+ ]
+ end
+ environmentpaths = Array(environmentpaths)
+ # Our return string.
+ myreturn = nil
+ # Loop through all path possibilities, on first git occurrence: assemble output and break out
+ # dirs_exist: Was any of the paths an actual directory on the Puppet server?
+ dirs_exist = false
+ environmentpaths.each do |checkpath|
+ next unless Dir.exist?(File.join(checkpath, environment))
+
+ dirs_exist = true
+ begin
+ # Get the path to the environment being compiled.
+ repo = Rugged::Repository.discover(File.join(checkpath, environment))
+ head = repo.head
+
+ # Leaving this - maybe we want to come back to it.
+ # # Get the hostname of the Puppet master compiling the catalog.
+ # # Sometimes the hostname is the fqdn, so we'll take the first segment.
+ # compiling_master = Socket.gethostname.split('.').first
+
+ # First 6 characters of the sha1 hash of the newest commit.
+ commit_id = head.target_id[0..5]
+
+ # Commit message:
+ commit_msg = head.target.message.delete("\n")
+
+ # Show the compiling master, environment name, and commit ID.
+ myreturn = "#{environment} -- #{commit_id} - #{commit_msg}"
+
+ # We have the message we want? Break the loop, we don't care about other
+ # folders anymore.
+ break
+ rescue Rugged::RepositoryError
+ # Folder is existing but not a git repo? Maybe check the next folder structure, then.
+ next
+ rescue Rugged::ConfigError
+ myreturn = "Environment: #{environment} (repository not usable for catalog message)"
+ break
+ end
+ end
+ if dirs_exist
+ "Environment: #{environment} (no git directory in code deployments)" if myreturn.nil?
+ else
+ "Environment: #{environment} (environment path(s) not existing)"
+ end
+ puts myreturn
+end