jackal-kitchen 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d226c76d54712b52e6c65bd61c088c17b784286c
4
+ data.tar.gz: 9bb59b0be25e5cb108dc1a0d2aaabf94df69a9c0
5
+ SHA512:
6
+ metadata.gz: f1cd57f4ef6381fed5963b2bf91ee5e3765b6f4f738670384f8b77cf397701deaf1fbb64cb88934402aee1101af73ff1d5242636f04ef6130620145840da62b4
7
+ data.tar.gz: fe5c54f0c7f94010abc8034acc30093547492aa49888444ab8956dcfac8ab589a6f631b3c49cc44d4e6ae275a2f5513b73b59348bd76fdd7d1cc226cd16e68a4
data/CHANGELOG.md ADDED
File without changes
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,25 @@
1
+ # Contributing
2
+
3
+ ## Branches
4
+
5
+ ### `master` branch
6
+
7
+ The master branch is the current stable released version.
8
+
9
+ ### `develop` branch
10
+
11
+ The develop branch is the current edge of development.
12
+
13
+ ## Pull requests
14
+
15
+ * https://github.com/carnivore-rb/jackal-kitchen/pulls
16
+
17
+ Please base all pull requests of the `develop` branch. Merges to
18
+ `master` only occur through the `develop` branch. Pull requests
19
+ based on `master` will likely be cherry picked.
20
+
21
+ ## Issues
22
+
23
+ Need to report an issue? Use the github issues:
24
+
25
+ * https://github.com/carnivore-rb/jackal-kitchen/issues
data/LICENSE ADDED
File without changes
data/README.md ADDED
File without changes
@@ -0,0 +1,18 @@
1
+ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__)) + '/lib/'
2
+ require 'jackal-kitchen/version'
3
+ Gem::Specification.new do |s|
4
+ s.name = 'jackal-kitchen'
5
+ s.version = Jackal::Kitchen::VERSION.version
6
+ s.summary = 'Test Kitchen executor'
7
+ s.author = 'Anthony Goddard'
8
+ s.email = 'anthony@hw-ops.com'
9
+ s.homepage = 'https://github.com/carnivore-rb/jackal-kitchen'
10
+ s.description = 'Command helpers'
11
+ s.require_path = 'lib'
12
+ s.license = 'Apache 2.0'
13
+ s.add_dependency 'jackal'
14
+ s.add_dependency 'childprocess'
15
+ s.add_dependency 'carnivore-http'
16
+ s.add_dependency 'carnivore-actor'
17
+ s.files = Dir['lib/**/*'] + %w(jackal-kitchen.gemspec README.md CHANGELOG.md CONTRIBUTING.md LICENSE)
18
+ end
@@ -0,0 +1,9 @@
1
+ require 'jackal'
2
+ require 'jackal-kitchen/version'
3
+ require 'jackal-kitchen/hook'
4
+
5
+ module Jackal
6
+ module Kitchen
7
+ autoload :Tester, 'jackal-kitchen/tester'
8
+ end
9
+ end
@@ -0,0 +1,17 @@
1
+ require 'jackal-kitchen'
2
+
3
+ class Jackal::Kitchen::Hook < Jackal::Utils::HttpApi; end
4
+
5
+ Jackal::Kitchen::Hook.define do
6
+ post '/kitchen' do |msg|
7
+ begin
8
+ Carnivore::Supervisor.supervisor[:jackal_kitchen_input].transmit(
9
+ new_payload('kitchen', :github => msg[:message][:body])
10
+ )
11
+ rescue => e
12
+ error "Error encountered #{e}"
13
+ ensure
14
+ msg.confirm!
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,116 @@
1
+ require 'jackal-kitchen'
2
+
3
+ module Jackal
4
+ module Kitchen
5
+ # Kitchen runner
6
+ class Tester < Jackal::Callback
7
+
8
+ # Setup the callback
9
+ def setup(*_)
10
+ require 'childprocess'
11
+ require 'tmpdir'
12
+ require 'shellwords'
13
+ end
14
+
15
+ # Validity of message
16
+ #
17
+ # @param msg [Carnivore::Message]
18
+ # @return [TrueClass, FalseClass]
19
+ def valid?(msg)
20
+ super do |payload|
21
+ payload.get(:data, :github, :ref)
22
+ end
23
+ end
24
+
25
+ # Execute action (test kitchen run)
26
+ #
27
+ # @param msg [Carnivore::Message]
28
+ def execute(msg)
29
+ failure_wrap(msg) do |payload|
30
+ user = payload.get(:data, :github, :repository, :owner, :name)
31
+ ref = payload.get(:data, :github, :head_commit, :id)
32
+ repo = payload.get(:data, :github, :repository, :url)
33
+ working_dir = working_path = Dir.mktmpdir
34
+ begin
35
+ maybe_clean_bundle do
36
+ setup_command("git clone #{repo} cookbook", working_path, payload)
37
+ working_path = File.join(working_path, 'cookbook')
38
+ setup_command("git checkout #{ref}", working_path, payload)
39
+ setup_command("bundle install", working_path, payload)
40
+ kitchen_command("bundle exec kitchen test", working_path, payload)
41
+ end
42
+ rescue => e
43
+ raise
44
+ ensure
45
+ FileUtils.rm_rf(working_dir)
46
+ end
47
+ job_completed(:kitchen, payload, msg)
48
+ end
49
+ end
50
+
51
+ # Run a command
52
+ #
53
+ # @param command [String] command to execute
54
+ # @param working_path [String] local working path
55
+ # @param payload [Smash] current payload
56
+ # @return [TrueClass]
57
+ def setup_command(command, working_path, payload)
58
+ cmd_input = Shellwords.shellsplit(command)
59
+ process = ChildProcess.build(*cmd_input)
60
+ stdout = File.open(File.join(working_path, 'stdout'), 'w+')
61
+ stderr = File.open(File.join(working_path, 'stderr'), 'w+')
62
+ process.io.stdout = stdout
63
+ process.io.stderr = stderr
64
+ process.cwd = working_path
65
+ process.start
66
+ status = process.wait
67
+ if status == 0
68
+ info "Setup command '#{command}' completed sucessfully"
69
+ payload.set(:data, :kitchen, :result, command, :success)
70
+ true
71
+ else
72
+ error "Command '#{command}' failed"
73
+ payload.set(:data, :kitchen, :result, command, :fail)
74
+ raise "Failed to execute setup command '#{command}'"
75
+ end
76
+ end
77
+
78
+ def kitchen_command(command, working_path, payload)
79
+ cmd_input = Shellwords.shellsplit(command)
80
+ process = ChildProcess.build(*cmd_input)
81
+ stdout = File.open(File.join(working_path, 'stdout'), 'w+')
82
+ stderr = File.open(File.join(working_path, 'stderr'), 'w+')
83
+ process.io.stdout = stdout
84
+ process.io.stderr = stderr
85
+ process.cwd = working_path
86
+ process.start
87
+ status = process.wait
88
+ if status == 0
89
+ info "Command '#{command}' completed sucessfully"
90
+ payload.set(:data, :kitchen, :result, command, :success)
91
+ true
92
+ else
93
+ error "Command '#{command}' failed"
94
+ payload.set(:data, :kitchen, :result, command, :fail)
95
+ raise "Failed to execute command '#{command}'"
96
+ end
97
+ end
98
+
99
+ # Clean environment of bundler variables
100
+ # if bundler is in use
101
+ #
102
+ # @yield block to execute
103
+ # @return [Object] result of yield
104
+ def maybe_clean_bundle
105
+ if(defined?(Bundler))
106
+ Bundler.with_clean_env do
107
+ yield
108
+ end
109
+ else
110
+ yield
111
+ end
112
+ end
113
+
114
+ end
115
+ end
116
+ end
@@ -0,0 +1,5 @@
1
+ module Jackal
2
+ module Kitchen
3
+ VERSION = Gem::Version.new('0.1.0')
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jackal-kitchen
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Anthony Goddard
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: jackal
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: childprocess
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: carnivore-http
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: carnivore-actor
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Command helpers
70
+ email: anthony@hw-ops.com
71
+ executables: []
72
+ extensions: []
73
+ extra_rdoc_files: []
74
+ files:
75
+ - CHANGELOG.md
76
+ - CONTRIBUTING.md
77
+ - LICENSE
78
+ - README.md
79
+ - jackal-kitchen.gemspec
80
+ - lib/jackal-kitchen.rb
81
+ - lib/jackal-kitchen/hook.rb
82
+ - lib/jackal-kitchen/tester.rb
83
+ - lib/jackal-kitchen/version.rb
84
+ homepage: https://github.com/carnivore-rb/jackal-kitchen
85
+ licenses:
86
+ - Apache 2.0
87
+ metadata: {}
88
+ post_install_message:
89
+ rdoc_options: []
90
+ require_paths:
91
+ - lib
92
+ required_ruby_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ requirements: []
103
+ rubyforge_project:
104
+ rubygems_version: 2.2.2
105
+ signing_key:
106
+ specification_version: 4
107
+ summary: Test Kitchen executor
108
+ test_files: []
109
+ has_rdoc: