clc-promote 0.3.16 → 0.4.0.dev

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9154527d572479db900219e14b964145fd8ca281
4
- data.tar.gz: 81e513887c826b6fdd14b03b1df886282e7e0ab3
3
+ metadata.gz: b6f45fd73d1b227a41b7cdf7875e41e1ec64e631
4
+ data.tar.gz: 84006d5c54e5a894e07ff83564e07340d77fb1b8
5
5
  SHA512:
6
- metadata.gz: 68513c9814d177a27e9aa98ae265c1aa12ecc9b289226225295625cc992487f07cf1d1407418e153058ab8f0d8496b3c0d1557dd135c66c0ef1a7e466c6fe67f
7
- data.tar.gz: 7156ac310dc558ac99e084ffe2cd94ac08a9e893d5414feb05f9e488082b95eb9dc6e0327f3b5b4400df47b725c3a34b357c8e4655224c9995a92df87cfb6614
6
+ metadata.gz: e195cea57475fb4ed28d85710a6239b378f2e667fe8f0f6589a0ee007f4831f8f0b113acec082b2b7280f4575ebcd2f9a7b640825dd92fa981c9207398bebee8
7
+ data.tar.gz: 1257b31c2149d871291f20d2610d9e1697fccea81a060823c3532b726486a6be369fe7cbb1dd18787baa6113c9d696154f10880364f158cd0639128e1634338c
@@ -3,9 +3,6 @@ require 'promote'
3
3
 
4
4
  module KnifePromote
5
5
  class PromoteEnvironment < Chef::Knife
6
- deps do
7
- require 'git'
8
- end
9
6
 
10
7
  banner "knife promote environment SOURCE_ENVIRONMENT DESTINATION_ENVIRONMENT"
11
8
 
@@ -42,7 +39,9 @@ module KnifePromote
42
39
  promoter.promote_to(source_env, dest_env)
43
40
 
44
41
  ui.info "Commiting and pushing changes to #{dest_env} back to git"
45
- commit(config, source_env, dest_env)
42
+ env_file = File.join(config.environment_directory, "#{dest_env}.json")
43
+ repo = Promote::GitRepo.new(env_file)
44
+ repo.commit("promoted new constraints from #{source_env} to #{dest_env}", true)
46
45
 
47
46
  ui.info "uploading #{dest_env} to #{config.chef_server_url}"
48
47
  uploader.upload_environment(dest_env)
@@ -52,19 +51,5 @@ module KnifePromote
52
51
 
53
52
  ui.info "promotion complete. Congratulations #{dest_env} on a well deserved promotion!!"
54
53
  end
55
-
56
- private
57
-
58
- include Promote::GitHelper
59
-
60
- def commit(config, source_env, dest_env)
61
- git = git_chef(config)
62
- dest_path = File.join(config.environment_directory, "#{dest_env}.json")
63
- git.add(dest_path)
64
- if !(git.status.changed.select{|s| dest_path.end_with?(s)}).keys.empty?
65
- git.commit("promoted new constraints from #{source_env} to #{dest_env}")
66
- git.push
67
- end
68
- end
69
54
  end
70
55
  end
data/lib/promote.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  require 'promote/config'
2
2
  require 'promote/environment_file'
3
- require 'promote/git_helper'
3
+ require 'promote/git_repo'
4
4
  require 'promote/uploader'
5
5
  require 'promote/versioner'
6
6
  require 'promote/promoter'
@@ -0,0 +1,44 @@
1
+ module Promote
2
+ class GitRepo
3
+ def initialize(scope_path)
4
+ @scope_path = scope_path
5
+ end
6
+
7
+ def version_number
8
+ all_commit_count = git.log(10000).object(scope_path).between(current_tag.sha).size
9
+ bump_commit_count = git.log(10000).object(scope_path).between(current_tag.sha).grep("CI:versioning chef artifacts").size
10
+ commit_count = all_commit_count - bump_commit_count
11
+ "#{current_tag.name}.#{commit_count}"
12
+ end
13
+
14
+ def git
15
+ require 'git'
16
+ @git ||= Git.open(git_root(scope_path))
17
+ end
18
+
19
+ def current_tag
20
+ @current_tag ||= git.tags.select { |t| t.name[/^[0-9\.]+/] }[-1]
21
+ end
22
+
23
+ def sha1
24
+ @sha1 ||= git.log(10000).between(current_tag.sha).first.sha
25
+ end
26
+
27
+ def commit(msg, push = false)
28
+ git.add(scope_path)
29
+ if !(git.status.changed.select{|s| scope_path.end_with?(s)}).keys.empty?
30
+ git.commit(msg)
31
+ git.push if push
32
+ end
33
+ end
34
+
35
+ attr_accessor :scope_path
36
+
37
+ private
38
+
39
+ def git_root(start_leaf)
40
+ return start_leaf if File.exist?(File.join(start_leaf, '.git'))
41
+ git_root(File.expand_path('..', start_leaf))
42
+ end
43
+ end
44
+ end
@@ -9,23 +9,27 @@ module Promote
9
9
 
10
10
  def version_cookbook(cookbook_name)
11
11
  dir = File.join(config.cookbook_directory, cookbook_name)
12
+ repo = GitRepo.new(dir)
12
13
  cookbook_name = File.basename(dir)
13
- ct = current_tag
14
- version = version_number(ct, dir)
14
+ version = repo.version_number
15
15
  metadata_file = File.join(dir, "metadata.rb")
16
16
  metadata_content = File.read(metadata_file)
17
17
  version_line = metadata_content[/^\s*version\s.*$/]
18
18
  current_version = version_line[/('|").*("|')/].gsub(/('|")/,"")
19
19
  if current_version != version
20
20
  metadata_content = metadata_content.gsub(current_version, version)
21
- outdata = metadata_content.gsub(/#sha1.*$/, "#sha1 '#{sha1}'")
21
+ outdata = metadata_content.gsub(/#sha1.*$/, "#sha1 '#{repo.sha1}'")
22
22
  if outdata[/#sha1.*$/].nil?
23
- outdata += "#sha1 '#{sha1}'"
23
+ outdata += "#sha1 '#{repo.sha1}'"
24
24
  end
25
25
  File.open(metadata_file, 'w') do |out|
26
26
  out << outdata
27
27
  end
28
- return { :cookbook => cookbook_name, :version => version, :sha1 => sha1}
28
+ return {
29
+ :cookbook => cookbook_name,
30
+ :version => version,
31
+ :sha1 => repo.sha1
32
+ }
29
33
  end
30
34
  end
31
35
 
@@ -101,7 +105,8 @@ module Promote
101
105
  def version_json(parent_directory, file_name, &block)
102
106
  version_string = "version"
103
107
  file = "#{parent_directory}/#{file_name}.json"
104
- version = version_number(current_tag, file)
108
+ repo = GitRepo.new(file)
109
+ version = repo.version_number
105
110
  content = JSON.parse(File.read(file))
106
111
  current_version = '0.0'
107
112
 
@@ -117,33 +122,16 @@ module Promote
117
122
 
118
123
  if current_version != version
119
124
  content_hash[version_string] = version
120
- content_hash['sha1'] = sha1
125
+ content_hash['sha1'] = repo.sha1
121
126
  File.open(file, 'w') do |out|
122
127
  out << JSON.pretty_generate(content)
123
128
  end
124
- { :artifact => file_name, :version => version, :sha1 => sha1}
129
+ {
130
+ :artifact => file_name,
131
+ :version => version,
132
+ :sha1 => repo.sha1
133
+ }
125
134
  end
126
135
  end
127
-
128
- def git
129
- @git ||= git_chef(config)
130
- end
131
-
132
- def current_tag
133
- @current_tag ||= git.tags.select { |t| t.name[/^[0-9\.]+/] }[-1]
134
- end
135
-
136
- def sha1
137
- @sha1 ||= git.log(10000).between(current_tag.sha).first.sha
138
- end
139
-
140
- def version_number(current_tag, ref)
141
- all_commit_count = git.log(10000).object(ref).between(current_tag.sha).size
142
- bump_commit_count = git.log(10000).object(ref).between(current_tag.sha).grep("CI:versioning chef artifacts").size
143
- commit_count = all_commit_count - bump_commit_count
144
- "#{current_tag.name}.#{commit_count}"
145
- end
146
-
147
- include Promote::GitHelper
148
136
  end
149
137
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clc-promote
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.16
4
+ version: 0.4.0.dev
5
5
  platform: ruby
6
6
  authors:
7
7
  - CenturyLink Cloud
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-26 00:00:00.000000000 Z
11
+ date: 2014-11-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chef
@@ -116,7 +116,7 @@ files:
116
116
  - lib/promote.rb
117
117
  - lib/promote/config.rb
118
118
  - lib/promote/environment_file.rb
119
- - lib/promote/git_helper.rb
119
+ - lib/promote/git_repo.rb
120
120
  - lib/promote/promoter.rb
121
121
  - lib/promote/rake_tasks.rb
122
122
  - lib/promote/uploader.rb
@@ -136,9 +136,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
136
136
  version: '0'
137
137
  required_rubygems_version: !ruby/object:Gem::Requirement
138
138
  requirements:
139
- - - ">="
139
+ - - ">"
140
140
  - !ruby/object:Gem::Version
141
- version: '0'
141
+ version: 1.3.1
142
142
  requirements: []
143
143
  rubyforge_project:
144
144
  rubygems_version: 2.4.1
@@ -1,15 +0,0 @@
1
- module Promote
2
- module GitHelper
3
-
4
- def git_chef(config)
5
- require 'git'
6
- Git.open(git_root(config.repo_root))
7
- end
8
-
9
- def git_root(start_leaf)
10
- return start_leaf if File.exist?(File.join(start_leaf, '.git'))
11
- git_root(File.expand_path('..', start_leaf))
12
- end
13
-
14
- end
15
- end