makit 0.0.5 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/lib/makit/apache.rb +32 -32
 - data/lib/makit/cli/clean.rb +14 -14
 - data/lib/makit/cli/clone.rb +59 -59
 - data/lib/makit/cli/init.rb +38 -38
 - data/lib/makit/cli/main.rb +33 -33
 - data/lib/makit/cli/make.rb +54 -54
 - data/lib/makit/cli/new.rb +37 -37
 - data/lib/makit/cli/nuget_cache.rb +38 -38
 - data/lib/makit/cli/pull.rb +31 -31
 - data/lib/makit/cli/setup.rb +71 -71
 - data/lib/makit/cli/work.rb +21 -21
 - data/lib/makit/command_runner.rb +321 -318
 - data/lib/makit/commands.rb +21 -21
 - data/lib/makit/content/default_gitignore.rb +5 -5
 - data/lib/makit/content/default_rakefile.rb +11 -11
 - data/lib/makit/content/gem_rakefile.rb +14 -14
 - data/lib/makit/data.rb +50 -50
 - data/lib/makit/directories.rb +140 -140
 - data/lib/makit/directory.rb +153 -153
 - data/lib/makit/dotnet.rb +83 -83
 - data/lib/makit/environment.rb +123 -123
 - data/lib/makit/files.rb +47 -47
 - data/lib/makit/git.rb +66 -66
 - data/lib/makit/gitlab_runner.rb +60 -60
 - data/lib/makit/humanize.rb +89 -89
 - data/lib/makit/logging.rb +96 -96
 - data/lib/makit/markdown.rb +75 -75
 - data/lib/makit/mp/basic_object_mp.rb +16 -16
 - data/lib/makit/mp/project_mp.rb +160 -156
 - data/lib/makit/mp/string_mp.rb +107 -107
 - data/lib/makit/nuget.rb +57 -57
 - data/lib/makit/protoc.rb +61 -61
 - data/lib/makit/serializer.rb +115 -115
 - data/lib/makit/storage.rb +131 -131
 - data/lib/makit/symbols.rb +149 -149
 - data/lib/makit/tasks.rb +67 -67
 - data/lib/makit/tree.rb +37 -37
 - data/lib/makit/v1/makit.v1_pb.rb +4 -3
 - data/lib/makit/v1/makit.v1_services_pb.rb +25 -25
 - data/lib/makit/version.rb +12 -12
 - data/lib/makit/wix.rb +95 -95
 - data/lib/makit/zip.rb +17 -17
 - data/lib/makit.rb +243 -243
 - metadata +3 -3
 
    
        data/lib/makit/environment.rb
    CHANGED
    
    | 
         @@ -1,123 +1,123 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            # frozen_string_literal: true
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
            require "sorted_set"
         
     | 
| 
       4 
     | 
    
         
            -
            require_relative "directory"
         
     | 
| 
       5 
     | 
    
         
            -
            # This module provides classes for the Makit gem.
         
     | 
| 
       6 
     | 
    
         
            -
            module Makit
         
     | 
| 
       7 
     | 
    
         
            -
              # This class provide methods for working with the system Environment.
         
     | 
| 
       8 
     | 
    
         
            -
              #
         
     | 
| 
       9 
     | 
    
         
            -
              class Environment
         
     | 
| 
       10 
     | 
    
         
            -
                def self.which(name)
         
     | 
| 
       11 
     | 
    
         
            -
                  return name if File.exist?(name)
         
     | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
       13 
     | 
    
         
            -
                  ["", ".exe", ".bat", ".cmd"].each do |ext|
         
     | 
| 
       14 
     | 
    
         
            -
                    aname = name + ext
         
     | 
| 
       15 
     | 
    
         
            -
                    return aname if File.exist?(aname)
         
     | 
| 
       16 
     | 
    
         
            -
             
     | 
| 
       17 
     | 
    
         
            -
                    ENV["PATH"].split(File::PATH_SEPARATOR).each do |path|
         
     | 
| 
       18 
     | 
    
         
            -
                      apath = "#{path.gsub("\\", "/")}/#{aname}".gsub("//", "/")
         
     | 
| 
       19 
     | 
    
         
            -
                      return apath if File.exist?(apath)
         
     | 
| 
       20 
     | 
    
         
            -
                    end
         
     | 
| 
       21 
     | 
    
         
            -
                  end
         
     | 
| 
       22 
     | 
    
         
            -
                  ""
         
     | 
| 
       23 
     | 
    
         
            -
                end
         
     | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
       25 
     | 
    
         
            -
                def self.constants_hash
         
     | 
| 
       26 
     | 
    
         
            -
                  constants = {}
         
     | 
| 
       27 
     | 
    
         
            -
                  # collect all constants that are all uppercase
         
     | 
| 
       28 
     | 
    
         
            -
                  Object.constants.each { |c| constants[c] = Object.const_get(c) if c == c.upcase } #	puts "#{c} = #{Object.const_get(c)}" }
         
     | 
| 
       29 
     | 
    
         
            -
                  #Object.constants.each { |c| constants[c] = Object.const_get(c)}#	puts "#{c} = #{Object.const_get(c)}" }
         
     | 
| 
       30 
     | 
    
         
            -
                  constants
         
     | 
| 
       31 
     | 
    
         
            -
                end
         
     | 
| 
       32 
     | 
    
         
            -
             
     | 
| 
       33 
     | 
    
         
            -
                def self.rake_file_name
         
     | 
| 
       34 
     | 
    
         
            -
                  caller_locations.each do |location|
         
     | 
| 
       35 
     | 
    
         
            -
                    return location.absolute_path if location.absolute_path&.end_with?("Rakefile")
         
     | 
| 
       36 
     | 
    
         
            -
                  end
         
     | 
| 
       37 
     | 
    
         
            -
                  nil
         
     | 
| 
       38 
     | 
    
         
            -
                end
         
     | 
| 
       39 
     | 
    
         
            -
             
     | 
| 
       40 
     | 
    
         
            -
                def self.gem_data_directory
         
     | 
| 
       41 
     | 
    
         
            -
                  gem_data_directory = File.join(Dir.home, ".makit")
         
     | 
| 
       42 
     | 
    
         
            -
                end
         
     | 
| 
       43 
     | 
    
         
            -
             
     | 
| 
       44 
     | 
    
         
            -
                def self.project_root_directory
         
     | 
| 
       45 
     | 
    
         
            -
                  if !Makit::Environment.rake_file_name.nil?
         
     | 
| 
       46 
     | 
    
         
            -
                    File.dirname(Makit::Environment.rake_file_name)
         
     | 
| 
       47 
     | 
    
         
            -
                  else
         
     | 
| 
       48 
     | 
    
         
            -
                    Makit::Directory.find_directory_with_pattern(File.dirname(__FILE__), "Rakefile")
         
     | 
| 
       49 
     | 
    
         
            -
                    # lass Directory
         
     | 
| 
       50 
     | 
    
         
            -
                    #  def self.find_directory_with_pattern(starting_directory, pattern)
         
     | 
| 
       51 
     | 
    
         
            -
                    # nil
         
     | 
| 
       52 
     | 
    
         
            -
                  end
         
     | 
| 
       53 
     | 
    
         
            -
                end
         
     | 
| 
       54 
     | 
    
         
            -
             
     | 
| 
       55 
     | 
    
         
            -
                def self.get_relative_directory(url)
         
     | 
| 
       56 
     | 
    
         
            -
                  url = url.gsub("https://", "").gsub("http://", "")
         
     | 
| 
       57 
     | 
    
         
            -
                  url = url.gsub("gitlab.com", "gitlab")
         
     | 
| 
       58 
     | 
    
         
            -
                  url
         
     | 
| 
       59 
     | 
    
         
            -
                end
         
     | 
| 
       60 
     | 
    
         
            -
             
     | 
| 
       61 
     | 
    
         
            -
                def self.get_code_root
         
     | 
| 
       62 
     | 
    
         
            -
                  # user home directory  + "code"
         
     | 
| 
       63 
     | 
    
         
            -
                  code_root = File.join(Dir.home, "code")
         
     | 
| 
       64 
     | 
    
         
            -
                end
         
     | 
| 
       65 
     | 
    
         
            -
             
     | 
| 
       66 
     | 
    
         
            -
                def self.get_work_directory(url)
         
     | 
| 
       67 
     | 
    
         
            -
                  raise "invalid url" if !url.include? "https://"
         
     | 
| 
       68 
     | 
    
         
            -
                  url = url.gsub("https://", "").gsub("http://", "")
         
     | 
| 
       69 
     | 
    
         
            -
                  #url = url.gsub("gitlab.com","gitlab")
         
     | 
| 
       70 
     | 
    
         
            -
                  url
         
     | 
| 
       71 
     | 
    
         
            -
                end
         
     | 
| 
       72 
     | 
    
         
            -
             
     | 
| 
       73 
     | 
    
         
            -
                def self.is_windows?
         
     | 
| 
       74 
     | 
    
         
            -
                  RbConfig::CONFIG["host_os"] =~ /mswin|msys|mingw|cygwin|bccwin|wince|emc/
         
     | 
| 
       75 
     | 
    
         
            -
                end
         
     | 
| 
       76 
     | 
    
         
            -
             
     | 
| 
       77 
     | 
    
         
            -
                def self.get_os
         
     | 
| 
       78 
     | 
    
         
            -
                  case RbConfig::CONFIG["host_os"]
         
     | 
| 
       79 
     | 
    
         
            -
                  when /linux/
         
     | 
| 
       80 
     | 
    
         
            -
                    "Linux"
         
     | 
| 
       81 
     | 
    
         
            -
                  when /darwin/
         
     | 
| 
       82 
     | 
    
         
            -
                    "macOS"
         
     | 
| 
       83 
     | 
    
         
            -
                  when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
         
     | 
| 
       84 
     | 
    
         
            -
                    "Windows"
         
     | 
| 
       85 
     | 
    
         
            -
                  else
         
     | 
| 
       86 
     | 
    
         
            -
                    "Unknown"
         
     | 
| 
       87 
     | 
    
         
            -
                  end
         
     | 
| 
       88 
     | 
    
         
            -
                end
         
     | 
| 
       89 
     | 
    
         
            -
             
     | 
| 
       90 
     | 
    
         
            -
                def self.get_runtime_identifier()
         
     | 
| 
       91 
     | 
    
         
            -
                  os = RbConfig::CONFIG["host_os"]
         
     | 
| 
       92 
     | 
    
         
            -
                  cpu = RbConfig::CONFIG["host_cpu"]
         
     | 
| 
       93 
     | 
    
         
            -
             
     | 
| 
       94 
     | 
    
         
            -
                  case os
         
     | 
| 
       95 
     | 
    
         
            -
                  when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
         
     | 
| 
       96 
     | 
    
         
            -
                    os_rid = "win"
         
     | 
| 
       97 
     | 
    
         
            -
                  when /darwin|mac os/
         
     | 
| 
       98 
     | 
    
         
            -
                    os_rid = "osx"
         
     | 
| 
       99 
     | 
    
         
            -
                  when /linux/
         
     | 
| 
       100 
     | 
    
         
            -
                    os_rid = "linux"
         
     | 
| 
       101 
     | 
    
         
            -
                  when /solaris|bsd/
         
     | 
| 
       102 
     | 
    
         
            -
                    os_rid = "unix"
         
     | 
| 
       103 
     | 
    
         
            -
                  else
         
     | 
| 
       104 
     | 
    
         
            -
                    raise "Unknown operating system: host_os=#{os}"
         
     | 
| 
       105 
     | 
    
         
            -
                  end
         
     | 
| 
       106 
     | 
    
         
            -
             
     | 
| 
       107 
     | 
    
         
            -
                  case cpu
         
     | 
| 
       108 
     | 
    
         
            -
                  when /x86_64|amd64|x64/
         
     | 
| 
       109 
     | 
    
         
            -
                    arch_rid = "x64"
         
     | 
| 
       110 
     | 
    
         
            -
                  when /i686|i386/
         
     | 
| 
       111 
     | 
    
         
            -
                    arch_rid = "x86"
         
     | 
| 
       112 
     | 
    
         
            -
                    #when /arm/
         
     | 
| 
       113 
     | 
    
         
            -
                    #  arch_rid = "arm"
         
     | 
| 
       114 
     | 
    
         
            -
                  when /aarch64|arm64/
         
     | 
| 
       115 
     | 
    
         
            -
                    arch_rid = "arm64"
         
     | 
| 
       116 
     | 
    
         
            -
                  else
         
     | 
| 
       117 
     | 
    
         
            -
                    raise "Unknown architecture: host_cpu=#{cpu}"
         
     | 
| 
       118 
     | 
    
         
            -
                  end
         
     | 
| 
       119 
     | 
    
         
            -
             
     | 
| 
       120 
     | 
    
         
            -
                  "#{os_rid}-#{arch_rid}"
         
     | 
| 
       121 
     | 
    
         
            -
                end
         
     | 
| 
       122 
     | 
    
         
            -
              end
         
     | 
| 
       123 
     | 
    
         
            -
            end
         
     | 
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            require "sorted_set"
         
     | 
| 
      
 4 
     | 
    
         
            +
            require_relative "directory"
         
     | 
| 
      
 5 
     | 
    
         
            +
            # This module provides classes for the Makit gem.
         
     | 
| 
      
 6 
     | 
    
         
            +
            module Makit
         
     | 
| 
      
 7 
     | 
    
         
            +
              # This class provide methods for working with the system Environment.
         
     | 
| 
      
 8 
     | 
    
         
            +
              #
         
     | 
| 
      
 9 
     | 
    
         
            +
              class Environment
         
     | 
| 
      
 10 
     | 
    
         
            +
                def self.which(name)
         
     | 
| 
      
 11 
     | 
    
         
            +
                  return name if File.exist?(name)
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
                  ["", ".exe", ".bat", ".cmd"].each do |ext|
         
     | 
| 
      
 14 
     | 
    
         
            +
                    aname = name + ext
         
     | 
| 
      
 15 
     | 
    
         
            +
                    return aname if File.exist?(aname)
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
                    ENV["PATH"].split(File::PATH_SEPARATOR).each do |path|
         
     | 
| 
      
 18 
     | 
    
         
            +
                      apath = "#{path.gsub("\\", "/")}/#{aname}".gsub("//", "/")
         
     | 
| 
      
 19 
     | 
    
         
            +
                      return apath if File.exist?(apath)
         
     | 
| 
      
 20 
     | 
    
         
            +
                    end
         
     | 
| 
      
 21 
     | 
    
         
            +
                  end
         
     | 
| 
      
 22 
     | 
    
         
            +
                  ""
         
     | 
| 
      
 23 
     | 
    
         
            +
                end
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
                def self.constants_hash
         
     | 
| 
      
 26 
     | 
    
         
            +
                  constants = {}
         
     | 
| 
      
 27 
     | 
    
         
            +
                  # collect all constants that are all uppercase
         
     | 
| 
      
 28 
     | 
    
         
            +
                  Object.constants.each { |c| constants[c] = Object.const_get(c) if c == c.upcase } #	puts "#{c} = #{Object.const_get(c)}" }
         
     | 
| 
      
 29 
     | 
    
         
            +
                  #Object.constants.each { |c| constants[c] = Object.const_get(c)}#	puts "#{c} = #{Object.const_get(c)}" }
         
     | 
| 
      
 30 
     | 
    
         
            +
                  constants
         
     | 
| 
      
 31 
     | 
    
         
            +
                end
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
                def self.rake_file_name
         
     | 
| 
      
 34 
     | 
    
         
            +
                  caller_locations.each do |location|
         
     | 
| 
      
 35 
     | 
    
         
            +
                    return location.absolute_path if location.absolute_path&.end_with?("Rakefile")
         
     | 
| 
      
 36 
     | 
    
         
            +
                  end
         
     | 
| 
      
 37 
     | 
    
         
            +
                  nil
         
     | 
| 
      
 38 
     | 
    
         
            +
                end
         
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
| 
      
 40 
     | 
    
         
            +
                def self.gem_data_directory
         
     | 
| 
      
 41 
     | 
    
         
            +
                  gem_data_directory = File.join(Dir.home, ".makit")
         
     | 
| 
      
 42 
     | 
    
         
            +
                end
         
     | 
| 
      
 43 
     | 
    
         
            +
             
     | 
| 
      
 44 
     | 
    
         
            +
                def self.project_root_directory
         
     | 
| 
      
 45 
     | 
    
         
            +
                  if !Makit::Environment.rake_file_name.nil?
         
     | 
| 
      
 46 
     | 
    
         
            +
                    File.dirname(Makit::Environment.rake_file_name)
         
     | 
| 
      
 47 
     | 
    
         
            +
                  else
         
     | 
| 
      
 48 
     | 
    
         
            +
                    Makit::Directory.find_directory_with_pattern(File.dirname(__FILE__), "Rakefile")
         
     | 
| 
      
 49 
     | 
    
         
            +
                    # lass Directory
         
     | 
| 
      
 50 
     | 
    
         
            +
                    #  def self.find_directory_with_pattern(starting_directory, pattern)
         
     | 
| 
      
 51 
     | 
    
         
            +
                    # nil
         
     | 
| 
      
 52 
     | 
    
         
            +
                  end
         
     | 
| 
      
 53 
     | 
    
         
            +
                end
         
     | 
| 
      
 54 
     | 
    
         
            +
             
     | 
| 
      
 55 
     | 
    
         
            +
                def self.get_relative_directory(url)
         
     | 
| 
      
 56 
     | 
    
         
            +
                  url = url.gsub("https://", "").gsub("http://", "")
         
     | 
| 
      
 57 
     | 
    
         
            +
                  url = url.gsub("gitlab.com", "gitlab")
         
     | 
| 
      
 58 
     | 
    
         
            +
                  url
         
     | 
| 
      
 59 
     | 
    
         
            +
                end
         
     | 
| 
      
 60 
     | 
    
         
            +
             
     | 
| 
      
 61 
     | 
    
         
            +
                def self.get_code_root
         
     | 
| 
      
 62 
     | 
    
         
            +
                  # user home directory  + "code"
         
     | 
| 
      
 63 
     | 
    
         
            +
                  code_root = File.join(Dir.home, "code")
         
     | 
| 
      
 64 
     | 
    
         
            +
                end
         
     | 
| 
      
 65 
     | 
    
         
            +
             
     | 
| 
      
 66 
     | 
    
         
            +
                def self.get_work_directory(url)
         
     | 
| 
      
 67 
     | 
    
         
            +
                  raise "invalid url" if !url.include? "https://"
         
     | 
| 
      
 68 
     | 
    
         
            +
                  url = url.gsub("https://", "").gsub("http://", "")
         
     | 
| 
      
 69 
     | 
    
         
            +
                  #url = url.gsub("gitlab.com","gitlab")
         
     | 
| 
      
 70 
     | 
    
         
            +
                  url
         
     | 
| 
      
 71 
     | 
    
         
            +
                end
         
     | 
| 
      
 72 
     | 
    
         
            +
             
     | 
| 
      
 73 
     | 
    
         
            +
                def self.is_windows?
         
     | 
| 
      
 74 
     | 
    
         
            +
                  RbConfig::CONFIG["host_os"] =~ /mswin|msys|mingw|cygwin|bccwin|wince|emc/
         
     | 
| 
      
 75 
     | 
    
         
            +
                end
         
     | 
| 
      
 76 
     | 
    
         
            +
             
     | 
| 
      
 77 
     | 
    
         
            +
                def self.get_os
         
     | 
| 
      
 78 
     | 
    
         
            +
                  case RbConfig::CONFIG["host_os"]
         
     | 
| 
      
 79 
     | 
    
         
            +
                  when /linux/
         
     | 
| 
      
 80 
     | 
    
         
            +
                    "Linux"
         
     | 
| 
      
 81 
     | 
    
         
            +
                  when /darwin/
         
     | 
| 
      
 82 
     | 
    
         
            +
                    "macOS"
         
     | 
| 
      
 83 
     | 
    
         
            +
                  when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
         
     | 
| 
      
 84 
     | 
    
         
            +
                    "Windows"
         
     | 
| 
      
 85 
     | 
    
         
            +
                  else
         
     | 
| 
      
 86 
     | 
    
         
            +
                    "Unknown"
         
     | 
| 
      
 87 
     | 
    
         
            +
                  end
         
     | 
| 
      
 88 
     | 
    
         
            +
                end
         
     | 
| 
      
 89 
     | 
    
         
            +
             
     | 
| 
      
 90 
     | 
    
         
            +
                def self.get_runtime_identifier()
         
     | 
| 
      
 91 
     | 
    
         
            +
                  os = RbConfig::CONFIG["host_os"]
         
     | 
| 
      
 92 
     | 
    
         
            +
                  cpu = RbConfig::CONFIG["host_cpu"]
         
     | 
| 
      
 93 
     | 
    
         
            +
             
     | 
| 
      
 94 
     | 
    
         
            +
                  case os
         
     | 
| 
      
 95 
     | 
    
         
            +
                  when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
         
     | 
| 
      
 96 
     | 
    
         
            +
                    os_rid = "win"
         
     | 
| 
      
 97 
     | 
    
         
            +
                  when /darwin|mac os/
         
     | 
| 
      
 98 
     | 
    
         
            +
                    os_rid = "osx"
         
     | 
| 
      
 99 
     | 
    
         
            +
                  when /linux/
         
     | 
| 
      
 100 
     | 
    
         
            +
                    os_rid = "linux"
         
     | 
| 
      
 101 
     | 
    
         
            +
                  when /solaris|bsd/
         
     | 
| 
      
 102 
     | 
    
         
            +
                    os_rid = "unix"
         
     | 
| 
      
 103 
     | 
    
         
            +
                  else
         
     | 
| 
      
 104 
     | 
    
         
            +
                    raise "Unknown operating system: host_os=#{os}"
         
     | 
| 
      
 105 
     | 
    
         
            +
                  end
         
     | 
| 
      
 106 
     | 
    
         
            +
             
     | 
| 
      
 107 
     | 
    
         
            +
                  case cpu
         
     | 
| 
      
 108 
     | 
    
         
            +
                  when /x86_64|amd64|x64/
         
     | 
| 
      
 109 
     | 
    
         
            +
                    arch_rid = "x64"
         
     | 
| 
      
 110 
     | 
    
         
            +
                  when /i686|i386/
         
     | 
| 
      
 111 
     | 
    
         
            +
                    arch_rid = "x86"
         
     | 
| 
      
 112 
     | 
    
         
            +
                    #when /arm/
         
     | 
| 
      
 113 
     | 
    
         
            +
                    #  arch_rid = "arm"
         
     | 
| 
      
 114 
     | 
    
         
            +
                  when /aarch64|arm64/
         
     | 
| 
      
 115 
     | 
    
         
            +
                    arch_rid = "arm64"
         
     | 
| 
      
 116 
     | 
    
         
            +
                  else
         
     | 
| 
      
 117 
     | 
    
         
            +
                    raise "Unknown architecture: host_cpu=#{cpu}"
         
     | 
| 
      
 118 
     | 
    
         
            +
                  end
         
     | 
| 
      
 119 
     | 
    
         
            +
             
     | 
| 
      
 120 
     | 
    
         
            +
                  "#{os_rid}-#{arch_rid}"
         
     | 
| 
      
 121 
     | 
    
         
            +
                end
         
     | 
| 
      
 122 
     | 
    
         
            +
              end
         
     | 
| 
      
 123 
     | 
    
         
            +
            end
         
     | 
    
        data/lib/makit/files.rb
    CHANGED
    
    | 
         @@ -1,47 +1,47 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            # frozen_string_literal: true
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
            require_relative "directory"
         
     | 
| 
       4 
     | 
    
         
            -
            require_relative "environment"
         
     | 
| 
       5 
     | 
    
         
            -
            require_relative "protoc"
         
     | 
| 
       6 
     | 
    
         
            -
            require_relative "nuget"
         
     | 
| 
       7 
     | 
    
         
            -
            require_relative "version"
         
     | 
| 
       8 
     | 
    
         
            -
            require "rake"
         
     | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
       10 
     | 
    
         
            -
            # This module provides classes for the Makit gem.
         
     | 
| 
       11 
     | 
    
         
            -
            module Makit
         
     | 
| 
       12 
     | 
    
         
            -
              # This class provide methods for working with the system Environment.
         
     | 
| 
       13 
     | 
    
         
            -
              #
         
     | 
| 
       14 
     | 
    
         
            -
              module Files
         
     | 
| 
       15 
     | 
    
         
            -
                if (Makit::Directories::PROJECT_ROOT != nil)
         
     | 
| 
       16 
     | 
    
         
            -
                  Dir.chdir(Makit::Directories::PROJECT_ROOT) do
         
     | 
| 
       17 
     | 
    
         
            -
                    CSPROJ = Dir.glob("**/*.csproj")
         
     | 
| 
       18 
     | 
    
         
            -
                  end
         
     | 
| 
       19 
     | 
    
         
            -
                else
         
     | 
| 
       20 
     | 
    
         
            -
                  CSPROJ = Array.new
         
     | 
| 
       21 
     | 
    
         
            -
                end
         
     | 
| 
       22 
     | 
    
         
            -
             
     | 
| 
       23 
     | 
    
         
            -
                # show all the files constants in a nicely formatted table format with the name of the constant and the value
         
     | 
| 
       24 
     | 
    
         
            -
                def self.show
         
     | 
| 
       25 
     | 
    
         
            -
                  # Array of constant names (symbols)
         
     | 
| 
       26 
     | 
    
         
            -
                  constant_names = [:CSPROJ]
         
     | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
       28 
     | 
    
         
            -
                  # Find the length of the longest constant name and add 1
         
     | 
| 
       29 
     | 
    
         
            -
                  max_length = constant_names.map(&:to_s).max_by(&:length).length + 1
         
     | 
| 
       30 
     | 
    
         
            -
             
     | 
| 
       31 
     | 
    
         
            -
                  # Iterate through each constant name
         
     | 
| 
       32 
     | 
    
         
            -
                  constant_names.each do |constant_name|
         
     | 
| 
       33 
     | 
    
         
            -
                    begin
         
     | 
| 
       34 
     | 
    
         
            -
                      constant_value = const_get(constant_name)  # Fetch the value of the constant
         
     | 
| 
       35 
     | 
    
         
            -
                      if (constant_value != nil && File.exist?(constant_value))
         
     | 
| 
       36 
     | 
    
         
            -
                        constant_value = constant_value.colorize(:green)
         
     | 
| 
       37 
     | 
    
         
            -
                      end
         
     | 
| 
       38 
     | 
    
         
            -
                      # Print the constant name right justified to the max_length
         
     | 
| 
       39 
     | 
    
         
            -
                      puts "#{constant_name.to_s.rjust(max_length)} = #{constant_value}"
         
     | 
| 
       40 
     | 
    
         
            -
                    rescue NameError
         
     | 
| 
       41 
     | 
    
         
            -
                      # Handle the case where the constant is not defined
         
     | 
| 
       42 
     | 
    
         
            -
                      puts "#{constant_name.to_s.rjust(max_length)} = [Constant not defined]"
         
     | 
| 
       43 
     | 
    
         
            -
                    end
         
     | 
| 
       44 
     | 
    
         
            -
                  end
         
     | 
| 
       45 
     | 
    
         
            -
                end
         
     | 
| 
       46 
     | 
    
         
            -
              end # module Files
         
     | 
| 
       47 
     | 
    
         
            -
            end # module Makit
         
     | 
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            require_relative "directory"
         
     | 
| 
      
 4 
     | 
    
         
            +
            require_relative "environment"
         
     | 
| 
      
 5 
     | 
    
         
            +
            require_relative "protoc"
         
     | 
| 
      
 6 
     | 
    
         
            +
            require_relative "nuget"
         
     | 
| 
      
 7 
     | 
    
         
            +
            require_relative "version"
         
     | 
| 
      
 8 
     | 
    
         
            +
            require "rake"
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
            # This module provides classes for the Makit gem.
         
     | 
| 
      
 11 
     | 
    
         
            +
            module Makit
         
     | 
| 
      
 12 
     | 
    
         
            +
              # This class provide methods for working with the system Environment.
         
     | 
| 
      
 13 
     | 
    
         
            +
              #
         
     | 
| 
      
 14 
     | 
    
         
            +
              module Files
         
     | 
| 
      
 15 
     | 
    
         
            +
                if (Makit::Directories::PROJECT_ROOT != nil)
         
     | 
| 
      
 16 
     | 
    
         
            +
                  Dir.chdir(Makit::Directories::PROJECT_ROOT) do
         
     | 
| 
      
 17 
     | 
    
         
            +
                    CSPROJ = Dir.glob("**/*.csproj")
         
     | 
| 
      
 18 
     | 
    
         
            +
                  end
         
     | 
| 
      
 19 
     | 
    
         
            +
                else
         
     | 
| 
      
 20 
     | 
    
         
            +
                  CSPROJ = Array.new
         
     | 
| 
      
 21 
     | 
    
         
            +
                end
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
                # show all the files constants in a nicely formatted table format with the name of the constant and the value
         
     | 
| 
      
 24 
     | 
    
         
            +
                def self.show
         
     | 
| 
      
 25 
     | 
    
         
            +
                  # Array of constant names (symbols)
         
     | 
| 
      
 26 
     | 
    
         
            +
                  constant_names = [:CSPROJ]
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
                  # Find the length of the longest constant name and add 1
         
     | 
| 
      
 29 
     | 
    
         
            +
                  max_length = constant_names.map(&:to_s).max_by(&:length).length + 1
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
                  # Iterate through each constant name
         
     | 
| 
      
 32 
     | 
    
         
            +
                  constant_names.each do |constant_name|
         
     | 
| 
      
 33 
     | 
    
         
            +
                    begin
         
     | 
| 
      
 34 
     | 
    
         
            +
                      constant_value = const_get(constant_name)  # Fetch the value of the constant
         
     | 
| 
      
 35 
     | 
    
         
            +
                      if (constant_value != nil && File.exist?(constant_value))
         
     | 
| 
      
 36 
     | 
    
         
            +
                        constant_value = constant_value.colorize(:green)
         
     | 
| 
      
 37 
     | 
    
         
            +
                      end
         
     | 
| 
      
 38 
     | 
    
         
            +
                      # Print the constant name right justified to the max_length
         
     | 
| 
      
 39 
     | 
    
         
            +
                      puts "#{constant_name.to_s.rjust(max_length)} = #{constant_value}"
         
     | 
| 
      
 40 
     | 
    
         
            +
                    rescue NameError
         
     | 
| 
      
 41 
     | 
    
         
            +
                      # Handle the case where the constant is not defined
         
     | 
| 
      
 42 
     | 
    
         
            +
                      puts "#{constant_name.to_s.rjust(max_length)} = [Constant not defined]"
         
     | 
| 
      
 43 
     | 
    
         
            +
                    end
         
     | 
| 
      
 44 
     | 
    
         
            +
                  end
         
     | 
| 
      
 45 
     | 
    
         
            +
                end
         
     | 
| 
      
 46 
     | 
    
         
            +
              end # module Files
         
     | 
| 
      
 47 
     | 
    
         
            +
            end # module Makit
         
     | 
    
        data/lib/makit/git.rb
    CHANGED
    
    | 
         @@ -1,66 +1,66 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            # frozen_string_literal: true
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
            # This module provides classes for the Makit gem.
         
     | 
| 
       4 
     | 
    
         
            -
            module Makit
         
     | 
| 
       5 
     | 
    
         
            -
              # This class provide methods for working with the system Environment.
         
     | 
| 
       6 
     | 
    
         
            -
              #
         
     | 
| 
       7 
     | 
    
         
            -
              class Git
         
     | 
| 
       8 
     | 
    
         
            -
                def self.is_git_repo
         
     | 
| 
       9 
     | 
    
         
            -
                  Dir.exist? ".git"
         
     | 
| 
       10 
     | 
    
         
            -
                end
         
     | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
       12 
     | 
    
         
            -
                def self.detached
         
     | 
| 
       13 
     | 
    
         
            -
                  `git status`.include?("detached")
         
     | 
| 
       14 
     | 
    
         
            -
                end
         
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
       16 
     | 
    
         
            -
                def self.is_read_only
         
     | 
| 
       17 
     | 
    
         
            -
                  !is_git_repo || detached
         
     | 
| 
       18 
     | 
    
         
            -
                end
         
     | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
       20 
     | 
    
         
            -
                def self.is_clean
         
     | 
| 
       21 
     | 
    
         
            -
                  `git status --porcelain`.empty?
         
     | 
| 
       22 
     | 
    
         
            -
                end
         
     | 
| 
       23 
     | 
    
         
            -
             
     | 
| 
       24 
     | 
    
         
            -
                def self.integrate
         
     | 
| 
       25 
     | 
    
         
            -
                  if is_git_repo && !detached
         
     | 
| 
       26 
     | 
    
         
            -
                    "git add .".run
         
     | 
| 
       27 
     | 
    
         
            -
                    "git commit -m \"integrate\"".run unless is_clean
         
     | 
| 
       28 
     | 
    
         
            -
                  end
         
     | 
| 
       29 
     | 
    
         
            -
                end
         
     | 
| 
       30 
     | 
    
         
            -
             
     | 
| 
       31 
     | 
    
         
            -
                def self.sync
         
     | 
| 
       32 
     | 
    
         
            -
                  if is_git_repo && !detached
         
     | 
| 
       33 
     | 
    
         
            -
                    "git pull".try
         
     | 
| 
       34 
     | 
    
         
            -
                    "git push origin".try
         
     | 
| 
       35 
     | 
    
         
            -
                  end
         
     | 
| 
       36 
     | 
    
         
            -
                end
         
     | 
| 
       37 
     | 
    
         
            -
             
     | 
| 
       38 
     | 
    
         
            -
                def self.zip_source_files(zipfilename)
         
     | 
| 
       39 
     | 
    
         
            -
                  "git archive --format zip --output #{zipfilename} HEAD".run
         
     | 
| 
       40 
     | 
    
         
            -
                end
         
     | 
| 
       41 
     | 
    
         
            -
             
     | 
| 
       42 
     | 
    
         
            -
                def self.branch
         
     | 
| 
       43 
     | 
    
         
            -
                  `git branch --show-current`.strip
         
     | 
| 
       44 
     | 
    
         
            -
                end
         
     | 
| 
       45 
     | 
    
         
            -
             
     | 
| 
       46 
     | 
    
         
            -
                def self.commitsha
         
     | 
| 
       47 
     | 
    
         
            -
                  `git rev-parse HEAD`.strip
         
     | 
| 
       48 
     | 
    
         
            -
                end
         
     | 
| 
       49 
     | 
    
         
            -
             
     | 
| 
       50 
     | 
    
         
            -
                def self.commitmsg
         
     | 
| 
       51 
     | 
    
         
            -
                  `git log -1 --pretty=%B`.strip
         
     | 
| 
       52 
     | 
    
         
            -
                end
         
     | 
| 
       53 
     | 
    
         
            -
             
     | 
| 
       54 
     | 
    
         
            -
                def self.commitdate
         
     | 
| 
       55 
     | 
    
         
            -
                  `git log -1 --pretty=%cd`.strip
         
     | 
| 
       56 
     | 
    
         
            -
                end
         
     | 
| 
       57 
     | 
    
         
            -
             
     | 
| 
       58 
     | 
    
         
            -
                def self.commitauthor
         
     | 
| 
       59 
     | 
    
         
            -
                  `git log -1 --pretty=%an`.strip
         
     | 
| 
       60 
     | 
    
         
            -
                end
         
     | 
| 
       61 
     | 
    
         
            -
             
     | 
| 
       62 
     | 
    
         
            -
                def self.commitemail
         
     | 
| 
       63 
     | 
    
         
            -
                  `git log -1 --pretty=%ae`.strip
         
     | 
| 
       64 
     | 
    
         
            -
                end
         
     | 
| 
       65 
     | 
    
         
            -
              end
         
     | 
| 
       66 
     | 
    
         
            -
            end
         
     | 
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            # This module provides classes for the Makit gem.
         
     | 
| 
      
 4 
     | 
    
         
            +
            module Makit
         
     | 
| 
      
 5 
     | 
    
         
            +
              # This class provide methods for working with the system Environment.
         
     | 
| 
      
 6 
     | 
    
         
            +
              #
         
     | 
| 
      
 7 
     | 
    
         
            +
              class Git
         
     | 
| 
      
 8 
     | 
    
         
            +
                def self.is_git_repo
         
     | 
| 
      
 9 
     | 
    
         
            +
                  Dir.exist? ".git"
         
     | 
| 
      
 10 
     | 
    
         
            +
                end
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
                def self.detached
         
     | 
| 
      
 13 
     | 
    
         
            +
                  `git status`.include?("detached")
         
     | 
| 
      
 14 
     | 
    
         
            +
                end
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
                def self.is_read_only
         
     | 
| 
      
 17 
     | 
    
         
            +
                  !is_git_repo || detached
         
     | 
| 
      
 18 
     | 
    
         
            +
                end
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
      
 20 
     | 
    
         
            +
                def self.is_clean
         
     | 
| 
      
 21 
     | 
    
         
            +
                  `git status --porcelain`.empty?
         
     | 
| 
      
 22 
     | 
    
         
            +
                end
         
     | 
| 
      
 23 
     | 
    
         
            +
             
     | 
| 
      
 24 
     | 
    
         
            +
                def self.integrate
         
     | 
| 
      
 25 
     | 
    
         
            +
                  if is_git_repo && !detached
         
     | 
| 
      
 26 
     | 
    
         
            +
                    "git add .".run
         
     | 
| 
      
 27 
     | 
    
         
            +
                    "git commit -m \"integrate\"".run unless is_clean
         
     | 
| 
      
 28 
     | 
    
         
            +
                  end
         
     | 
| 
      
 29 
     | 
    
         
            +
                end
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
                def self.sync
         
     | 
| 
      
 32 
     | 
    
         
            +
                  if is_git_repo && !detached
         
     | 
| 
      
 33 
     | 
    
         
            +
                    "git pull".try
         
     | 
| 
      
 34 
     | 
    
         
            +
                    "git push origin".try
         
     | 
| 
      
 35 
     | 
    
         
            +
                  end
         
     | 
| 
      
 36 
     | 
    
         
            +
                end
         
     | 
| 
      
 37 
     | 
    
         
            +
             
     | 
| 
      
 38 
     | 
    
         
            +
                def self.zip_source_files(zipfilename)
         
     | 
| 
      
 39 
     | 
    
         
            +
                  "git archive --format zip --output #{zipfilename} HEAD".run
         
     | 
| 
      
 40 
     | 
    
         
            +
                end
         
     | 
| 
      
 41 
     | 
    
         
            +
             
     | 
| 
      
 42 
     | 
    
         
            +
                def self.branch
         
     | 
| 
      
 43 
     | 
    
         
            +
                  `git branch --show-current`.strip
         
     | 
| 
      
 44 
     | 
    
         
            +
                end
         
     | 
| 
      
 45 
     | 
    
         
            +
             
     | 
| 
      
 46 
     | 
    
         
            +
                def self.commitsha
         
     | 
| 
      
 47 
     | 
    
         
            +
                  `git rev-parse HEAD`.strip
         
     | 
| 
      
 48 
     | 
    
         
            +
                end
         
     | 
| 
      
 49 
     | 
    
         
            +
             
     | 
| 
      
 50 
     | 
    
         
            +
                def self.commitmsg
         
     | 
| 
      
 51 
     | 
    
         
            +
                  `git log -1 --pretty=%B`.strip
         
     | 
| 
      
 52 
     | 
    
         
            +
                end
         
     | 
| 
      
 53 
     | 
    
         
            +
             
     | 
| 
      
 54 
     | 
    
         
            +
                def self.commitdate
         
     | 
| 
      
 55 
     | 
    
         
            +
                  `git log -1 --pretty=%cd`.strip
         
     | 
| 
      
 56 
     | 
    
         
            +
                end
         
     | 
| 
      
 57 
     | 
    
         
            +
             
     | 
| 
      
 58 
     | 
    
         
            +
                def self.commitauthor
         
     | 
| 
      
 59 
     | 
    
         
            +
                  `git log -1 --pretty=%an`.strip
         
     | 
| 
      
 60 
     | 
    
         
            +
                end
         
     | 
| 
      
 61 
     | 
    
         
            +
             
     | 
| 
      
 62 
     | 
    
         
            +
                def self.commitemail
         
     | 
| 
      
 63 
     | 
    
         
            +
                  `git log -1 --pretty=%ae`.strip
         
     | 
| 
      
 64 
     | 
    
         
            +
                end
         
     | 
| 
      
 65 
     | 
    
         
            +
              end
         
     | 
| 
      
 66 
     | 
    
         
            +
            end
         
     | 
    
        data/lib/makit/gitlab_runner.rb
    CHANGED
    
    | 
         @@ -1,60 +1,60 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            # frozen_string_literal: true
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
            require "yaml"
         
     | 
| 
       4 
     | 
    
         
            -
            require "fileutils"
         
     | 
| 
       5 
     | 
    
         
            -
             
     | 
| 
       6 
     | 
    
         
            -
            # This module provides classes for the Makit gem.
         
     | 
| 
       7 
     | 
    
         
            -
            module Makit
         
     | 
| 
       8 
     | 
    
         
            -
              # This class provide methods for working with Directories/
         
     | 
| 
       9 
     | 
    
         
            -
              #
         
     | 
| 
       10 
     | 
    
         
            -
              # Example:
         
     | 
| 
       11 
     | 
    
         
            -
              #
         
     | 
| 
       12 
     | 
    
         
            -
              #   Makit::Directory.find_directory_with_pattern("/home/user", "*.rb")
         
     | 
| 
       13 
     | 
    
         
            -
              #
         
     | 
| 
       14 
     | 
    
         
            -
              class GitLabRunner
         
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
       16 
     | 
    
         
            -
                # Parse the .gitlab-ci.yml file
         
     | 
| 
       17 
     | 
    
         
            -
                def parse_gitlab_ci_file(file_path)
         
     | 
| 
       18 
     | 
    
         
            -
                  YAML.load_file(file_path)
         
     | 
| 
       19 
     | 
    
         
            -
                end
         
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
       21 
     | 
    
         
            -
                # Extract the script for a specified job
         
     | 
| 
       22 
     | 
    
         
            -
                def extract_script(ci_config, job_name)
         
     | 
| 
       23 
     | 
    
         
            -
                  job = ci_config[job_name]
         
     | 
| 
       24 
     | 
    
         
            -
                  job ? job["script"] : nil
         
     | 
| 
       25 
     | 
    
         
            -
                end
         
     | 
| 
       26 
     | 
    
         
            -
             
     | 
| 
       27 
     | 
    
         
            -
                # Write the script to a temporary file
         
     | 
| 
       28 
     | 
    
         
            -
                def write_script_to_file(script, file_path)
         
     | 
| 
       29 
     | 
    
         
            -
                  File.open(file_path, "w") do |file|
         
     | 
| 
       30 
     | 
    
         
            -
                    script.each { |line| file.puts(line) }
         
     | 
| 
       31 
     | 
    
         
            -
                  end
         
     | 
| 
       32 
     | 
    
         
            -
                end
         
     | 
| 
       33 
     | 
    
         
            -
             
     | 
| 
       34 
     | 
    
         
            -
                # Run the script in a Docker container
         
     | 
| 
       35 
     | 
    
         
            -
                def run_script_in_docker(image, script_file)
         
     | 
| 
       36 
     | 
    
         
            -
                  system("docker run --rm -v #{Dir.pwd}:/workspace -w /workspace #{image} /bin/sh #{script_file}")
         
     | 
| 
       37 
     | 
    
         
            -
                end
         
     | 
| 
       38 
     | 
    
         
            -
             
     | 
| 
       39 
     | 
    
         
            -
                # Main function to execute the process
         
     | 
| 
       40 
     | 
    
         
            -
                def run_job(ci_file_path, job_name, docker_image)
         
     | 
| 
       41 
     | 
    
         
            -
                  ci_config = parse_gitlab_ci_file(ci_file_path)
         
     | 
| 
       42 
     | 
    
         
            -
                  script = extract_script(ci_config, job_name)
         
     | 
| 
       43 
     | 
    
         
            -
             
     | 
| 
       44 
     | 
    
         
            -
                  unless script
         
     | 
| 
       45 
     | 
    
         
            -
                    puts "Job '#{job_name}' not found in #{ci_file_path}"
         
     | 
| 
       46 
     | 
    
         
            -
                    return
         
     | 
| 
       47 
     | 
    
         
            -
                  end
         
     | 
| 
       48 
     | 
    
         
            -
             
     | 
| 
       49 
     | 
    
         
            -
                  script_file = "temp_script.sh"
         
     | 
| 
       50 
     | 
    
         
            -
                  write_script_to_file(script, script_file)
         
     | 
| 
       51 
     | 
    
         
            -
                  FileUtils.chmod("+x", script_file)
         
     | 
| 
       52 
     | 
    
         
            -
             
     | 
| 
       53 
     | 
    
         
            -
                  puts "Running script in Docker container..."
         
     | 
| 
       54 
     | 
    
         
            -
                  run_script_in_docker(docker_image, script_file)
         
     | 
| 
       55 
     | 
    
         
            -
             
     | 
| 
       56 
     | 
    
         
            -
                  # Clean up the temporary script file
         
     | 
| 
       57 
     | 
    
         
            -
                  FileUtils.rm(script_file)
         
     | 
| 
       58 
     | 
    
         
            -
                end
         
     | 
| 
       59 
     | 
    
         
            -
              end
         
     | 
| 
       60 
     | 
    
         
            -
            end
         
     | 
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            require "yaml"
         
     | 
| 
      
 4 
     | 
    
         
            +
            require "fileutils"
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
            # This module provides classes for the Makit gem.
         
     | 
| 
      
 7 
     | 
    
         
            +
            module Makit
         
     | 
| 
      
 8 
     | 
    
         
            +
              # This class provide methods for working with Directories/
         
     | 
| 
      
 9 
     | 
    
         
            +
              #
         
     | 
| 
      
 10 
     | 
    
         
            +
              # Example:
         
     | 
| 
      
 11 
     | 
    
         
            +
              #
         
     | 
| 
      
 12 
     | 
    
         
            +
              #   Makit::Directory.find_directory_with_pattern("/home/user", "*.rb")
         
     | 
| 
      
 13 
     | 
    
         
            +
              #
         
     | 
| 
      
 14 
     | 
    
         
            +
              class GitLabRunner
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
                # Parse the .gitlab-ci.yml file
         
     | 
| 
      
 17 
     | 
    
         
            +
                def parse_gitlab_ci_file(file_path)
         
     | 
| 
      
 18 
     | 
    
         
            +
                  YAML.load_file(file_path)
         
     | 
| 
      
 19 
     | 
    
         
            +
                end
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
                # Extract the script for a specified job
         
     | 
| 
      
 22 
     | 
    
         
            +
                def extract_script(ci_config, job_name)
         
     | 
| 
      
 23 
     | 
    
         
            +
                  job = ci_config[job_name]
         
     | 
| 
      
 24 
     | 
    
         
            +
                  job ? job["script"] : nil
         
     | 
| 
      
 25 
     | 
    
         
            +
                end
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
                # Write the script to a temporary file
         
     | 
| 
      
 28 
     | 
    
         
            +
                def write_script_to_file(script, file_path)
         
     | 
| 
      
 29 
     | 
    
         
            +
                  File.open(file_path, "w") do |file|
         
     | 
| 
      
 30 
     | 
    
         
            +
                    script.each { |line| file.puts(line) }
         
     | 
| 
      
 31 
     | 
    
         
            +
                  end
         
     | 
| 
      
 32 
     | 
    
         
            +
                end
         
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
      
 34 
     | 
    
         
            +
                # Run the script in a Docker container
         
     | 
| 
      
 35 
     | 
    
         
            +
                def run_script_in_docker(image, script_file)
         
     | 
| 
      
 36 
     | 
    
         
            +
                  system("docker run --rm -v #{Dir.pwd}:/workspace -w /workspace #{image} /bin/sh #{script_file}")
         
     | 
| 
      
 37 
     | 
    
         
            +
                end
         
     | 
| 
      
 38 
     | 
    
         
            +
             
     | 
| 
      
 39 
     | 
    
         
            +
                # Main function to execute the process
         
     | 
| 
      
 40 
     | 
    
         
            +
                def run_job(ci_file_path, job_name, docker_image)
         
     | 
| 
      
 41 
     | 
    
         
            +
                  ci_config = parse_gitlab_ci_file(ci_file_path)
         
     | 
| 
      
 42 
     | 
    
         
            +
                  script = extract_script(ci_config, job_name)
         
     | 
| 
      
 43 
     | 
    
         
            +
             
     | 
| 
      
 44 
     | 
    
         
            +
                  unless script
         
     | 
| 
      
 45 
     | 
    
         
            +
                    puts "Job '#{job_name}' not found in #{ci_file_path}"
         
     | 
| 
      
 46 
     | 
    
         
            +
                    return
         
     | 
| 
      
 47 
     | 
    
         
            +
                  end
         
     | 
| 
      
 48 
     | 
    
         
            +
             
     | 
| 
      
 49 
     | 
    
         
            +
                  script_file = "temp_script.sh"
         
     | 
| 
      
 50 
     | 
    
         
            +
                  write_script_to_file(script, script_file)
         
     | 
| 
      
 51 
     | 
    
         
            +
                  FileUtils.chmod("+x", script_file)
         
     | 
| 
      
 52 
     | 
    
         
            +
             
     | 
| 
      
 53 
     | 
    
         
            +
                  puts "Running script in Docker container..."
         
     | 
| 
      
 54 
     | 
    
         
            +
                  run_script_in_docker(docker_image, script_file)
         
     | 
| 
      
 55 
     | 
    
         
            +
             
     | 
| 
      
 56 
     | 
    
         
            +
                  # Clean up the temporary script file
         
     | 
| 
      
 57 
     | 
    
         
            +
                  FileUtils.rm(script_file)
         
     | 
| 
      
 58 
     | 
    
         
            +
                end
         
     | 
| 
      
 59 
     | 
    
         
            +
              end
         
     | 
| 
      
 60 
     | 
    
         
            +
            end
         
     |