reagan 0.1.0 → 0.1.1

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: 81eba23bd4f21dcdeb8ba9cec1228560880a3fe6
4
- data.tar.gz: 770bc4ff47f00f98d153567e0e1dcb938b95e90e
3
+ metadata.gz: 02c3bd10ce4bddde059363830e05d2176836bca5
4
+ data.tar.gz: 7fb0f5239c5be78c0df12f6fdcfe1f482472fb8d
5
5
  SHA512:
6
- metadata.gz: 7b50e052ef7437ee4ec9f51626ebddb04fbe35522d023e4c279cb6d9cde87d5560bdcb4fc09035e601b1bd5a713690a548ea336b10004ba4b3c5ea0001147c2f
7
- data.tar.gz: 8ccf32432cac3d545bc3c0975fa796ef0459e3adadcf6d7b0d15bf2ef12c084c2fbea0c5274a8e939d656d8463ba0f60fc6e863bd12a945a552d2a4e3df7f32b
6
+ metadata.gz: a1409c348a81dc77f64468905626e58d3d987280c0c16d4d555b6beb3434753fb74cf4439e3f89a47e1dd4d07c534f91e9e9ecd4ea92243b3ed9fc2bc7294dbd
7
+ data.tar.gz: 1bad65512d3cb2f3d4a2320a5e5aa28d3b39e55f3e315e070b5182ee23bc86001dc725a84396c46c7257e7c65f9c3775524c4898497d045fb712694e6d50c129
data/bin/reagan CHANGED
@@ -1,38 +1,24 @@
1
1
  #!/usr/bin/env ruby
2
2
  #
3
+ # Author:: Tim Smith (<tim@cozy.co>)
4
+ # Copyright:: Copyright (c) 2014 Tim Smith
5
+ # License:: Apache License, Version 2.0
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
3
18
 
4
19
  # load the libs
5
- $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
6
-
7
- begin
8
- require 'change'
9
- require 'test_knife'
10
- require 'test_version'
11
- rescue LoadError => e
12
- raise "Missing lib #{e}"
13
- end
14
-
15
- # make sure the Github Pull Request plugin was used to pass in the pull ID
16
- fail 'ghprbPullId environmental variable not set. Cannot continue' unless ENV['ghprbPullId']
17
-
18
- def pretty_print(string)
19
- puts "\n#{string}"
20
- string.length.times { printf '-' }
21
- puts "\n"
22
- end
23
-
24
- puts "Grabbing contents of pull request #{ENV['ghprbPullId']}\n"
25
- cookbooks = ReaganChange.new.files
26
-
27
- pretty_print('The following cookbooks were changed')
28
- cookbooks.each { |cb| puts cb }
20
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
29
21
 
30
- results = []
31
- cookbooks.each do |cookbook|
32
- pretty_print("Testing cookbook #{cookbook}")
33
- results << ReaganTestVersion.new(cookbook).test
34
- results << ReaganTestKnife.new(cookbook).test
35
- end
22
+ require 'reagan'
36
23
 
37
- # if any test failed then exit 1 so jenkins can pick up the failure
38
- exit 1 if results.include?(false)
24
+ Reagan.new.run
data/lib/change.rb CHANGED
@@ -1,19 +1,33 @@
1
- #!/usr/bin/ruby
2
1
  # encoding: UTF-8
2
+ #
3
+ # Author:: Tim Smith (<tim@cozy.co>)
4
+ # Copyright:: Copyright (c) 2014 Tim Smith
5
+ # License:: Apache License, Version 2.0
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
3
18
 
4
19
  begin
20
+ require 'reagan'
5
21
  require 'rubygems'
6
22
  require 'octokit'
7
- require 'yaml'
8
23
  rescue LoadError => e
9
- raise "Missing gem #{e}"
24
+ raise "Missing gem or lib #{e}"
10
25
  end
11
26
 
12
27
  # determines changed files in the commit
13
- class ReaganChange
28
+ class Change < Reagan
14
29
  attr_accessor :files
15
30
  def initialize
16
- @config = YAML.load_file('/etc/reagan.yml')
17
31
  @files = list_files_changed
18
32
  end
19
33
 
@@ -35,9 +49,14 @@ class ReaganChange
35
49
  end
36
50
 
37
51
  def list_files_changed
38
- gh = Octokit::Client.new(:access_token => @config['github'] ['auth_token'])
52
+ # make sure the Github Pull Request plugin was used to pass in the pull ID
53
+ fail 'ghprbPullId environmental variable not set. Cannot continue' unless ENV['ghprbPullId']
39
54
 
40
- pull_files = files_from_pull(gh.pull_request_files(@config ['github']['repo'], ENV['ghprbPullId']))
55
+ puts "Grabbing contents of pull request #{ENV['ghprbPullId']}\n"
56
+
57
+ gh = Octokit::Client.new(:access_token => @@config['github']['auth_token'])
58
+
59
+ pull_files = files_from_pull(gh.pull_request_files(@@config ['github']['repo'], ENV['ghprbPullId']))
41
60
  unique_cookbooks(pull_files)
42
61
  end
43
62
  end
data/lib/reagan.rb ADDED
@@ -0,0 +1,56 @@
1
+ # encoding: UTF-8
2
+ #
3
+ # Author:: Tim Smith (<tim@cozy.co>)
4
+ # Copyright:: Copyright (c) 2014 Tim Smith
5
+ # License:: Apache License, Version 2.0
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+
19
+ # the main class for the reagan app. gets called by the reagan bin
20
+ class Reagan
21
+ require 'yaml'
22
+ require 'change'
23
+ require 'test_knife'
24
+ require 'test_version'
25
+
26
+ attr_accessor :config
27
+ def initialize
28
+ @@config = YAML.load_file('/etc/reagan.yml')
29
+ end
30
+
31
+ # nicely prints marques
32
+ def pretty_print(string)
33
+ puts "\n#{string}"
34
+ string.length.times { printf '-' }
35
+ puts "\n"
36
+ end
37
+
38
+ # grab the changes and run the tests
39
+ def run
40
+ # grab all cookbooks changed
41
+ cookbooks = Change.new.files
42
+
43
+ pretty_print('The following cookbooks were changed')
44
+ cookbooks.each { |cb| puts cb }
45
+
46
+ results = []
47
+ cookbooks.each do |cookbook|
48
+ pretty_print("Testing cookbook #{cookbook}")
49
+ results << TestVersion.new(cookbook).test
50
+ results << TestKnife.new(cookbook).test
51
+ end
52
+
53
+ # if any test failed then exit 1 so jenkins can pick up the failure
54
+ exit 1 if results.include?(false)
55
+ end
56
+ end
data/lib/test_knife.rb CHANGED
@@ -1,17 +1,24 @@
1
- #!/usr/bin/ruby
2
1
  # encoding: UTF-8
2
+ #
3
+ # Author:: Tim Smith (<tim@cozy.co>)
4
+ # Copyright:: Copyright (c) 2014 Tim Smith
5
+ # License:: Apache License, Version 2.0
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
3
18
 
4
- begin
5
- require 'rubygems'
6
- require 'yaml'
7
- rescue LoadError => e
8
- raise "Missing gem #{e}"
9
- end
10
-
11
- # performs tests on the passed in cookbook
12
- class ReaganTestKnife
19
+ # tests cookbooks using knife cookbook test functionality
20
+ class TestKnife < Reagan
13
21
  def initialize(cookbook)
14
- @config = YAML.load_file('/etc/reagan.yml')
15
22
  @cookbook = cookbook
16
23
  end
17
24
 
@@ -19,7 +26,7 @@ class ReaganTestKnife
19
26
  # returns true if cookbook passed or false if it failed
20
27
  def test
21
28
  # grab the version of the cookbook in the local metadata
22
- result = system "knife cookbook test -o #{File.join(@config['jenkins']['workspace_dir'], 'cookbooks')} #{@cookbook} > /dev/null 2>&1"
29
+ result = system "knife cookbook test -o #{File.join(@@config['jenkins']['workspace_dir'], 'cookbooks')} #{@cookbook} > /dev/null 2>&1"
23
30
 
24
31
  puts 'Running knife cookbook test:'
25
32
  puts result ? ' PASS: Knife cookbook test was successful' : 'FAIL: Knife cookbookk test was NOT successful'
data/lib/test_version.rb CHANGED
@@ -1,26 +1,39 @@
1
- #!/usr/bin/ruby
2
1
  # encoding: UTF-8
2
+ #
3
+ # Author:: Tim Smith (<tim@cozy.co>)
4
+ # Copyright:: Copyright (c) 2014 Tim Smith
5
+ # License:: Apache License, Version 2.0
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
3
18
 
4
19
  begin
5
20
  require 'rubygems'
6
- require 'yaml'
7
21
  require 'ridley'
8
22
  require 'chef/cookbook/metadata'
9
23
  rescue LoadError => e
10
- raise "Missing gem #{e}"
24
+ raise "Missing gem or lib #{e}"
11
25
  end
12
26
 
13
- # performs tests on the passed in cookbook
14
- class ReaganTestVersion
27
+ # tests to make sure the version has been updated on the cookbook
28
+ class TestVersion < Reagan
15
29
  def initialize(cookbook)
16
- @config = YAML.load_file('/etc/reagan.yml')
17
30
  @cookbook = cookbook
18
31
  end
19
32
 
20
33
  # grab the version of the cookbook in the local metadata
21
34
  def check_commit_version
22
35
  metadata = Chef::Cookbook::Metadata.new
23
- metadata.from_file(File.join(@config['jenkins']['workspace_dir'], 'cookbooks', @cookbook, 'metadata.rb'))
36
+ metadata.from_file(File.join(@@config['jenkins']['workspace_dir'], 'cookbooks', @cookbook, 'metadata.rb'))
24
37
  metadata.version
25
38
  end
26
39
 
@@ -28,9 +41,9 @@ class ReaganTestVersion
28
41
  def check_server_version
29
42
  Ridley::Logging.logger.level = Logger.const_get 'ERROR'
30
43
  server_con = Ridley.new(
31
- server_url: @config['chef']['server_url'],
32
- client_name: @config['chef']['client_name'],
33
- client_key: @config['chef']['pem_path'],
44
+ server_url: @@config['chef']['server_url'],
45
+ client_name: @@config['chef']['client_name'],
46
+ client_key: @@config['chef']['pem_path'],
34
47
  ssl: { verify: false }
35
48
  )
36
49
  server_con.cookbook.all[@cookbook][0]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reagan
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Smith
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-09 00:00:00.000000000 Z
11
+ date: 2014-10-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: octokit
@@ -81,6 +81,7 @@ files:
81
81
  - Rakefile
82
82
  - bin/reagan
83
83
  - lib/change.rb
84
+ - lib/reagan.rb
84
85
  - lib/test_knife.rb
85
86
  - lib/test_version.rb
86
87
  - reagan.yml.EXAMPLE