Module: PigCI

Extended by:
PigCI
Included in:
PigCI
Defined in:
lib/pig_ci.rb,
lib/pig_ci/version.rb

Defined Under Namespace

Modules: TestFrameworks Classes: Configuration, Decorator, Metric, Profiler, ProfilerEngine, Report, Summary

Constant Summary collapse

VERSION =
"1.1.0".freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#commit_sha1Object



104
105
106
# File 'lib/pig_ci.rb', line 104

def commit_sha1
  @commit_sha1 || ENV["CI_COMMIT_ID"] || ENV["CIRCLE_SHA1"] || ENV["TRAVIS_COMMIT"] || `git rev-parse HEAD`.strip
end

#during_setup_eager_load_application=(value) ⇒ Object (writeonly)

Sets the attribute during_setup_eager_load_application

Parameters:

  • value

    the value to set the attribute during_setup_eager_load_application to.



62
63
64
# File 'lib/pig_ci.rb', line 62

def during_setup_eager_load_application=(value)
  @during_setup_eager_load_application = value
end

#during_setup_make_blank_application_request=(value) ⇒ Object (writeonly)

Sets the attribute during_setup_make_blank_application_request

Parameters:

  • value

    the value to set the attribute during_setup_make_blank_application_request to.



67
68
69
# File 'lib/pig_ci.rb', line 67

def during_setup_make_blank_application_request=(value)
  @during_setup_make_blank_application_request = value
end

#during_setup_precompile_assets=(value) ⇒ Object (writeonly)

Sets the attribute during_setup_precompile_assets

Parameters:

  • value

    the value to set the attribute during_setup_precompile_assets to.



72
73
74
# File 'lib/pig_ci.rb', line 72

def during_setup_precompile_assets=(value)
  @during_setup_precompile_assets = value
end

#enabled=(value) ⇒ Object (writeonly)

Sets the attribute enabled

Parameters:

  • value

    the value to set the attribute enabled to.



20
21
22
# File 'lib/pig_ci.rb', line 20

def enabled=(value)
  @enabled = value
end

#generate_html_summaryObject

Returns the value of attribute generate_html_summary.



47
48
49
# File 'lib/pig_ci.rb', line 47

def generate_html_summary
  @generate_html_summary
end

#generate_terminal_summaryObject

Returns the value of attribute generate_terminal_summary.



42
43
44
# File 'lib/pig_ci.rb', line 42

def generate_terminal_summary
  @generate_terminal_summary
end

#head_branchObject



109
110
111
# File 'lib/pig_ci.rb', line 109

def head_branch
  @head_branch || ENV["CI_BRANCH"] || ENV["CIRCLE_BRANCH"] || ENV["TRAVIS_BRANCH"] || `git rev-parse --abbrev-ref HEAD`.strip
end

#historical_data_run_limitObject



89
90
91
# File 'lib/pig_ci.rb', line 89

def historical_data_run_limit
  @historical_data_run_limit ||= 10
end

#ignore_cached_queries=(value) ⇒ Object (writeonly)

Rails caches repeated queries within the same request. You can not count any cached queries if you’d like.



27
28
29
# File 'lib/pig_ci.rb', line 27

def ignore_cached_queries=(value)
  @ignore_cached_queries = value
end

#localeObject



119
120
121
# File 'lib/pig_ci.rb', line 119

def locale
  @locale || :en
end

#max_change_percentage_precisionObject



53
54
55
# File 'lib/pig_ci.rb', line 53

def max_change_percentage_precision
  @max_change_percentage_precision || 1
end

#output_directoryObject



38
39
40
# File 'lib/pig_ci.rb', line 38

def output_directory
  @output_directory || Pathname.new(Dir.getwd).join("pig-ci")
end

#pidObject

Returns the value of attribute pid.



18
19
20
# File 'lib/pig_ci.rb', line 18

def pid
  @pid
end

#profiler_engineObject



99
100
101
# File 'lib/pig_ci.rb', line 99

def profiler_engine
  @profiler_engine ||= PigCI::ProfilerEngine::Rails.new
end

#report_memory_precisionObject



58
59
60
# File 'lib/pig_ci.rb', line 58

def report_memory_precision
  @report_memory_precision || 2
end

#report_row_sort_by(data) ⇒ Object



84
85
86
# File 'lib/pig_ci.rb', line 84

def report_row_sort_by(data)
  (@report_row_sort_by || proc { |d| d[:max].to_i * -1 }).call(data)
end

#run_timestampObject



94
95
96
# File 'lib/pig_ci.rb', line 94

def run_timestamp
  @run_timestamp ||= Time.now.to_i.to_s
end

#terminal_report_row_limitObject



78
79
80
# File 'lib/pig_ci.rb', line 78

def terminal_report_row_limit
  @terminal_report_row_limit || -1
end

#tmp_directoryObject



33
34
35
# File 'lib/pig_ci.rb', line 33

def tmp_directory
  @tmp_directory || Pathname.new(Dir.getwd).join("tmp", "pig-ci")
end

Class Method Details

.load_i18ns!Object



150
151
152
153
# File 'lib/pig_ci.rb', line 150

def load_i18ns!
  I18n.available_locales << PigCI.locale
  I18n.load_path += Dir["#{File.expand_path("../config/locales/pig_ci", __dir__)}/*.{rb,yml}"]
end

.run_exit_tasks!Object



155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'lib/pig_ci.rb', line 155

def run_exit_tasks!
  return if PigCI.pid != Process.pid || !PigCI.profiler_engine.request_captured?

  # Save all the reports as JSON
  profiler_engine.profilers.each(&:save!)

  # Print the report summary to Terminal
  PigCI::Summary::Terminal.new(reports: profiler_engine.reports).print! if PigCI.generate_terminal_summary?

  # Save the report summary to the project root.
  PigCI::Summary::HTML.new(reports: profiler_engine.reports).save! if PigCI.generate_html_summary?

  # Make sure CI fails when metrics are over thresholds.
  PigCI::Summary::CI.new(reports: profiler_engine.reports).call!
end

.start(&block) ⇒ Object



133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/pig_ci.rb', line 133

def start(&block)
  self.pid = Process.pid
  PigCI::TestFrameworks::Rspec.configure! if defined?(::RSpec)

  block&.call(self)

  # Add our translations
  load_i18ns!

  # Make sure our directories exist
  Dir.mkdir(tmp_directory) unless File.exist?(tmp_directory)
  Dir.mkdir(output_directory) unless File.exist?(output_directory)

  # Purge any previous logs and attach some listeners
  profiler_engine.setup!
end

Instance Method Details

#api_key=(value) ⇒ Object

Throw deprecation notice for setting API



114
115
116
# File 'lib/pig_ci.rb', line 114

def api_key=(value)
  puts "DEPRECATED: PigCI.com API has been retired, you no longer need to set config.api_key in your spec/rails_helper.rb file."
end

#during_setup_eager_load_application?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/pig_ci.rb', line 63

def during_setup_eager_load_application?
  @during_setup_eager_load_application.nil? || @during_setup_eager_load_application
end

#during_setup_make_blank_application_request?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/pig_ci.rb', line 68

def during_setup_make_blank_application_request?
  @during_setup_make_blank_application_request.nil? || @during_setup_make_blank_application_request
end

#during_setup_precompile_assets?Boolean

Returns:

  • (Boolean)


73
74
75
# File 'lib/pig_ci.rb', line 73

def during_setup_precompile_assets?
  @during_setup_precompile_assets.nil? || @during_setup_precompile_assets
end

#enabled?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/pig_ci.rb', line 21

def enabled?
  @enabled.nil? ? true : @enabled
end

#generate_html_summary?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/pig_ci.rb', line 48

def generate_html_summary?
  @generate_html_summary.nil? || @generate_html_summary
end

#generate_terminal_summary?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/pig_ci.rb', line 43

def generate_terminal_summary?
  @generate_terminal_summary.nil? || @generate_terminal_summary
end

#ignore_cached_queries?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/pig_ci.rb', line 28

def ignore_cached_queries?
  @ignore_cached_queries.nil? ? false : @ignore_cached_queries
end

#thresholdsObject



127
128
129
# File 'lib/pig_ci.rb', line 127

def thresholds
  @thresholds ||= PigCI::Configuration::Thresholds.new
end

#thresholds=(values) ⇒ Object



123
124
125
# File 'lib/pig_ci.rb', line 123

def thresholds=(values)
  @thresholds = PigCI::Configuration::Thresholds.new(values)
end