Module: CiCd::Builder::Manifest::Build
- Included in:
- Runner
- Defined in:
- lib/cicd/builder/manifest/mixlib/build.rb
Constant Summary collapse
- VER_RGX =
%r'^\d+\.\d+(\.?\d)*$'
- MMP_RGX =
%r'^(\d+\.?){2,3}$'
- EXT_RGX =
%r'\.*(tar\.gz|tgz|tar.bzip2|tar.bz2|bzip2|bz2|jar|war|[a-z]+)$'
Instance Method Summary collapse
-
#cleanupAfterPackaging(lines) ⇒ Object
—————————————————————————————————————.
-
#getVersionBuild(path, artifact, comp) ⇒ Object
—————————————————————————————————————.
-
#getVersionBuildFromName(artifact) ⇒ Object
—————————————————————————————————————.
-
#packageBuild ⇒ Object
—————————————————————————————————————.
-
#prepareBuild ⇒ Object
————————————————————————————————————— noinspection RubyHashKeysTypesInspection.
Instance Method Details
#cleanupAfterPackaging(lines) ⇒ Object
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
# File 'lib/cicd/builder/manifest/mixlib/build.rb', line 191 def cleanupAfterPackaging(lines) begin unless IO.write(@vars[:build_mff], lines.join("\n")) > 0 @logger.error "Nothing was written to build manifest '#{@vars[:build_mff]}'" @vars[:return_code] = Errors::MANIFEST_EMPTY end rescue => e @logger.error "Failed to write manifest '#{@vars[:build_mff]}' (#{e.})" @vars[:return_code] = Errors::MANIFEST_WRITE end FileUtils.rmtree(@vars[:build_dir]) @vars[:return_code] = File.directory?(@vars[:build_dir]) ? Errors::BUILD_DIR : 0 unless @vars[:return_code] == 0 @logger.warn "Remove manifest '#{@vars[:build_mff]}' due to error" FileUtils.rm_f(@vars[:build_mff]) # @vars[:return_code] = File.exists?(@vars[:build_mff]) ? Errors::MANIFEST_DELETE : 0 end end |
#getVersionBuild(path, artifact, comp) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/cicd/builder/manifest/mixlib/build.rb', line 91 def getVersionBuild(path,artifact,comp) cname,cdata = comp version,build = File.split(path) if build.match(%r'^\d+$') and version.match(%r'/?\d+\.\d+\.?\d*$') # Hole in one! version = File.basename(version) else if build.match(VER_RGX) version = build build = '' else version = cdata[:build].nil? ? '' : ( cdata[:build] > 0 ? build.to_s : '' ) end unless version.match(VER_RGX) version = cdata[:version] || '' end ver,bld = getVersionBuildFromName(artifact) if version.empty? version,build = [ver,bld] if version.empty? version = @vars[:build_ver] else _,ver = File.split(path) if version =~ %r'^#{ver}' if version =~ VER_RGX if version =~ %r'^#{build}' # prob the major part of version build = '' end else unless version.eql?(ver) build = version.dup version = ver build = build.gsub(%r'^#{version}(\.|-)*','') end end else # The whacky cases build = version.dup if ver =~ %r/\d+\.(\d+\.)*/ version = ver build = build.gsub(%r'^#{version}(\.|-)*','') else vra = version.gsub!(%r'^((\d+\.?)+)', '\1').split(/\./) version = vra[0..2].join('.') build = vra[-1] #build = @vars[:build_num] end end end else if ver.match(VER_RGX) if ver.match(MMP_RGX) if version.length < ver.length version = ver # Guessing it is the better version end else build = ver.dup # version.gsub!(/\.d+$/, '') build.gsub!(/^#{version}\.?/, '') end end end unless build.match(%r'^[1-9]\d*$') build = cdata[:build] build = @vars[:build_num] if (build.nil? or build.empty? or build.to_i == 0) end end [version,build] end |
#getVersionBuildFromName(artifact) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/cicd/builder/manifest/mixlib/build.rb', line 76 def getVersionBuildFromName(artifact) version = artifact.dup version.gsub!(EXT_RGX, '') version.gsub!(%r'^[a-zA-Z\-._]+', '') version.gsub!(%r'\.\.+', '.') build = '' if version.match(VER_RGX) if version.match(%r'\-') version,build = version.split(/-/) end end [version,build] end |
#packageBuild ⇒ Object
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/cicd/builder/manifest/mixlib/build.rb', line 160 def packageBuild() @logger.info CLASS+'::'+__method__.to_s if isSameDirectory(Dir.pwd, ENV['WORKSPACE']) if @vars.has_key?(:components) and not @vars[:components].empty? @vars[:return_code] = 0 getRepoInstance('S3') if 0 == @vars[:return_code] lines = [] @vars[:artifacts] = [] # Deal with all artifacts of each component @vars[:components].each { |comp| processComponent(comp, lines) } if @vars[:return_code] == 0 cleanupAfterPackaging(lines) end end else @logger.error 'No components found during preparation?' @vars[:return_code] = Errors::NO_COMPONENTS end else @logger.error "Not in WORKSPACE? '#{pwd}' does not match WORKSPACE='#{workspace}'" @vars[:return_code] = Errors::WORKSPACE_DIR end @vars[:return_code] end |
#prepareBuild ⇒ Object
noinspection RubyHashKeysTypesInspection
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/cicd/builder/manifest/mixlib/build.rb', line 11 def prepareBuild() @logger.step CLASS+'::'+__method__.to_s ret = super if ret == 0 @vars[:artifacts] = [] yaml = YAML.load(IO.read(ENV['MANIFEST_FILE'])) keys = Hash[yaml.keys.map.with_index.to_a].keys.sort # @logger.info keys.ai ordr = [] bads = [] apps = {} vars = {} rmap = { sha256: %w[_sha256], base_url: %w[_repo_base_url], url: %w[_url], version: %w[_app_version], build: %w[_app_build], } keys.each do |prod| rmap.keys.each do |var| vars[var] = '' end name = '' match = nil rmap.each do |var,lst| lst.each do |regexstr| match = prod.match(%r'^(.*?)#{regexstr}$') if match name = match[1] vars[var] = yaml[prod] break end end break if match end if match ordr << name unless apps[name] apps[name] = { name: name, } end rmap.keys.each do |var| apps[name][var] = vars[var] unless vars[var].empty? end else bads << prod end end @logger.debug "App entries: #{apps.ai}" if bads.size > 0 @logger.fatal "Bad entries: #{bads.map{|p| "#{p}: #{yaml[p]}"}.ai}" ret = Errors::BAD_ARTIFACTS else @vars[:components] = apps end end @vars[:return_code] = ret end |