reagan 0.4.0 → 0.5.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1f8adf202a5a529b33dcd43b082bb06db72736e1
4
- data.tar.gz: 0b4b6abb058964f5fd80486a273f01db178522e6
3
+ metadata.gz: 10d499645a7fb99af58df282d16978e489f65530
4
+ data.tar.gz: 89c4f2c89136fa938e8b5a3eda8f747daecf19cc
5
5
  SHA512:
6
- metadata.gz: c497af04ace64eaa119b66d212e1ede9a5dd3076ddcfc8960805cf4f8166a5917ee73bcb6c2b59739b32cf3fbcc2af11031fece2c967d8e872c37028acf7b6dc
7
- data.tar.gz: c0f978a8ded444cb0d92110dee3fe832c699a4f1261a1605aff691559e6a2211676e062bd30d982f1e8f6d8a2347e29db5f819a9d9e8df581f70961fd281c65f
6
+ metadata.gz: 9ee71ff549f6e7a5440a723e3039df9c4a5c9829438c7482dcbbf6092eba3e2c3d89358cb40c654151c6987611d00019186d72ba2ad070c2f467e06d9e722d84
7
+ data.tar.gz: bb97448e1f97dcf37806eb3fcb4edf1f536d796fca1fd3ce8c160260ded74f7877f95e55bec5ae84d462901f13095db763147f3aa011330709b670b3638dee4d
data/README.md CHANGED
@@ -1,22 +1,64 @@
1
1
  reagan
2
2
  ======
3
3
 
4
- Trust But Verify - Ruby Jenkins build script that automates the testing of Chef cookbooks
4
+ Trust But Verify - Ruby Jenkins build script that automates the testing of individual Chef cookbooks in a monolithic chef-repo. Reagan allows you to test only the cookbooks that have changed in a particular pull request and includes the following tests:
5
+
6
+ * Ensure versions are bumped in cookbooks vs. the current version on the server
7
+ * Validate ruby / templates according to knife cookbook test
8
+ * Optionally run any commands in a per cookbook reagan_test.yml file (rubocop? foodcritic? chefspec?)
5
9
 
6
10
  ##Requirements
11
+ * Ruby 1.9.3 (rbenv Jenkins plugin suggested to get more modern Ruby)
7
12
  * Jenkins Github Pull Request Builder plugin
8
- * A working knife toolchain
13
+ * A working knife toolchain on your Jenkins boxes
9
14
  * Gems
10
15
  * octokit
11
16
  * chef
12
- * reidley
17
+ * ridley
13
18
 
14
19
  ## Running Locally
15
20
  While this app is written to be run as a Jenkins job it can also be run locally. This is particularly useful when you want to run the tests prior to commit. To run Reagan locally use the following command line options:
16
21
 
17
22
  * -c /path/to/reagan.yml
18
23
  * -o overide,list,of,comma,separated,cookbooks
19
- * -p 123 pull request number to manually test
24
+ * -p 123 pull request number to manually test a github pull request
20
25
 
21
26
  ##Running in Jenkins
22
- coming soon!
27
+ 1) Create a Gemfile in your chef-repo and add the reagan gem to the file. Example:
28
+
29
+ ```ruby
30
+ source 'https://rubygems.org'
31
+
32
+ gem 'chef', '~> 11.0'
33
+ gem 'berkshelf', '~> 3.1'
34
+
35
+ group :test do
36
+ gem 'reagan', '~> 0.4'
37
+ gem 'rubocop', '~> 0.26'
38
+ gem 'foodcritic', '~> 4.0'
39
+ end
40
+ ```
41
+
42
+ 2) Setup a Jenkins job per the instructions in the Github Pull Request Plugin documentation at https://wiki.jenkins-ci.org/display/JENKINS/GitHub+pull+request+builder+plugin
43
+
44
+ 3) Add the following it:ms to your job configuration:
45
+
46
+ * If you're using the rbenv plugin enable the plugin under 'Build Environment', set a ruby version, and add 'bundler' to the list of gems to preinstall
47
+ * Under Build -> Execute shell add the following command: bundle install; bundle exec reagan
48
+ * Under Build Triggers -> Advanced either set the crontab to */2 * * * * or setup building using github web hooks (not possible if your jenkins is not exposed to the Web)
49
+
50
+ 3) If you don't already have a Jenkins user for your Github account create one now. You can always use your own account's privs, but you really shouldn't do this. Once you have an account with privs on your chef-repo go to https://github.com/settings/applications and create a oauth token. Make sure the token has repo and public_repo scope. Same off the token for the config creation below
51
+
52
+ 4) Create a Reagan config file (example is in the repo at reagan.yml.EXAMPLE). Unless you specify a custom config location with -c this should be at /etc/reagan.yml, and should be owned by the Jenkins user with 600 privs so to keep your github token private. The config contains the following items:
53
+
54
+ * Github auth_token: that you created in the Github UI
55
+ * Github repo: the Org/repo format name of your chef repo
56
+ * Jenkins workspace_dir: The path to the checked out chef-repo workspace used by Jenkins
57
+ * Chef pem_path: Path to a chef .pem file on your jenkins host
58
+ * Chef client_name: The name of the client for the jenkins chef install on your Jenkins host (not the server's client name)
59
+ * Chef server_url: The full URL of your Chef server
60
+
61
+ 5) At this point you should be able to open a test pull request
62
+
63
+
64
+
data/lib/test_reagan.rb CHANGED
@@ -16,23 +16,33 @@
16
16
  # See the License for the specific language governing permissions and
17
17
  # limitations under the License.
18
18
 
19
- # tests cookbooks using the reagan-test rake tasks
19
+ # tests cookbooks using tests defined in reagan_test.yml files
20
20
  class TestReagan < Reagan
21
21
  def initialize(cookbook)
22
22
  @cookbook = cookbook
23
23
  end
24
24
 
25
- # performs knife cookbook test
26
- # returns true if cookbook passed or false if it failed
25
+ # returns true if tests defined in reagan_test.yml passed/don't exist or false if it failed
27
26
  def test
28
- puts 'Running reagan_test Rake task:'
29
- # run the rake task if it exists, otherwise skip
30
- if File.exist?(File.join(@@config['jenkins']['workspace_dir'], 'cookbooks', @cookbook, 'Rakefile'))
31
- result = system "rake #{File.join(@@config['jenkins']['workspace_dir'], 'cookbooks', @cookbook, 'Rakefile')} > /dev/null 2>&1"
32
- puts result ? ' PASS: reagan_test Rake task was successful' : ' FAIL: reagan_test Rake task was NOT successful'
33
- result
27
+ puts 'Running reagan_test.yml defined tests:'
28
+ # check to see if a reagan_test.yml file exists
29
+ if File.exist?(File.join(@@config['jenkins']['workspace_dir'], 'cookbooks', @cookbook, 'reagan_test.yml'))
30
+
31
+ # load the reagan config file
32
+ reagan_def = YAML.load_file(File.join(@@config['jenkins']['workspace_dir'], 'cookbooks', @cookbook, 'reagan_test.yml'))
33
+
34
+ # change into the cookbook dir so rake tests run locally
35
+ Dir.chdir(File.join(@@config['jenkins']['workspace_dir'], 'cookbooks', @cookbook))
36
+
37
+ pass = true
38
+ reagan_def['tests'].each do |test|
39
+ result = system test
40
+ pass = false if result == false
41
+ end
42
+ puts pass ? ' PASS: reagan_test.yml test was successful' : ' FAIL: reagan_test.yml test was NOT successful'
43
+ pass
34
44
  else
35
- puts ' SKIP: No Rakefile found in the cookbook path. Skipping test'
45
+ puts ' SKIP: No reagan_test.yml file found in the cookbook path. Skipping test'
36
46
  end
37
47
  true
38
48
  end
@@ -0,0 +1,3 @@
1
+ tests:
2
+ - rubocop .
3
+ - foodcritic . -f any --tags ~FC001 --tags ~FC019
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.4.0
4
+ version: 0.5.0
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-11 00:00:00.000000000 Z
11
+ date: 2014-10-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: octokit
@@ -86,6 +86,7 @@ files:
86
86
  - lib/test_reagan.rb
87
87
  - lib/test_version.rb
88
88
  - reagan.yml.EXAMPLE
89
+ - reagan_test.yml.EXAMPLE
89
90
  homepage: http://www.github.com/tas50/reagan
90
91
  licenses:
91
92
  - Apache-2.0