jenkins_cap 0.0.0 → 0.1.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.
data/Gemfile CHANGED
@@ -4,6 +4,7 @@ source "http://rubygems.org"
4
4
  # gem "activesupport", ">= 2.3.5"
5
5
  gem "capistrano", ">= 2.9.0"
6
6
  gem "json"
7
+ gem "term-ansicolor"
7
8
 
8
9
  # Add dependencies to develop your gem here.
9
10
  # Include everything needed to run rake, tests, features, etc.
data/Gemfile.lock CHANGED
@@ -24,6 +24,7 @@ GEM
24
24
  rake (0.9.2.2)
25
25
  rcov (0.9.8)
26
26
  shoulda (2.11.3)
27
+ term-ansicolor (1.0.7)
27
28
 
28
29
  PLATFORMS
29
30
  ruby
@@ -35,3 +36,4 @@ DEPENDENCIES
35
36
  json
36
37
  rcov
37
38
  shoulda
39
+ term-ansicolor
data/README.rdoc CHANGED
@@ -1,6 +1,22 @@
1
1
  = jenkins_cap
2
2
 
3
- Description goes here.
3
+ Adds Jenkins tasks to Capistrano.
4
+
5
+ == Installation
6
+
7
+ $ gem install jenkins_cap
8
+
9
+ Include in your Capfile
10
+ require 'rubygems'
11
+ require 'jenkins_cap'
12
+
13
+ == Usage
14
+
15
+ In your deploy.rb
16
+ set :jenkins_host, "http://jenkins.example.com"
17
+ set :jenkins_job_name, "mybuild"
18
+
19
+ before 'deploy', 'jenkins_cap:build_check' # check if the revision has been built by Jenkins successfully
4
20
 
5
21
  == Contributing to jenkins_cap
6
22
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.0
1
+ 0.1.0
@@ -0,0 +1,69 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{jenkins_cap}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = [%q{Dru Ibarra}]
12
+ s.date = %q{2012-03-09}
13
+ s.description = %q{add Jenkins tasks to Capistrano}
14
+ s.email = %q{Druwerd@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ "Gemfile",
22
+ "Gemfile.lock",
23
+ "LICENSE.txt",
24
+ "README.rdoc",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "jenkins_cap.gemspec",
28
+ "lib/jenkins_cap.rb",
29
+ "test/helper.rb",
30
+ "test/test_jenkins_cap.rb",
31
+ "test/test_settings.yml.template"
32
+ ]
33
+ s.homepage = %q{http://github.com/Druwerd/jenkins_cap}
34
+ s.licenses = [%q{MIT}]
35
+ s.require_paths = [%q{lib}]
36
+ s.rubygems_version = %q{1.8.6}
37
+ s.summary = %q{adds Jenkins tasks to Capistrano}
38
+
39
+ if s.respond_to? :specification_version then
40
+ s.specification_version = 3
41
+
42
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
43
+ s.add_runtime_dependency(%q<capistrano>, [">= 2.9.0"])
44
+ s.add_runtime_dependency(%q<json>, [">= 0"])
45
+ s.add_runtime_dependency(%q<term-ansicolor>, [">= 0"])
46
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
47
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
48
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
49
+ s.add_development_dependency(%q<rcov>, [">= 0"])
50
+ else
51
+ s.add_dependency(%q<capistrano>, [">= 2.9.0"])
52
+ s.add_dependency(%q<json>, [">= 0"])
53
+ s.add_dependency(%q<term-ansicolor>, [">= 0"])
54
+ s.add_dependency(%q<shoulda>, [">= 0"])
55
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
56
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
57
+ s.add_dependency(%q<rcov>, [">= 0"])
58
+ end
59
+ else
60
+ s.add_dependency(%q<capistrano>, [">= 2.9.0"])
61
+ s.add_dependency(%q<json>, [">= 0"])
62
+ s.add_dependency(%q<term-ansicolor>, [">= 0"])
63
+ s.add_dependency(%q<shoulda>, [">= 0"])
64
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
65
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
66
+ s.add_dependency(%q<rcov>, [">= 0"])
67
+ end
68
+ end
69
+
data/lib/jenkins_cap.rb CHANGED
@@ -1,8 +1,14 @@
1
1
  require 'json'
2
+ require 'term/ansicolor'
3
+ require 'capistrano'
2
4
 
3
- Capistrano::Configuration.instance(true).load do
5
+ class String
6
+ include Term::ANSIColor
7
+ end
4
8
 
9
+ module Capistrano
5
10
  module JenkinsCap
11
+
6
12
  def json_request(url)
7
13
  response = `wget -q -O - #{url}`
8
14
  JSON.load(response)
@@ -13,6 +19,8 @@ Capistrano::Configuration.instance(true).load do
13
19
  builds = []
14
20
  json_results['builds'].each{|b| builds << b['number']}
15
21
  builds
22
+ rescue NoMethodError => e
23
+ puts "WARNING: #{e}".yellow
16
24
  end
17
25
 
18
26
  def get_revision_from_build(build_number)
@@ -21,41 +29,52 @@ Capistrano::Configuration.instance(true).load do
21
29
  revisions = []
22
30
  json_results['changeSet']['revisions'].each{|r| revisions << r['revision']}
23
31
  revisions.sort.last
32
+ rescue NoMethodError => e
33
+ puts "WARNING: #{e}".yellow
24
34
  end
25
35
 
26
- def build_has_current_revision?(build_number)
36
+ def build_has_revision?(build_number)
27
37
  build_revision = get_revision_from_build(build_number)
28
- puts build_revision
29
- build_revision.to_i == current_revision.to_i
38
+ #puts build_revision
39
+ build_revision.to_i == revision.to_i
30
40
  end
31
41
 
32
42
  def build_passed?(build_number)
33
43
  json_results = json_request("#{jenkins_host}/job/#{jenkins_job_name}/#{build_number}/api/json")
34
- puts json_results['result']
35
44
  json_results['result'] == "SUCCESS"
45
+ rescue NoMethodError => e
46
+ puts "WARNING: #{e}".yellow
36
47
  end
37
48
 
38
49
  def revision_passed?()
39
50
  builds_list = get_builds()
51
+ return false if builds_list.nil?
52
+
40
53
  builds_list.each do |build_number|
41
- puts "checking #{build_number}"
42
- if build_has_current_revision?(build_number) # check if build has the revision we care about
54
+ if build_has_revision?(build_number) # check if build has the revision we care about
43
55
  return build_passed?(build_number)
44
56
  end
45
57
  end
46
58
  false
47
59
  end
48
- end
60
+
61
+ def self.load_into(configuration)
62
+ configuration.load do
63
+ namespace :jenkins_cap do
64
+ desc "Check if this deployment as a good Jenkins build"
65
+ task "build_check" do
66
+ abort "\n\n\nThis revision #{revision} has not been built by Jenkins successfully!\n\n\n".red unless jenkins.revision_passed?
67
+ end # end of task
68
+ end # end of namespace
69
+ end # end of configuration.load
70
+ end # end of def self.load_into
71
+
72
+ end # end of JenkinsCap module
49
73
 
50
74
  Capistrano.plugin :jenkins, JenkinsCap
51
75
 
52
- namespace :jenkinscap do
53
- desc "Check if this deployment as a good Jenkins build"
54
- task "build_check" do
55
- if (not jenkins.revision_passed?)
56
- abort "\n\n\n\e[0;31m This revision #{current_revision} has not been built by Jenkins successfully! \e[0m\n\n\n"
57
- end
58
- end
59
- end
76
+ end # end of Capistrano module
60
77
 
78
+ if Capistrano::Configuration.instance
79
+ Capistrano::JenkinsCap.load_into(Capistrano::Configuration.instance)
61
80
  end
data/test/helper.rb CHANGED
@@ -9,7 +9,6 @@ rescue Bundler::BundlerError => e
9
9
  end
10
10
  require 'test/unit'
11
11
  require 'shoulda'
12
- require 'capistrano'
13
12
 
14
13
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
15
14
  $LOAD_PATH.unshift(File.dirname(__FILE__))
@@ -1,10 +1,51 @@
1
1
  require 'helper'
2
2
 
3
+ TEST_SETTINGS = YAML.load_file(File.join(File.dirname(__FILE__), "test_settings.yml"))
4
+
3
5
  class TestJenkinsCap < Test::Unit::TestCase
4
6
  def setup
7
+ @config = Capistrano::Configuration.new
8
+ Capistrano::JenkinsCap.load_into(@config)
9
+ @config.role :app, TEST_SETTINGS["app"]
10
+ @config.set :deploy_to, TEST_SETTINGS["deploy_to"]
11
+ @config.set :jenkins_host, TEST_SETTINGS["jenkins_host"]
12
+ @config.set :jenkins_job_name, TEST_SETTINGS["jenkins_job_name"]
13
+ @config.set :revision, TEST_SETTINGS["revision"]
14
+ end
15
+
16
+ # Unit tests for helper functions
17
+ #
18
+ should "get a successful JSON response" do
19
+ assert @config.jenkins.json_request("#{@config.jenkins_host}/api/json")
20
+ end
21
+
22
+ should "get an Array of build numbers" do
23
+ assert_kind_of Array, @config.jenkins.get_builds
24
+ end
25
+
26
+ should "get a revision number (or nil) without error" do
27
+ # no assertion here because can't be sure what we'll get from Jenkins
28
+ @config.jenkins.get_revision_from_build(TEST_SETTINGS["build_number"])
29
+ end
30
+
31
+ should "check if a build contains the revision number about to be deployed" do
32
+ # no assertion here because can't be sure what we'll get from Jenkins
33
+ @config.jenkins.build_has_revision?(TEST_SETTINGS["build_number"])
34
+ end
35
+
36
+ should "check if a build passed" do
37
+ # no assertion here because can't be sure what we'll get from Jenkins
38
+ @config.jenkins.build_passed?(TEST_SETTINGS["build_number"])
39
+ end
40
+
41
+ should "check if a revision passed" do
42
+ # no assertion here because can't be sure what we'll get from Jenkins
43
+ @config.jenkins.revision_passed?
5
44
  end
6
45
 
7
- should "probably rename this file and start testing for real" do
8
- flunk "hey buddy, you should probably rename this file and start testing for real"
46
+ # Unit tests for Capistrano tasks
47
+ should "run build_check task" do
48
+ # need a revision that will pass, otherwise the tests will abort
49
+ #@config.jenkins_cap.build_check
9
50
  end
10
51
  end
@@ -0,0 +1,5 @@
1
+ app: localhost
2
+ deploy_to: "/tmp"
3
+ jenkins_host: "http://localhost"
4
+ jenkins_job_name: "test_job"
5
+ revision: "1"
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jenkins_cap
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
+ - 1
8
9
  - 0
9
- - 0
10
- version: 0.0.0
10
+ version: 0.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Dru Ibarra
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-03-06 00:00:00 Z
18
+ date: 2012-03-09 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  type: :runtime
@@ -48,7 +48,7 @@ dependencies:
48
48
  name: json
49
49
  prerelease: false
50
50
  - !ruby/object:Gem::Dependency
51
- type: :development
51
+ type: :runtime
52
52
  requirement: &id003 !ruby/object:Gem::Requirement
53
53
  none: false
54
54
  requirements:
@@ -59,11 +59,25 @@ dependencies:
59
59
  - 0
60
60
  version: "0"
61
61
  version_requirements: *id003
62
- name: shoulda
62
+ name: term-ansicolor
63
63
  prerelease: false
64
64
  - !ruby/object:Gem::Dependency
65
65
  type: :development
66
66
  requirement: &id004 !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ hash: 3
72
+ segments:
73
+ - 0
74
+ version: "0"
75
+ version_requirements: *id004
76
+ name: shoulda
77
+ prerelease: false
78
+ - !ruby/object:Gem::Dependency
79
+ type: :development
80
+ requirement: &id005 !ruby/object:Gem::Requirement
67
81
  none: false
68
82
  requirements:
69
83
  - - ~>
@@ -74,12 +88,12 @@ dependencies:
74
88
  - 0
75
89
  - 0
76
90
  version: 1.0.0
77
- version_requirements: *id004
91
+ version_requirements: *id005
78
92
  name: bundler
79
93
  prerelease: false
80
94
  - !ruby/object:Gem::Dependency
81
95
  type: :development
82
- requirement: &id005 !ruby/object:Gem::Requirement
96
+ requirement: &id006 !ruby/object:Gem::Requirement
83
97
  none: false
84
98
  requirements:
85
99
  - - ~>
@@ -90,12 +104,12 @@ dependencies:
90
104
  - 6
91
105
  - 4
92
106
  version: 1.6.4
93
- version_requirements: *id005
107
+ version_requirements: *id006
94
108
  name: jeweler
95
109
  prerelease: false
96
110
  - !ruby/object:Gem::Dependency
97
111
  type: :development
98
- requirement: &id006 !ruby/object:Gem::Requirement
112
+ requirement: &id007 !ruby/object:Gem::Requirement
99
113
  none: false
100
114
  requirements:
101
115
  - - ">="
@@ -104,7 +118,7 @@ dependencies:
104
118
  segments:
105
119
  - 0
106
120
  version: "0"
107
- version_requirements: *id006
121
+ version_requirements: *id007
108
122
  name: rcov
109
123
  prerelease: false
110
124
  description: add Jenkins tasks to Capistrano
@@ -124,9 +138,11 @@ files:
124
138
  - README.rdoc
125
139
  - Rakefile
126
140
  - VERSION
141
+ - jenkins_cap.gemspec
127
142
  - lib/jenkins_cap.rb
128
143
  - test/helper.rb
129
144
  - test/test_jenkins_cap.rb
145
+ - test/test_settings.yml.template
130
146
  homepage: http://github.com/Druwerd/jenkins_cap
131
147
  licenses:
132
148
  - MIT