danger-xcprofiler 0.2.0 → 0.5.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
- SHA1:
3
- metadata.gz: 58787f96f3db5f505748ca1532c89bc7686fc084
4
- data.tar.gz: fbe9fd4ef7f9e6e970b2a4ac2e86af6ae8639967
2
+ SHA256:
3
+ metadata.gz: ffb92acc3f723fffe36d95a54d3e39d743c2ac24425e7cf4468992535c353ede
4
+ data.tar.gz: 236ecd6d8f3af89039d22a608b8ce261669e6cfd5dc7f27a0387ef6ce17d1f93
5
5
  SHA512:
6
- metadata.gz: 17e3d2e656fac5bb7ae49c74ac8a51427f71abf96a4cee082c7e1515c40dab02aa284d37bcd6ab85949e652d19d2b8803af09b109f72b2608b7411e0cb2328d3
7
- data.tar.gz: ee1878fb82f7845d4540d3661d199e62f1735b25d0f730e291a2ead922f7f7846e41769777b6e5b9b3f2ef4b9d6710a752b2caac3ac94ad8feed195042279e0b
6
+ metadata.gz: c77695577fb7b5a8c527bada81931274cd86da2d213ce350078ea2b64935711b95e0d2039a0e2bbce5efc087b39e4b998ef991ef7da5de559b812c9bf72f2c3e
7
+ data.tar.gz: 99efe20d66d9ee8a2529f00ef436afe8dd7514b8456c6bd25b20fa9467d263408558c0020a7896402900ae07568b046597cc5c06acb3ae3b9a2f07b0b68c637b
@@ -0,0 +1,37 @@
1
+ # This workflow uses actions that are not certified by GitHub.
2
+ # They are provided by a third-party and are governed by
3
+ # separate terms of service, privacy policy, and support
4
+ # documentation.
5
+ # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
6
+ # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
7
+
8
+ name: Ruby
9
+
10
+ on:
11
+ push:
12
+ branches: [ master ]
13
+ pull_request:
14
+ branches: [ master ]
15
+
16
+ jobs:
17
+ test:
18
+
19
+ runs-on: ubuntu-latest
20
+ strategy:
21
+ matrix:
22
+ ruby-version: ['2.6', '2.7', '3.0']
23
+
24
+ steps:
25
+ - uses: actions/checkout@v2
26
+ - name: Set up Ruby
27
+ # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
28
+ # change this to (see https://github.com/ruby/setup-ruby#versioning):
29
+ # uses: ruby/setup-ruby@v1
30
+ uses: ruby/setup-ruby@473e4d8fe5dd94ee328fdfca9f8c9c7afc9dae5e
31
+ with:
32
+ ruby-version: ${{ matrix.ruby-version }}
33
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
34
+ - name: Run tests
35
+ run: |
36
+ bundle exec rake
37
+ bundle exec rubocop
data/.rubocop.yml CHANGED
@@ -1,3 +1,9 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.6
3
+
4
+ Metrics/ModuleLength:
5
+ Max: 120
6
+
1
7
  Metrics/MethodLength:
2
8
  Enabled: false
3
9
 
@@ -11,4 +17,17 @@ Metrics/BlockLength:
11
17
  Style/Documentation:
12
18
  Enabled: false
13
19
 
20
+ Metrics/AbcSize:
21
+ Max: 25
22
+
23
+ Lint/DuplicateMethods:
24
+ Enabled: false
25
+
26
+ Style/DoubleNegation:
27
+ Enabled: false
28
+
29
+ Style/FrozenStringLiteralComment:
30
+ Enabled: false
14
31
 
32
+ Metrics/CyclomaticComplexity:
33
+ Max: 10
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.0.2
data/README.md CHANGED
@@ -1,6 +1,5 @@
1
1
  # danger-xcprofiler
2
- [![Build Status](https://travis-ci.org/giginet/danger-xcprofiler.svg?branch=master)](https://travis-ci.org/giginet/danger-xcprofiler)
3
- [![Coverage Status](https://coveralls.io/repos/github/giginet/danger-xcprofiler/badge.svg?branch=master)](https://coveralls.io/github/giginet/danger-xcprofiler?branch=master)
2
+ ![GitHub Action](https://github.com/giginet/danger-xcprofiler/actions/workflows/ruby.yml/badge.svg)
4
3
  [![Gem Version](https://badge.fury.io/rb/danger-xcprofiler.svg)](https://badge.fury.io/rb/danger-xcprofiler)
5
4
 
6
5
  [danger](https://github.com/danger/danger) plugin for asserting Swift compilation time.
@@ -25,6 +24,12 @@ Just add this line to your Dangerfile:
25
24
  xcprofiler.report 'MyApp'
26
25
  ```
27
26
 
27
+ Or specify an xcactivitylog path
28
+ ```ruby
29
+ logDir = Dir[File.join('DerivedData/Logs/Build/', '*.xcactivitylog')].first
30
+ xcprofiler.report nil, nil, logDir
31
+ ```
32
+
28
33
  If compilation times of each methods are exceeded the thresholds, `danger` adds inline comment to your PR.
29
34
 
30
35
  Default thresholds is 50ms for warning, 100ms for failure.
@@ -1,8 +1,6 @@
1
- # coding: utf-8
2
-
3
- lib = File.expand_path('../lib', __FILE__)
1
+ lib = File.expand_path('lib', __dir__)
4
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
- require 'xcprofiler/gem_version.rb'
3
+ require 'xcprofiler/gem_version'
6
4
 
7
5
  Gem::Specification.new do |spec|
8
6
  spec.name = 'danger-xcprofiler'
@@ -19,22 +17,21 @@ Gem::Specification.new do |spec|
19
17
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
18
  spec.require_paths = ['lib']
21
19
 
20
+ spec.required_ruby_version = '>= 2.6'
21
+
22
22
  spec.add_dependency 'xcprofiler'
23
23
  spec.add_runtime_dependency 'danger-plugin-api', '~> 1.0'
24
24
 
25
25
  # General ruby development
26
- spec.add_development_dependency 'bundler', '~> 1.3'
27
- spec.add_development_dependency 'rake', '~> 10.0'
26
+ spec.add_development_dependency 'bundler'
27
+ spec.add_development_dependency 'rake'
28
28
 
29
29
  # Testing support
30
- spec.add_development_dependency 'rspec', '~> 3.4'
31
-
32
- # Calculating code coverage
33
- spec.add_development_dependency 'coveralls'
30
+ spec.add_development_dependency 'rspec'
34
31
 
35
32
  # Linting code and docs
36
- spec.add_development_dependency 'rubocop', '~> 0.41'
37
- spec.add_development_dependency 'yard', '~> 0.8'
33
+ spec.add_development_dependency 'rubocop'
34
+ spec.add_development_dependency 'yard'
38
35
 
39
36
  # Makes testing easy via `bundle exec guard`
40
37
  spec.add_development_dependency 'guard', '~> 2.14'
@@ -3,22 +3,33 @@ require 'pathname'
3
3
 
4
4
  module Danger
5
5
  class DangerReporter < Xcprofiler::AbstractReporter
6
- def initialize(dangerfile, thresholds, inline_mode, working_dir)
6
+ def initialize(dangerfile, thresholds, inline_mode, working_dir, ignored_files)
7
7
  super({})
8
8
  @dangerfile = dangerfile
9
9
  @thresholds = thresholds
10
10
  @inline_mode = inline_mode
11
11
  @working_dir = working_dir
12
+ @ignored_files = ignored_files
12
13
  end
13
14
 
14
15
  def report!(executions)
16
+ executions.reject! { |execution| ignored_files.any? { |pattern| File.fnmatch(pattern, execution.path) } }
17
+
18
+ if @inline_mode
19
+ inline_report(executions)
20
+ else
21
+ markdown_report(executions)
22
+ end
23
+ end
24
+
25
+ private
26
+
27
+ def inline_report(executions)
15
28
  executions.each do |execution|
16
29
  options = {}
17
- if @inline_mode
18
- options[:file] = relative_path(execution.path)
19
- options[:line] = execution.line
20
- end
21
- message = message(execution)
30
+ options[:file] = relative_path(execution.path)
31
+ options[:line] = execution.line
32
+ message = "`#{execution.method_name}` takes #{execution.time} ms to build"
22
33
 
23
34
  if execution.time >= @thresholds[:fail]
24
35
  @dangerfile.fail(message, options)
@@ -28,17 +39,42 @@ module Danger
28
39
  end
29
40
  end
30
41
 
31
- private
42
+ def markdown_report(executions)
43
+ warning_executions = executions.select do |e|
44
+ e.time >= @thresholds[:warn] && e.time < @thresholds[:fail]
45
+ end
46
+ error_executions = executions.select do |e|
47
+ e.time >= @thresholds[:fail]
48
+ end
32
49
 
33
- def message(execution)
34
- message = "`#{execution.method_name}` takes #{execution.time} ms to build"
35
- return message if @inline_mode
36
- "[#{execution.filename}] #{message}"
50
+ return if warning_executions.empty? && error_executions.empty?
51
+
52
+ message = "### Xcprofiler found issues\n\n"
53
+ message << markdown_issues(warning_executions, 'Warnings') unless warning_executions.empty?
54
+ message << markdown_issues(error_executions, 'Errors') unless error_executions.empty?
55
+ @dangerfile.markdown(message, {})
37
56
  end
38
57
 
39
58
  def relative_path(path)
40
59
  working_dir = Pathname.new(@working_dir)
41
60
  Pathname.new(path).relative_path_from(working_dir).to_s
42
61
  end
62
+
63
+ def markdown_issues(executions, heading)
64
+ message = "#### #{heading}\n\n"
65
+
66
+ message << "| File | Line | Method Name | Build Time (ms) |\n"
67
+ message << "| ---- | ---- | ----------- | --------------- |\n"
68
+
69
+ executions.each do |e|
70
+ message << "| #{e.filename} | #{e.line} | #{e.method_name} | #{e.time} |\n"
71
+ end
72
+
73
+ message
74
+ end
75
+
76
+ def ignored_files
77
+ [@ignored_files].flatten.compact
78
+ end
43
79
  end
44
80
  end
@@ -1,3 +1,3 @@
1
1
  module DangerXcprofiler
2
- VERSION = '0.2.0'.freeze
2
+ VERSION = '0.5.0'.freeze
3
3
  end
@@ -12,6 +12,10 @@ module Danger
12
12
  # xcprofiler.thresholds = { warn: 100, fail: 500 }
13
13
  # xcprofiler.report 'MyApp'
14
14
  #
15
+ # @example Specify a custom DerivedData directory
16
+ #
17
+ # xcprofiler.report 'MyApp' './DerivedData'
18
+ #
15
19
  # @see giginet/danger-xcprofiler
16
20
  # @tags xcode, ios, danger
17
21
  class DangerXcprofiler < Plugin
@@ -33,13 +37,28 @@ module Danger
33
37
  # @return [Boolean]
34
38
  attr_accessor :inline_mode
35
39
 
40
+ # A globbed string or array of strings which should match the files
41
+ # that you want to ignore warnings on. Defaults to nil.
42
+ # An example would be `'**/Pods/**'` to ignore warnings in Pods that your project uses.
43
+ #
44
+ # @param [String or [String]] value
45
+ # @return [[String]]
46
+ attr_accessor :ignored_files
47
+
36
48
  # Search the latest .xcactivitylog by the passing product_name and profile compilation time
37
49
  # @param [String] product_name Product name for the target project.
50
+ # @param [String] derived_data_path Path to the directory containing the DerivedData.
51
+ # @param [String] log_path Path to the xcactivitylog to process.
38
52
  # @return [void]
39
- def report(product_name)
40
- profiler = Xcprofiler::Profiler.by_product_name(product_name)
53
+ def report(product_name, derived_data_path = nil, log_path = nil)
54
+ profiler = if log_path&.end_with?('.xcactivitylog')
55
+ Xcprofiler::Profiler.by_path(log_path)
56
+ else
57
+ Xcprofiler::Profiler.by_product_name(product_name, derived_data_path)
58
+ end
59
+
41
60
  profiler.reporters = [
42
- DangerReporter.new(@dangerfile, thresholds, inline_mode, working_dir)
61
+ DangerReporter.new(@dangerfile, thresholds, inline_mode, working_dir, ignored_files)
43
62
  ]
44
63
  profiler.report!
45
64
  rescue Xcprofiler::DerivedDataNotFound, Xcprofiler::BuildFlagIsNotEnabled => e
@@ -57,8 +76,9 @@ module Danger
57
76
  end
58
77
 
59
78
  def inline_mode
60
- return false if @inline_mode.nil? == false
61
- true
79
+ return true if @inline_mode.nil?
80
+
81
+ !!@inline_mode
62
82
  end
63
83
  end
64
84
  end
data/spec/spec_helper.rb CHANGED
@@ -1,10 +1,7 @@
1
- require 'coveralls'
2
- Coveralls.wear!
3
-
4
1
  require 'pathname'
5
- ROOT = Pathname.new(File.expand_path('../../', __FILE__))
6
- $LOAD_PATH.unshift((ROOT + 'lib').to_s)
7
- $LOAD_PATH.unshift((ROOT + 'spec').to_s)
2
+ ROOT = Pathname.new(File.expand_path('..', __dir__))
3
+ $LOAD_PATH.unshift("#{ROOT}lib".to_s)
4
+ $LOAD_PATH.unshift("#{ROOT}spec".to_s)
8
5
 
9
6
  require 'bundler/setup'
10
7
  require 'pry'
@@ -1,6 +1,7 @@
1
- require File.expand_path('../spec_helper', __FILE__)
1
+ require File.expand_path('spec_helper', __dir__)
2
2
  require 'xcprofiler'
3
3
 
4
+ # rubocop:disable Metrics/ModuleLength
4
5
  module Danger
5
6
  describe Danger::DangerXcprofiler do
6
7
  it 'should be a plugin' do
@@ -24,7 +25,8 @@ module Danger
24
25
  @xcprofiler.working_dir = ''
25
26
  allow(@dangerfile).to receive(:warn)
26
27
  allow(@dangerfile).to receive(:fail)
27
- allow(Xcprofiler::Profiler).to receive(:by_product_name).with(product_name).and_return(profiler)
28
+ allow(@dangerfile).to receive(:markdown)
29
+ allow(Xcprofiler::Profiler).to receive(:by_product_name).with(product_name, nil).and_return(profiler)
28
30
  allow(derived_data).to receive(:flag_enabled?).and_return(true)
29
31
  allow(derived_data).to receive(:executions).and_return([execution0, execution1])
30
32
  [execution0, execution1].each do |execution|
@@ -33,6 +35,25 @@ module Danger
33
35
  end
34
36
  end
35
37
 
38
+ context 'with ignored files' do
39
+ let(:time0) { 49.9 }
40
+ let(:time1) { 50 }
41
+ it 'skips matching warning' do
42
+ @xcprofiler.ignored_files = ['path/**']
43
+ @xcprofiler.report(product_name)
44
+ expect(@dangerfile).to_not have_received(:warn).with('`doSomething()` takes 50.0 ms to build',
45
+ file: 'path/to/Source.swift',
46
+ line: 20)
47
+ end
48
+ it 'includes non-matching warning' do
49
+ @xcprofiler.ignored_files = ['other/path/**']
50
+ @xcprofiler.report(product_name)
51
+ expect(@dangerfile).to have_received(:warn).with('`doSomething()` takes 50.0 ms to build',
52
+ file: 'path/to/Source.swift',
53
+ line: 20)
54
+ end
55
+ end
56
+
36
57
  context 'with slow execution' do
37
58
  let(:time0) { 49.9 }
38
59
  let(:time1) { 50 }
@@ -92,21 +113,30 @@ module Danger
92
113
  context 'with slow execution' do
93
114
  let(:time0) { 49.9 }
94
115
  let(:time1) { 50 }
116
+ message = "### Xcprofiler found issues\n\n"
117
+ message << "#### Warnings\n\n"
118
+ message << "| File | Line | Method Name | Build Time (ms) |\n"
119
+ message << "| ---- | ---- | ----------- | --------------- |\n"
120
+ message << "| Source.swift | 20 | doSomething() | 50.0 |\n"
95
121
  it 'asserts warning' do
96
122
  @xcprofiler.report(product_name)
97
- expect(@dangerfile).to have_received(:warn)
98
- .with('[Source.swift] `doSomething()` takes 50.0 ms to build', {})
123
+ expect(@dangerfile).to have_received(:markdown).with(message, {})
99
124
  end
100
125
  end
101
126
 
102
127
  context 'with very slow execution' do
128
+ message = "### Xcprofiler found issues\n\n"
129
+ message << "#### Errors\n\n"
130
+ message << "| File | Line | Method Name | Build Time (ms) |\n"
131
+ message << "| ---- | ---- | ----------- | --------------- |\n"
132
+ message << "| Source.swift | 20 | doSomething() | 100.0 |\n"
103
133
  it 'asserts failure' do
104
134
  @xcprofiler.report(product_name)
105
- expect(@dangerfile).to have_received(:fail)
106
- .with('[Source.swift] `doSomething()` takes 100.0 ms to build', {})
135
+ expect(@dangerfile).to have_received(:markdown).with(message, {})
107
136
  end
108
137
  end
109
138
  end
110
139
  end
111
140
  end
112
141
  end
142
+ # rubocop:enable Metrics/ModuleLength
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: danger-xcprofiler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - giginet
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-11 00:00:00.000000000 Z
11
+ date: 2021-11-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: xcprofiler
@@ -42,46 +42,32 @@ dependencies:
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '1.3'
47
+ version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '1.3'
54
+ version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: '10.0'
61
+ version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: '10.0'
68
+ version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - "~>"
74
- - !ruby/object:Gem::Version
75
- version: '3.4'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - "~>"
81
- - !ruby/object:Gem::Version
82
- version: '3.4'
83
- - !ruby/object:Gem::Dependency
84
- name: coveralls
85
71
  requirement: !ruby/object:Gem::Requirement
86
72
  requirements:
87
73
  - - ">="
@@ -98,30 +84,30 @@ dependencies:
98
84
  name: rubocop
99
85
  requirement: !ruby/object:Gem::Requirement
100
86
  requirements:
101
- - - "~>"
87
+ - - ">="
102
88
  - !ruby/object:Gem::Version
103
- version: '0.41'
89
+ version: '0'
104
90
  type: :development
105
91
  prerelease: false
106
92
  version_requirements: !ruby/object:Gem::Requirement
107
93
  requirements:
108
- - - "~>"
94
+ - - ">="
109
95
  - !ruby/object:Gem::Version
110
- version: '0.41'
96
+ version: '0'
111
97
  - !ruby/object:Gem::Dependency
112
98
  name: yard
113
99
  requirement: !ruby/object:Gem::Requirement
114
100
  requirements:
115
- - - "~>"
101
+ - - ">="
116
102
  - !ruby/object:Gem::Version
117
- version: '0.8'
103
+ version: '0'
118
104
  type: :development
119
105
  prerelease: false
120
106
  version_requirements: !ruby/object:Gem::Requirement
121
107
  requirements:
122
- - - "~>"
108
+ - - ">="
123
109
  - !ruby/object:Gem::Version
124
- version: '0.8'
110
+ version: '0'
125
111
  - !ruby/object:Gem::Dependency
126
112
  name: guard
127
113
  requirement: !ruby/object:Gem::Requirement
@@ -185,10 +171,10 @@ executables: []
185
171
  extensions: []
186
172
  extra_rdoc_files: []
187
173
  files:
188
- - ".coveralls.yml"
174
+ - ".github/workflows/ruby.yml"
189
175
  - ".gitignore"
190
176
  - ".rubocop.yml"
191
- - ".travis.yml"
177
+ - ".ruby-version"
192
178
  - Gemfile
193
179
  - Guardfile
194
180
  - LICENSE.txt
@@ -207,7 +193,7 @@ homepage: https://github.com/giginet/danger-xcprofiler
207
193
  licenses:
208
194
  - MIT
209
195
  metadata: {}
210
- post_install_message:
196
+ post_install_message:
211
197
  rdoc_options: []
212
198
  require_paths:
213
199
  - lib
@@ -215,16 +201,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
215
201
  requirements:
216
202
  - - ">="
217
203
  - !ruby/object:Gem::Version
218
- version: '0'
204
+ version: '2.6'
219
205
  required_rubygems_version: !ruby/object:Gem::Requirement
220
206
  requirements:
221
207
  - - ">="
222
208
  - !ruby/object:Gem::Version
223
209
  version: '0'
224
210
  requirements: []
225
- rubyforge_project:
226
- rubygems_version: 2.5.1
227
- signing_key:
211
+ rubygems_version: 3.2.22
212
+ signing_key:
228
213
  specification_version: 4
229
214
  summary: danger plugin for asserting Swift compilation time.
230
215
  test_files:
data/.coveralls.yml DELETED
@@ -1 +0,0 @@
1
- service_name: travis-ci
data/.travis.yml DELETED
@@ -1,12 +0,0 @@
1
- language: ruby
2
- cache:
3
- directories:
4
- - bundle
5
-
6
- rvm:
7
- - 2.0
8
- - 2.1.3
9
- - 2.3.1
10
-
11
- script:
12
- - bundle exec rake spec