deprecation_toolkit 1.2.2 → 1.3.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: ddd5dffb6bef31488bd68ff821e1f5972393faf9a662822846b6329ed6224d22
4
- data.tar.gz: 01d152d7fac7479039f518c38f1bbd7dae49aaa090c62a0cd42d99b99c800484
3
+ metadata.gz: c2aa284de572854194d47e8fb3a0928f6004e657c957fc3818a646f7f87baa2e
4
+ data.tar.gz: 80c06869204811d135e0ca7933aad4d29d58c297d78c586aef170f35400fe809
5
5
  SHA512:
6
- metadata.gz: 7834446b68db25c28bc19f17cefead446cd390846af1cdde3bb8183a5eda53c87ea95fc1abcdf71b080486d80b0c9c5497986061146f81752742e2c4fc5e6e8f
7
- data.tar.gz: 6307da3564c55fa2879fd99b610bd923eaf5247abd33bb39ec96c974f9c4cf7f8f5fa2e8392b493735950ff7f0afde18110036844b326971ea2f8ed674cb7dc1
6
+ metadata.gz: f6919678301384aee34d895fc914b044af7729261ebeb0c1cf50b50eb3bc2c8cb696225fc24a6a74eccc525394b89d0b3f2e6f250862f58d4c8cc775e88a635f
7
+ data.tar.gz: ce5328b98b756eb6c19f163e58333cfd1a3f3ed286d34cf5bb9dbdabf97a00f0678b7663e8c7825811ee28b0f51f27eed78da7cf66496d41cda257d93101f23c
data/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## master (unreleased)
4
4
 
5
+ ## 1.3.0 (2019-02-28)
6
+ * [#38](https://github.com/Shopify/deprecation_toolkit/pull/38): Add a way to mark test as flaky. (@Edouard-chin)
7
+ * [#39](https://github.com/Shopify/deprecation_toolkit/pull/39): Introduced a way to help recording massive amount of deprecations. (@Edouard-chin)
8
+
5
9
  ## 1.2.1 (2019-01-09)
6
10
 
7
11
  ### Bug fixes
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- deprecation_toolkit (1.2.2)
4
+ deprecation_toolkit (1.3.0)
5
5
  activesupport (>= 4.2)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -52,6 +52,7 @@ This gem provides 3 behaviors, the default one being `DeprecationToolkit::Behavi
52
52
  - `DeprecationToolkit::DeprecationIntroduced` error if a new deprecation is introduced.
53
53
  - `DeprecationToolkit::DeprecationRemoved` error if a deprecation was removed (compare to the one recorded in the shitlist).
54
54
  * `DeprecationToolkit::Behaviors::Record` will record deprecations.
55
+ * `DeprecationToolkit::Behaviors::CIRecordHelper` See separated explanation below.
55
56
  * `DeprecationToolkit::Behaviors::Disabled` will do nothing.
56
57
  - This is useful if you want to disable this gem for a moment without removing the gem from your Gemfile.
57
58
 
@@ -71,6 +72,15 @@ end
71
72
  DeprecationToolkit::Configuration.behavior = StatsdBehavior
72
73
  ```
73
74
 
75
+ ##### DeprecationToolkit::Behaviors::CIRecordHelper
76
+
77
+ This is a special type of behaviour meant to help you record deprecations if you have a lof of them.
78
+ Imagine if you have thousands of tests and need to record deprecations for each on your machine, this is going to take ages.
79
+ Recording deprecations on CI with the regular `Record` behavior isn't possible because of the way CI parallelize test in multiple container (Multiple tests from the same file runs in parallel in diferrent machines, the deprecation files that get created are then splitted. Regrouping them is a nightmare.)
80
+
81
+ This behaviour will output a JSON representation of your deprecations. Your CI should have a way to download the log generated from the test run. Download it on your locale machine. Finally run the rake task `FILEPATH=<path_to_downloaded_log> deprecation_toolkit:record_from_ci_output`.
82
+ This task will parse your CI log and grab the output generated by the DeprecationToolkit and will finally convert everything back to YML files.
83
+
74
84
  ### 🔨 `#DeprecationToolkit::Configuration#allowed_deprecations`
75
85
 
76
86
  You can ignore some deprecations using `allowed_deprecations`. `allowed_deprecations` accepts an array of Regexp and Procs.
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ load('tasks/ci_recorder.rake')
4
+
3
5
  module DeprecationToolkit
4
6
  autoload :DeprecationSubscriber, "deprecation_toolkit/deprecation_subscriber"
5
7
  autoload :Configuration, "deprecation_toolkit/configuration"
@@ -10,6 +12,7 @@ module DeprecationToolkit
10
12
  autoload :Disabled, "deprecation_toolkit/behaviors/disabled"
11
13
  autoload :Raise, "deprecation_toolkit/behaviors/raise"
12
14
  autoload :Record, "deprecation_toolkit/behaviors/record"
15
+ autoload :CIRecordHelper, "deprecation_toolkit/behaviors/ci_record_helper"
13
16
  end
14
17
 
15
18
  def self.add_notify_behavior
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+
5
+ module DeprecationToolkit
6
+ module Behaviors
7
+ class CIRecordHelper
8
+ extend ReadWriteHelper
9
+
10
+ HEADER = '[DeprecationToolkit]'
11
+
12
+ def self.trigger(test, current_deprecations, _recorded_deprecations)
13
+ filename = recorded_deprecations_path(test)
14
+
15
+ to_output = {
16
+ filename.to_s => {
17
+ test.name => current_deprecations.deprecations_without_stacktrace,
18
+ },
19
+ }
20
+
21
+ raise "#{HEADER} #{JSON.dump(to_output)}"
22
+ end
23
+ end
24
+ end
25
+ end
@@ -6,7 +6,9 @@ module DeprecationToolkit
6
6
  extend ReadWriteHelper
7
7
 
8
8
  def self.trigger(test, collector, _)
9
- write(test, collector.deprecations_without_stacktrace)
9
+ deprecation_file = recorded_deprecations_path(test)
10
+
11
+ write(deprecation_file, test.name => collector.deprecations_without_stacktrace)
10
12
  end
11
13
  end
12
14
  end
@@ -59,5 +59,9 @@ module DeprecationToolkit
59
59
 
60
60
  difference
61
61
  end
62
+
63
+ def flaky?
64
+ size == 1 && deprecations.first['flaky'] == true
65
+ end
62
66
  end
63
67
  end
@@ -7,7 +7,7 @@ module DeprecationToolkit
7
7
  def trigger_deprecation_toolkit_behavior
8
8
  current_deprecations = Collector.new(Collector.deprecations)
9
9
  recorded_deprecations = Collector.load(self)
10
- if current_deprecations != recorded_deprecations
10
+ if !recorded_deprecations.flaky? && current_deprecations != recorded_deprecations
11
11
  Configuration.behavior.trigger(self, current_deprecations, recorded_deprecations)
12
12
  end
13
13
  ensure
@@ -7,21 +7,22 @@ require "yaml"
7
7
  module DeprecationToolkit
8
8
  module ReadWriteHelper
9
9
  def read(test)
10
- deprecation_file = recorded_deprecations_path(test)
10
+ deprecation_file = Bundler.root.join(recorded_deprecations_path(test))
11
11
  YAML.load(deprecation_file.read).fetch(test.name, [])
12
12
  rescue Errno::ENOENT
13
13
  []
14
14
  end
15
15
 
16
- def write(test, deprecations)
17
- deprecation_file = recorded_deprecations_path(test)
16
+ def write(deprecation_file, deprecations_to_record)
18
17
  create_deprecation_file(deprecation_file) unless deprecation_file.exist?
19
18
 
20
19
  content = YAML.load_file(deprecation_file)
21
- if deprecations.any?
22
- content[test.name] = deprecations
23
- else
24
- content.delete(test.name)
20
+ deprecations_to_record.each do |test_name, deprecations|
21
+ if deprecations.any?
22
+ content[test_name] = deprecations
23
+ else
24
+ content.delete(test_name)
25
+ end
25
26
  end
26
27
 
27
28
  if content.any?
@@ -45,7 +46,7 @@ module DeprecationToolkit
45
46
  Configuration.deprecation_path
46
47
  end
47
48
 
48
- Bundler.root.join(deprecation_folder, "#{test.class.name.underscore}.yml")
49
+ Pathname(deprecation_folder).join("#{test.class.name.underscore}.yml")
49
50
  end
50
51
 
51
52
  def test_location(test)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DeprecationToolkit
4
- VERSION = "1.2.2"
4
+ VERSION = "1.3.0"
5
5
  end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'tempfile'
4
+ require 'json'
5
+ require 'active_support/core_ext/hash'
6
+ require 'rake'
7
+ require_relative '../deprecation_toolkit/read_write_helper'
8
+
9
+ class CIRecorder
10
+ include Rake::DSL
11
+ include DeprecationToolkit::ReadWriteHelper
12
+
13
+ def initialize
14
+ namespace :deprecation_toolkit do
15
+ desc 'Parse a file generated with the CIOutputHelper and generate deprecations out of it'
16
+ task :record_from_ci_output do
17
+ raw_file = ENV.fetch('FILEPATH')
18
+
19
+ deprecations = extract_deprecations_output(raw_file) do |file|
20
+ parse_file(file)
21
+ end
22
+
23
+ generate_deprecations_file(deprecations)
24
+ end
25
+ end
26
+ end
27
+
28
+ private
29
+
30
+ def extract_deprecations_output(file)
31
+ tmp_file = Tempfile.new
32
+ shell_command = "cat #{file} | sed -n -e 's/^.* \\[DeprecationToolkit\\] \\(.*\\)/\\1/p' > #{tmp_file.path}"
33
+
34
+ raise "Couldn't extract deprecations from output" unless system(shell_command)
35
+ yield(tmp_file)
36
+ ensure
37
+ tmp_file.delete
38
+ end
39
+
40
+ def parse_file(file)
41
+ file.each.with_object({}) do |line, hash|
42
+ hash.deep_merge!(JSON.parse(line))
43
+ end
44
+ end
45
+
46
+ def generate_deprecations_file(deprecations_to_record)
47
+ deprecations_to_record.each do |filename, deprecations|
48
+ write(Pathname(filename), deprecations)
49
+ end
50
+ end
51
+ end
52
+
53
+ CIRecorder.new
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deprecation_toolkit
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.2
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shopify
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-01-22 00:00:00.000000000 Z
11
+ date: 2019-02-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -90,6 +90,7 @@ files:
90
90
  - gemfiles/activesupport_5.2.gemfile
91
91
  - gemfiles/test/deprecations
92
92
  - lib/deprecation_toolkit.rb
93
+ - lib/deprecation_toolkit/behaviors/ci_record_helper.rb
93
94
  - lib/deprecation_toolkit/behaviors/disabled.rb
94
95
  - lib/deprecation_toolkit/behaviors/raise.rb
95
96
  - lib/deprecation_toolkit/behaviors/record.rb
@@ -101,6 +102,7 @@ files:
101
102
  - lib/deprecation_toolkit/version.rb
102
103
  - lib/deprecation_toolkit/warning.rb
103
104
  - lib/minitest/deprecation_toolkit_plugin.rb
105
+ - lib/tasks/ci_recorder.rake
104
106
  - shipit.rubygems.yml
105
107
  homepage: https://github.com/shopify/deprecation_toolkit
106
108
  licenses: