cider_ci-support 1.0.0.pre.beta.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: 1e09f4d2a4d72576c796662b6cac7c000dffd55d
4
+ data.tar.gz: a2116eb4ec51cee52cc46942ba65e5179591a227
5
+ SHA512:
6
+ metadata.gz: 5830c018025c6a3432ae2f1148fd4152a6370105a9c13ebb61a338e3cb406333b333cc7a3f7442c22812e7ede9fb2e69a4ca04795d0f3b58e9c485d646169f34
7
+ data.tar.gz: 43ec163832dc8ec8f51cb329def4c9cf9b7151ba9ce02a28fb90e604f1fa77f3a109b596ad6ee5444e8c58134499120d0fdb2cec9c359c02a35ae335e7c04562
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Thomas Schank
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,46 @@
1
+ # Cider-CI Support for Ruby and Ruby on Rails projects
2
+
3
+ This gem provides convenience executables to work with Cider-CI.
4
+
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'cider_ci-support'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install cider_ci-rails
21
+
22
+
23
+ ## Usage
24
+
25
+ ### Aggregate Coverage with `cider-ci_coverage`
26
+
27
+ 1. Add [Simplecov]() to your project and configure it.
28
+
29
+ 2. Have the coverage output attached to the trials, e.g.
30
+
31
+ ```yaml
32
+ task_defaults:
33
+ trial_attachments:
34
+ coverage_resultset:
35
+ glob: 'coverage/.resultset.json'
36
+ content-type: application/json
37
+ ```
38
+
39
+ 3. Run the tests on Cider-CI.
40
+
41
+ 4. Within the top level directory of you project, e.g.
42
+
43
+ cider-ci_coverage -e EXECUTION_ID
44
+
45
+
46
+
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,217 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ ###############################################################################
4
+ # This script gathers ruby coverage information from a cider-ci instance and
5
+ # aggregates it via simplecov.
6
+ #
7
+ # Authors: Thomas Schank <DrTom@schank.ch>
8
+ #
9
+ ###############################################################################
10
+
11
+
12
+ # Planned features for the future:
13
+ #
14
+ # * upload result to cider-ci (attachments to the tree_id)
15
+
16
+ require 'fileutils'
17
+ require 'json_roa/client'
18
+ require 'optparse'
19
+ require 'ostruct'
20
+ require 'simplecov'
21
+ require 'thread/future'
22
+ require 'thread/pool'
23
+ require 'mime/types'
24
+ require 'open-uri'
25
+
26
+ #require 'pry'
27
+
28
+ ###############################################################################
29
+ # Download from Cider-CI
30
+ ###############################################################################
31
+
32
+ def connect base_url, username, password
33
+ root_resource = JSON_ROA::Client.connect base_url do |conn|
34
+ conn.basic_auth(username,password)
35
+ conn.ssl.verify= false
36
+ end
37
+ end
38
+
39
+ def get_execution_resource root, execution_id
40
+ root.relation('execution').get('id' => execution_id )
41
+ end
42
+
43
+
44
+ def get_and_convert_resultset_attachments execution, thread_pool_size
45
+ print "download_resultset_attachments"; STDOUT.flush
46
+ pool = Thread.pool thread_pool_size
47
+
48
+ execution.relation('tasks').get("state" => "success").collection\
49
+ .map do |task_relation|
50
+ Thread.future pool do
51
+ print "."; STDOUT.flush
52
+ task_relation.get().relation('trials') \
53
+ .get("state" => "success").collection.map(&:get).map do |trial|
54
+ print "."; STDOUT.flush
55
+ trial.relation('trial-attachments') \
56
+ .get.collection.map do |tar|
57
+ trial_attachment_resource= tar.get
58
+ print "."; STDOUT.flush
59
+ if (working_dir= trial.data['scripts'] \
60
+ .map{|k,v| v["working_dir"]}.compact.first) \
61
+ and (trial_attachment_resource.data['path'] =~ /resultset\.json/)
62
+ print "*"; STDOUT.flush
63
+ resultset= trial_attachment_resource \
64
+ .relation('data-stream').get.response.body
65
+ convert_resultset resultset, working_dir
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end.map(&:~).flatten.compact
71
+ end
72
+
73
+
74
+
75
+ ###############################################################################
76
+ # Simplev cov
77
+ ###############################################################################
78
+
79
+
80
+ def convert_resultset resultset, working_dir
81
+ SimpleCov::JSON.parse(resultset.to_json).map do |command_name, data|
82
+ [ command_name, data.map do |k,v|
83
+ case k
84
+ when "coverage"
85
+ [ k, v.map do |filename,file_coverage|
86
+ [(FileUtils.pwd + filename[working_dir.length,filename.length]) \
87
+ , file_coverage]
88
+ end.instance_eval{Hash[self]} ]
89
+ else
90
+ [k,v]
91
+ end
92
+ end.instance_eval {Hash[self]} ]
93
+ end.instance_eval{Hash[self]}.instance_eval{SimpleCov::Result.from_hash(self)}
94
+ end
95
+
96
+
97
+ def reduce_resultsets resultsets
98
+ puts "reduce_resultsets"
99
+ resultsets.reduce({}) do |agg,resultset|
100
+ resultset.original_result.merge_resultset(agg)
101
+ end
102
+ end
103
+
104
+
105
+ def init_simple_cov
106
+ SimpleCov.add_group "Models", "app/models"
107
+ SimpleCov.add_group "Controllers", "app/controllers"
108
+ SimpleCov.add_group "Views", "app/views"
109
+ SimpleCov.add_group "Helpers", "app/helpers"
110
+ SimpleCov.add_group "Factories", "factories"
111
+ SimpleCov.add_group "Libraries", "app/lib"
112
+ end
113
+
114
+
115
+ ###############################################################################
116
+ # Run
117
+ ###############################################################################
118
+
119
+ def run_coverage execution, thrad_pool_size
120
+ get_and_convert_resultset_attachments(execution,thrad_pool_size) \
121
+ .instance_eval do
122
+ reduce_resultsets self
123
+ end.instance_eval do
124
+ init_simple_cov
125
+ SimpleCov::Result.new self
126
+ end.instance_eval do
127
+ SimpleCov::Formatter::HTMLFormatter.new.format self
128
+ end
129
+ end
130
+
131
+
132
+ ###############################################################################
133
+ # Options, main ....
134
+ ###############################################################################
135
+
136
+
137
+ def parse_options options
138
+
139
+
140
+ optparse = OptionParser.new do |opts|
141
+ opts.banner = "Usage: retrieve_cider_coverage.rb -e EXECUTION_ID"
142
+
143
+ opts.on('-a', '--api-url API-URL') do |url|
144
+ options.api_url= url
145
+ end
146
+
147
+ opts.on('-e', '--execution EXECUTION_ID',
148
+ 'Execution ID to retrieve coverage for') do |exid|
149
+ options.execution_id = exid
150
+ end
151
+
152
+ opts.on('-t', '--thread-pool-size N', Integer) do |t|
153
+ options.thread_pool_size = t
154
+ end
155
+
156
+ opts.on('-u', '--username NAME', String) do |n|
157
+ options.username = n
158
+ end
159
+
160
+ opts.on('-p', '--password PASSWORD', String) do |p|
161
+ options.password= p
162
+ end
163
+
164
+ end.parse!
165
+
166
+ options
167
+ end
168
+
169
+
170
+ def assert_correct_tree_id execution
171
+ if execution.data['tree_id'] != `git log -n 1 --pretty=%T`.strip
172
+ raise ScriptError, "you must be on the same tree_id as the execution"
173
+ end
174
+ end
175
+
176
+ def upload_as_tree_attachments execution
177
+ print "upload_as_tree_attachments"; STDOUT.flush
178
+ upload_relation= execution.relation("tree-attachments").get().relation("data-stream")
179
+ Dir.glob("coverage/**/*").each do |filename|
180
+ if content_type= MIME::Types.of(filename).first.content_type rescue nil
181
+ payload= Faraday::UploadIO.new(filename, content_type)
182
+ upload_relation.put({"path" => filename},
183
+ File.open(filename, "rb").read,
184
+ {"content-type" => content_type})
185
+ print "*"; STDOUT.flush
186
+ end
187
+ end
188
+ puts ""
189
+ end
190
+
191
+ def main
192
+ options = OpenStruct.new
193
+ options.thread_pool_size= 50
194
+ options.execution_id= nil
195
+ options.username= ENV['CIDER_CI_USERNAME']
196
+ options.password= ENV['CIDER_CI_PASSWORD']
197
+ options.api_url= ENV['CIDER_CI_API_URL']
198
+ parse_options options
199
+ options.execution_id || raise(OptionParser::MissingArgument \
200
+ , "execution_id is required")
201
+ options.api_url || raise(OptionParser::MissingArgument \
202
+ , "api_url is required, set CIDER_CI_API_URL or provide -a option")
203
+ options.username || raise(OptionParser::MissingArgument \
204
+ , "username is required, set CIDER_CI_USERNAME")
205
+ options.password || raise(OptionParser::MissingArgument \
206
+ , "password is required, set CIDER_CI_PASSWORD")
207
+
208
+
209
+ root = connect(options.api_url, options.username, options.password).get()
210
+ execution= get_execution_resource root, options.execution_id
211
+ assert_correct_tree_id execution
212
+ FileUtils.rm_rf('coverage')
213
+ run_coverage execution, options.thread_pool_size
214
+ upload_as_tree_attachments execution
215
+ end
216
+
217
+ main
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'cider_ci/support/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "cider_ci-support"
8
+ spec.version = Cider_CI::Support::VERSION
9
+ spec.authors = ["Thomas Schank"]
10
+ spec.email = ["DrTom@schank.ch"]
11
+ spec.summary = "Cider-CI support for Ruby and Ruby on Rails projects"
12
+ spec.description = ""
13
+ spec.homepage = "https://github.com/cider-ci/cider-ci_ruby-support"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+
24
+ spec.add_runtime_dependency 'mime-types', '~> 2.4'
25
+ spec.add_runtime_dependency 'thread', '= 0.1.4'
26
+ spec.add_runtime_dependency 'simplecov', '~> 0.9'
27
+ spec.add_runtime_dependency 'json_roa-client', "= 1.0.0.pre.beta.0"
28
+ end
@@ -0,0 +1,5 @@
1
+ module Cider_CI
2
+ module Support
3
+ VERSION = "1.0.0-beta.0"
4
+ end
5
+ end
@@ -0,0 +1,6 @@
1
+ require "cider_ci/support/version"
2
+
3
+ module Cider_CI
4
+ module Support
5
+ end
6
+ end
metadata ADDED
@@ -0,0 +1,138 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cider_ci-support
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0.pre.beta.0
5
+ platform: ruby
6
+ authors:
7
+ - Thomas Schank
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: mime-types
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.4'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.4'
55
+ - !ruby/object:Gem::Dependency
56
+ name: thread
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: 0.1.4
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '='
67
+ - !ruby/object:Gem::Version
68
+ version: 0.1.4
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.9'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.9'
83
+ - !ruby/object:Gem::Dependency
84
+ name: json_roa-client
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '='
88
+ - !ruby/object:Gem::Version
89
+ version: 1.0.0.pre.beta.0
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '='
95
+ - !ruby/object:Gem::Version
96
+ version: 1.0.0.pre.beta.0
97
+ description: ''
98
+ email:
99
+ - DrTom@schank.ch
100
+ executables:
101
+ - cider-ci_coverage
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".gitignore"
106
+ - Gemfile
107
+ - LICENSE.txt
108
+ - README.md
109
+ - Rakefile
110
+ - bin/cider-ci_coverage
111
+ - cider_ci-support.gemspec
112
+ - lib/cider_ci/support.rb
113
+ - lib/cider_ci/support/version.rb
114
+ homepage: https://github.com/cider-ci/cider-ci_ruby-support
115
+ licenses:
116
+ - MIT
117
+ metadata: {}
118
+ post_install_message:
119
+ rdoc_options: []
120
+ require_paths:
121
+ - lib
122
+ required_ruby_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ required_rubygems_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">"
130
+ - !ruby/object:Gem::Version
131
+ version: 1.3.1
132
+ requirements: []
133
+ rubyforge_project:
134
+ rubygems_version: 2.2.2
135
+ signing_key:
136
+ specification_version: 4
137
+ summary: Cider-CI support for Ruby and Ruby on Rails projects
138
+ test_files: []