pig-ci-rails 0.1.5 → 0.2.0

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
  SHA256:
3
- metadata.gz: 9a0910dfcd93b0aa8da420798e8888787f3c7c614a86836c6d456c89123aeea3
4
- data.tar.gz: c550a0069bd3d36eeba1511a3c9601777c8bbdb7f939d6c039b5cf0415f54b0a
3
+ metadata.gz: 45e75a450ac91998d1c684580aadb2f2beab4dc4b12aefc2b1cc39ff18d6aced
4
+ data.tar.gz: 35ceebb576bae40eaeb17566ae3cfa764e165c68e4c2680f4257b1046849d79d
5
5
  SHA512:
6
- metadata.gz: f7411322993aa119f7e8f70d545ec214aed0730467b7274aab4ea4f33a9359ef6569b649056882c9eaaed4f44e9429232b65c980e536539bf98c703dc5feb7c3
7
- data.tar.gz: 82d3ed70e9f709d0d464c8df1acb9c37f9a2c62c722f48c98362d2d4f5e5d3f6a402cbcfe8c522a0ffcd5b85533c2dda38f81e05d2f34d158f446c32e3d93ac1
6
+ metadata.gz: d59558555c2138ea84554770b9e296c5e49d7f3c9b50f2913bf7d5a3b64be795e947440cf297665e9e726bae9ad5ab1934fec67f8194ed95692c8555d99b0b4b
7
+ data.tar.gz: 74e3514d08d9021ab082f4e75c3edc8bf7e7c369b10a83583f96ec701e1f312325e1bf338286a168793eb06eb24de0aa54dac6540932fadc83ba26d8ba05d11c
@@ -0,0 +1,29 @@
1
+ name: Build & Publish Ruby Gem
2
+
3
+ on:
4
+ create:
5
+ tags:
6
+
7
+ jobs:
8
+ build:
9
+ name: Build + Publish
10
+ runs-on: ubuntu-latest
11
+
12
+ steps:
13
+ - uses: actions/checkout@v2
14
+ - name: Set up Ruby 2.6
15
+ uses: actions/setup-ruby@v1
16
+ with:
17
+ version: 2.6.x
18
+
19
+ - name: Publish to GPR
20
+ run: |
21
+ mkdir -p $HOME/.gem
22
+ touch $HOME/.gem/credentials
23
+ chmod 0600 $HOME/.gem/credentials
24
+ printf -- "---\n:github: Bearer ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
25
+ gem build *.gemspec
26
+ gem push --KEY github --host https://rubygems.pkg.github.com/${OWNER} *.gem
27
+ env:
28
+ GEM_HOST_API_KEY: ${{secrets.GPR_AUTH_TOKEN}}
29
+ OWNER: MikeRogers0
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.6.5
data/.travis.yml CHANGED
@@ -7,10 +7,10 @@ cache: bundler
7
7
 
8
8
  rvm:
9
9
  - 2.3.8
10
- - 2.4.5
11
- - 2.5.3
12
- - 2.6.3
13
- - ruby-head
10
+ - 2.4.7
11
+ - 2.5.7
12
+ - 2.6.5
13
+ - 2.7.0-preview1
14
14
 
15
15
  before_install:
16
16
  - gem install bundler -v 2.0.1
data/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.3.0 (In Development)
4
+
5
+ * TODO: Deprecate pigci.com integration.
6
+
7
+ ## 0.2.0
8
+
9
+ * [Updating TravisCI to test latest ruby versions](https://github.com/PigCI/pig-ci-rails/pull/15)
10
+ * [Update rake requirement from ~> 12.3 to ~> 13.0](https://github.com/PigCI/pig-ci-rails/pull/14)
11
+ * [Update rspec requirement from ~> 3.8.0 to ~> 3.9.0](https://github.com/PigCI/pig-ci-rails/pull/16)
12
+ * [Update webmock requirement from ~> 3.7.0 to ~> 3.8.0](https://github.com/PigCI/pig-ci-rails/pull/17)
13
+ * [Adding config.thresholds, this allows standalone usage without pigci.com](https://github.com/PigCI/pig-ci-rails/pull/18) & [Replace references for limit to be threshold](https://github.com/PigCI/pig-ci-rails/pull/21)
14
+ * Setting up repo to publish gem when new tags are created.
15
+
3
16
  ## 0.1.5
4
17
 
5
18
  * [Widen i18n gem version requirement](https://github.com/PigCI/pig-ci-rails/pull/12)
data/README.md CHANGED
@@ -45,22 +45,26 @@ require 'pig_ci'
45
45
  PigCI.start
46
46
  ```
47
47
 
48
- ### With [PigCI.com](https://pigci.com) - For sharing runs as a team via CI
48
+ ### Configuring thresholds
49
49
 
50
- You can hookup your project to PigCI.com, this will fail PRs when metric thresholds are exceeded (e.g. your app see a big increase in memory).
50
+ Configuring the thresholds will allow your test suite to fail in CI. You will need to configure the thresholds depending on your application.
51
51
 
52
52
  ```ruby
53
53
  # In spec/rails_helper.rb
54
54
  require 'pig_ci'
55
55
  PigCI.start do |config|
56
- # When you connect your project, you'll be given an API key.
57
- config.api_key = 'your-api-key-here'
58
- end
59
- ```
56
+ # Maximum memory in megabytes
57
+ config.thresholds.memory = 350
60
58
 
61
- It's a great way to track metrics over time & support this project.
59
+ # Maximum time per a HTTP request
60
+ config.thresholds.request_time = 250
62
61
 
63
- ### Configuring PigCI
62
+ # Maximum database calls per a request
63
+ config.thresholds.database_request = 35
64
+ end if RSpec.configuration.files_to_run.count > 1
65
+ ```
66
+
67
+ ### Configuring other options
64
68
 
65
69
  This gems was setup to be configured by passing a block to the `PigCI.start` method, e.g:
66
70
 
@@ -77,9 +81,27 @@ end # if RSpec.configuration.files_to_run.count > 1
77
81
 
78
82
  You can see the full configuration options [lib/pig_ci.rb](https://github.com/PigCI/pig-ci-rails/blob/master/lib/pig_ci.rb#L21).
79
83
 
84
+
85
+ ### With [PigCI.com](https://pigci.com) - For sharing runs as a team via CI
86
+
87
+ _Note: This feature will be deprecated in the future. Instead use "Configuring thresholds" to have CI pass/fail._
88
+
89
+ You can hookup your project to PigCI.com, this will fail PRs when metric thresholds are exceeded (e.g. your app see a big increase in memory).
90
+
91
+ ```ruby
92
+ # In spec/rails_helper.rb
93
+ require 'pig_ci'
94
+ PigCI.start do |config|
95
+ # When you connect your project, you'll be given an API key.
96
+ config.api_key = 'your-api-key-here'
97
+ end
98
+ ```
99
+
100
+ It's a great way to track metrics over time & support this project.
101
+
80
102
  ### Framework support
81
103
 
82
- Currently this gem only supports Ruby on Rails.
104
+ Currently this gem only supports Ruby on Rails tested via RSpec.
83
105
 
84
106
  ### Metric notes
85
107
 
@@ -128,12 +150,12 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
128
150
 
129
151
  Features I'd like to add at some point:
130
152
 
153
+ * Add support for "upsert" for when tests are split over multiple machines
131
154
  * HTML output to include branch - Right now they're just timestamps which makes filtering hard.
132
155
  * Document setting branch/commit to handle when CI doesn't set it correctly.
133
156
  * Add rake for submitting reports.
134
157
  * https://rubydoc.info/gems/yard/file/docs/GettingStarted.md - Document the gem so it's easier for people to jump on.
135
158
  * Support ActionCable (when requests have no key).
136
- * Add support for "upsert" for when tests are split over multiple machines
137
159
 
138
160
  ## Contributing
139
161
 
@@ -2,9 +2,12 @@ en:
2
2
  pig_ci:
3
3
  api:
4
4
  reports:
5
+ success: 'PigCI: Successfully submitted report to pigci.com'
5
6
  error: 'Unable to connect to PigCI API: %{error}'
6
7
  api_error: 'Unable to connect to PigCI API'
7
8
  summary:
9
+ ci_start: 'PigCI Thresholds Summary:'
10
+ ci_failure: 'PigCI: This commit has exceeded the thresholds defined in PigCI.thresholds'
8
11
  saved_successfully: PigCI report generated to %{output_directory}
9
12
  title: PigCI Results
10
13
  view_historic_reports: 'Historic Reports'
data/lib/pig_ci.rb CHANGED
@@ -4,6 +4,7 @@ require 'rake'
4
4
 
5
5
  require 'pig_ci/version'
6
6
  require 'pig_ci/api'
7
+ require 'pig_ci/configuration'
7
8
  require 'pig_ci/decorator'
8
9
  require 'pig_ci/summary'
9
10
  require 'pig_ci/profiler_engine'
@@ -117,6 +118,14 @@ module PigCI
117
118
  @locale || :en
118
119
  end
119
120
 
121
+ def thresholds=(values)
122
+ @thresholds = PigCI::Configuration::Thresholds.new(values)
123
+ end
124
+
125
+ def thresholds
126
+ @thresholds ||= PigCI::Configuration::Thresholds.new
127
+ end
128
+
120
129
  module_function
121
130
 
122
131
  def start(&block)
@@ -154,6 +163,9 @@ module PigCI
154
163
 
155
164
  # If they have an API key, share it with PigCI.com
156
165
  PigCI::Api::Reports.new(reports: profiler_engine.reports).share! if PigCI.api_key?
166
+
167
+ # Make sure CI fails when metrics are over thresholds.
168
+ PigCI::Summary::CI.new(reports: profiler_engine.reports).call!
157
169
  end
158
170
  end
159
171
 
@@ -5,7 +5,10 @@ class PigCI::Api::Reports < PigCI::Api
5
5
 
6
6
  def share!
7
7
  response = post_payload
8
- return if response.success?
8
+ if response.success?
9
+ puts I18n.t('pig_ci.api.reports.success')
10
+ return
11
+ end
9
12
 
10
13
  puts I18n.t('pig_ci.api.reports.error', error: JSON.parse(response.parsed_response || '{}')['error'])
11
14
  rescue JSON::ParserError => _e
@@ -0,0 +1,7 @@
1
+ class PigCI::Configuration
2
+ Thresholds = Struct.new(:memory, :request_time, :database_request) do
3
+ def initialize(memory: 350, request_time: 250, database_request: 35)
4
+ super(memory, request_time, database_request)
5
+ end
6
+ end
7
+ end
data/lib/pig_ci/report.rb CHANGED
@@ -15,6 +15,20 @@ class PigCI::Report
15
15
  I18n.t('.name', scope: i18n_scope, locale: PigCI.locale)
16
16
  end
17
17
 
18
+ def max_for(timestamp)
19
+ sorted_and_formatted_data_for(timestamp).collect { |row| row[:max] }.max
20
+ end
21
+
22
+ def threshold
23
+ PigCI.thresholds.dig(@i18n_key.to_sym)
24
+ end
25
+
26
+ def over_threshold_for?(timestamp)
27
+ return false unless threshold.present? && max_for(timestamp).present?
28
+
29
+ max_for(timestamp) > threshold
30
+ end
31
+
18
32
  def sorted_and_formatted_data_for(timestamp)
19
33
  data_for(timestamp)[@i18n_key.to_sym].sort_by do |data|
20
34
  PigCI.report_row_sort_by(data)
@@ -1,4 +1,5 @@
1
1
  class PigCI::Summary; end
2
2
 
3
+ require 'pig_ci/summary/ci'
3
4
  require 'pig_ci/summary/html'
4
5
  require 'pig_ci/summary/terminal'
@@ -0,0 +1,43 @@
1
+ require 'colorized_string'
2
+
3
+ class PigCI::Summary::CI < PigCI::Summary
4
+ def initialize(reports:)
5
+ @reports = reports
6
+ @timestamp = PigCI.run_timestamp
7
+ end
8
+
9
+ def call!
10
+ puts ''
11
+ puts I18n.t('pig_ci.summary.ci_start')
12
+
13
+ over_threshold = false
14
+ @reports.each do |report|
15
+ print_report(report)
16
+ over_threshold = true if report.over_threshold_for?(@timestamp)
17
+ end
18
+
19
+ fail_with_error! if over_threshold
20
+ puts ''
21
+ end
22
+
23
+ private
24
+
25
+ def fail_with_error!
26
+ puts I18n.t('pig_ci.summary.ci_failure')
27
+ Kernel.exit(2)
28
+ end
29
+
30
+ def print_report(report)
31
+ max_and_threshold = [
32
+ report.max_for(@timestamp).to_s,
33
+ '/',
34
+ report.threshold
35
+ ].join(' ')
36
+
37
+ if report.over_threshold_for?(@timestamp)
38
+ puts "#{report.i18n_name}: #{ColorizedString[max_and_threshold].colorize(:red)}\n"
39
+ else
40
+ puts "#{report.i18n_name}: #{ColorizedString[max_and_threshold].colorize(:green)}\n"
41
+ end
42
+ end
43
+ end
@@ -1,3 +1,3 @@
1
1
  module PigCI
2
- VERSION = '0.1.5'.freeze
2
+ VERSION = '0.2.0'.freeze
3
3
  end
data/pig_ci.gemspec CHANGED
@@ -13,15 +13,6 @@ Gem::Specification.new do |spec|
13
13
  spec.homepage = 'https://github.com/PigCI/pig-ci-rails'
14
14
  spec.license = 'MIT'
15
15
 
16
- # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
- # to allow pushing to a single host or delete this section to allow pushing to any host.
18
- if spec.respond_to?(:metadata)
19
- spec.metadata['allowed_push_host'] = 'https://rubygems.org'
20
- else
21
- raise 'RubyGems 2.0 or newer is required to protect against ' \
22
- 'public gem pushes.'
23
- end
24
-
25
16
  # Specify which files should be added to the gem when it is released.
26
17
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
27
18
  spec.files = Dir.chdir(File.expand_path(__dir__)) do
@@ -39,10 +30,18 @@ Gem::Specification.new do |spec|
39
30
  spec.add_dependency 'terminal-table', '~> 1.8.0'
40
31
 
41
32
  spec.add_development_dependency 'bundler', '~> 2.0'
42
- spec.add_development_dependency 'rake', '~> 12.3'
43
- spec.add_development_dependency 'webmock', '~> 3.7.0'
33
+ spec.add_development_dependency 'rake', '~> 13.0'
34
+ spec.add_development_dependency 'webmock', '~> 3.8.0'
44
35
 
45
36
  spec.add_development_dependency 'json-schema', '~> 2.8.1'
46
- spec.add_development_dependency 'rspec', '~> 3.8.0'
37
+ spec.add_development_dependency 'rspec', '~> 3.9.0'
47
38
  spec.add_development_dependency 'simplecov', '~> 0.17.0'
39
+ spec.add_development_dependency 'yard', '~> 0.9.24'
40
+
41
+ spec.post_install_message = [
42
+ 'Thank you for install Pig CI!',
43
+ 'Upgrade Notes:',
44
+ 'The latest version adds a "config.thresholds" option which will replace the pigci.com integration in future.',
45
+ 'See https://github.com/PigCI/pig-ci-rails#configuring-thresholds for more information :)'
46
+ ].join("\n")
48
47
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pig-ci-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Rogers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-09-23 00:00:00.000000000 Z
11
+ date: 2020-03-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -134,28 +134,28 @@ dependencies:
134
134
  requirements:
135
135
  - - "~>"
136
136
  - !ruby/object:Gem::Version
137
- version: '12.3'
137
+ version: '13.0'
138
138
  type: :development
139
139
  prerelease: false
140
140
  version_requirements: !ruby/object:Gem::Requirement
141
141
  requirements:
142
142
  - - "~>"
143
143
  - !ruby/object:Gem::Version
144
- version: '12.3'
144
+ version: '13.0'
145
145
  - !ruby/object:Gem::Dependency
146
146
  name: webmock
147
147
  requirement: !ruby/object:Gem::Requirement
148
148
  requirements:
149
149
  - - "~>"
150
150
  - !ruby/object:Gem::Version
151
- version: 3.7.0
151
+ version: 3.8.0
152
152
  type: :development
153
153
  prerelease: false
154
154
  version_requirements: !ruby/object:Gem::Requirement
155
155
  requirements:
156
156
  - - "~>"
157
157
  - !ruby/object:Gem::Version
158
- version: 3.7.0
158
+ version: 3.8.0
159
159
  - !ruby/object:Gem::Dependency
160
160
  name: json-schema
161
161
  requirement: !ruby/object:Gem::Requirement
@@ -176,14 +176,14 @@ dependencies:
176
176
  requirements:
177
177
  - - "~>"
178
178
  - !ruby/object:Gem::Version
179
- version: 3.8.0
179
+ version: 3.9.0
180
180
  type: :development
181
181
  prerelease: false
182
182
  version_requirements: !ruby/object:Gem::Requirement
183
183
  requirements:
184
184
  - - "~>"
185
185
  - !ruby/object:Gem::Version
186
- version: 3.8.0
186
+ version: 3.9.0
187
187
  - !ruby/object:Gem::Dependency
188
188
  name: simplecov
189
189
  requirement: !ruby/object:Gem::Requirement
@@ -198,6 +198,20 @@ dependencies:
198
198
  - - "~>"
199
199
  - !ruby/object:Gem::Version
200
200
  version: 0.17.0
201
+ - !ruby/object:Gem::Dependency
202
+ name: yard
203
+ requirement: !ruby/object:Gem::Requirement
204
+ requirements:
205
+ - - "~>"
206
+ - !ruby/object:Gem::Version
207
+ version: 0.9.24
208
+ type: :development
209
+ prerelease: false
210
+ version_requirements: !ruby/object:Gem::Requirement
211
+ requirements:
212
+ - - "~>"
213
+ - !ruby/object:Gem::Version
214
+ version: 0.9.24
201
215
  description: A gem for Ruby on Rails that will report key metrics (memory, request
202
216
  time & SQL Requests) for request & feature tests.
203
217
  email:
@@ -207,8 +221,10 @@ extensions: []
207
221
  extra_rdoc_files: []
208
222
  files:
209
223
  - ".github/FUNDING.yml"
224
+ - ".github/workflows/gempush.yml"
210
225
  - ".gitignore"
211
226
  - ".rubocop.yml"
227
+ - ".ruby-version"
212
228
  - ".travis.yml"
213
229
  - CHANGELOG.md
214
230
  - CODE_OF_CONDUCT.md
@@ -222,6 +238,7 @@ files:
222
238
  - lib/pig_ci.rb
223
239
  - lib/pig_ci/api.rb
224
240
  - lib/pig_ci/api/reports.rb
241
+ - lib/pig_ci/configuration.rb
225
242
  - lib/pig_ci/decorator.rb
226
243
  - lib/pig_ci/decorator/report_terminal_decorator.rb
227
244
  - lib/pig_ci/metric.rb
@@ -239,6 +256,7 @@ files:
239
256
  - lib/pig_ci/report/memory.rb
240
257
  - lib/pig_ci/report/request_time.rb
241
258
  - lib/pig_ci/summary.rb
259
+ - lib/pig_ci/summary/ci.rb
242
260
  - lib/pig_ci/summary/html.rb
243
261
  - lib/pig_ci/summary/terminal.rb
244
262
  - lib/pig_ci/version.rb
@@ -250,9 +268,12 @@ files:
250
268
  homepage: https://github.com/PigCI/pig-ci-rails
251
269
  licenses:
252
270
  - MIT
253
- metadata:
254
- allowed_push_host: https://rubygems.org
255
- post_install_message:
271
+ metadata: {}
272
+ post_install_message: |-
273
+ Thank you for install Pig CI!
274
+ Upgrade Notes:
275
+ The latest version adds a "config.thresholds" option which will replace the pigci.com integration in future.
276
+ See https://github.com/PigCI/pig-ci-rails#configuring-thresholds for more information :)
256
277
  rdoc_options: []
257
278
  require_paths:
258
279
  - lib