affected_tests 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 +4 -4
- data/Gemfile.lock +2 -2
- data/README.md +30 -1
- data/lib/affected_tests/map_merger.rb +41 -0
- data/lib/affected_tests/version.rb +1 -1
- data/lib/affected_tests.rb +11 -6
- data/scripts/generate-diff-files-from-github +17 -5
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dcc672116e5bb9b0e2da893b7210c77f11e5b95e3c64fc4c217edb1f06f2e7d2
|
4
|
+
data.tar.gz: 1f03fe6932d5f970ee5606501412f30cc397163e86b3a543fe1e95c2d04c3dbd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2f92a2f7dd2d2f322d27ca90ebeeaffb18d765145d51efcd6b2df571dd95ffe6a67ba27b3a16e25736853cc148f07f3d064fee1b28f843cbfe43150872757d8e
|
7
|
+
data.tar.gz: ac127737a5b1555e35d18eb3ce9b0cde6adfd679b8bb852482934296e0ec371ed9f14027c1614af98e436f52896c59053094be5b6016c296a481f3b45ffd5078
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -29,10 +29,28 @@ require "affected_tests/rspec"
|
|
29
29
|
AffectedTests.setup(
|
30
30
|
project_path: File.expand_path("../../", __FILE__),
|
31
31
|
test_dir_path: "spec/",
|
32
|
-
output_path: "log/affected-tests-map.json"
|
32
|
+
output_path: "log/affected-tests-map.json",
|
33
|
+
revision: "1cf22fdb86e2b2d6107" # or git rev-parse HEAD > REVISION
|
33
34
|
)
|
34
35
|
```
|
35
36
|
|
37
|
+
this will write associated test files per file on `log/affected-tests-map.json`:
|
38
|
+
|
39
|
+
```json
|
40
|
+
{
|
41
|
+
"revision": "1cf22fdb86e2b2d6107",
|
42
|
+
"map": {
|
43
|
+
"app/controllers/comments_controller.rb": [
|
44
|
+
"spec/requests/comments_spec.rb"
|
45
|
+
],
|
46
|
+
"app/views/comments/index.html.erb": [
|
47
|
+
"spec/requests/comments_spec.rb",
|
48
|
+
"spec/views/comments/index.html.erb_spec.rb"
|
49
|
+
]
|
50
|
+
}
|
51
|
+
}
|
52
|
+
```
|
53
|
+
|
36
54
|
### Get Diff
|
37
55
|
|
38
56
|
#### Schema
|
@@ -76,6 +94,17 @@ pp target_tests
|
|
76
94
|
|
77
95
|
See also: `scripts/calculate-target-tests`
|
78
96
|
|
97
|
+
#### Merge results from parallel test
|
98
|
+
|
99
|
+
```
|
100
|
+
require "affected_tests/map_merger"
|
101
|
+
|
102
|
+
AffectedTests::MapMerger.run(
|
103
|
+
map_file_paths: %w[node1-result.json node2-result.json node3-result.json],
|
104
|
+
output_path: "merged-result.json"
|
105
|
+
)
|
106
|
+
```
|
107
|
+
|
79
108
|
## Development
|
80
109
|
|
81
110
|
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "json"
|
4
|
+
require "set"
|
5
|
+
|
6
|
+
module AffectedTests
|
7
|
+
module MapMerger
|
8
|
+
module_function
|
9
|
+
|
10
|
+
def run(map_file_paths:, output_path:)
|
11
|
+
map_infos = map_file_paths.map do |map_file_path|
|
12
|
+
JSON.parse(File.read(map_file_path))
|
13
|
+
end
|
14
|
+
|
15
|
+
revisions = map_infos.map { |map_info| map_info["revision"] }.uniq
|
16
|
+
raise "map files weren't generated by same revision" if revisions.size != 1
|
17
|
+
|
18
|
+
keys = map_infos.flat_map { |map_info| map_info["map"].keys }.uniq
|
19
|
+
|
20
|
+
result_map = {}
|
21
|
+
keys.each do |key|
|
22
|
+
map_infos.each do |map_info|
|
23
|
+
map = map_info["map"]
|
24
|
+
next if map[key].nil?
|
25
|
+
|
26
|
+
result_map[key] ||= Set.new
|
27
|
+
map[key].each do |test_file_path|
|
28
|
+
result_map[key] << test_file_path
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
result = {
|
34
|
+
revision: revisions.first,
|
35
|
+
map: result_map.transform_values(&:to_a)
|
36
|
+
}
|
37
|
+
|
38
|
+
File.write(output_path, JSON.dump(result))
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/lib/affected_tests.rb
CHANGED
@@ -10,10 +10,11 @@ require_relative "affected_tests/version"
|
|
10
10
|
module AffectedTests
|
11
11
|
module_function
|
12
12
|
|
13
|
-
def setup(project_path:, test_dir_path:, output_path:)
|
13
|
+
def setup(project_path:, test_dir_path:, output_path:, revision: nil)
|
14
14
|
@project_path = project_path
|
15
15
|
@test_dir_path = test_dir_path
|
16
16
|
@output_path = output_path
|
17
|
+
@revision = revision
|
17
18
|
@rotoscope = Rotoscope.new do |call|
|
18
19
|
next if self == call.receiver
|
19
20
|
|
@@ -54,7 +55,7 @@ module AffectedTests
|
|
54
55
|
end
|
55
56
|
|
56
57
|
def dump
|
57
|
-
data = { revision: revision, map: cache.transform_values(&:to_a) }
|
58
|
+
data = { revision: @revision || build_revision, map: cache.transform_values(&:to_a) }
|
58
59
|
File.write(@output_path, JSON.dump(data))
|
59
60
|
ensure
|
60
61
|
@rotoscope.stop_trace if @rotoscope.tracing?
|
@@ -73,10 +74,14 @@ module AffectedTests
|
|
73
74
|
cache[callee].add(caller)
|
74
75
|
end
|
75
76
|
|
76
|
-
def
|
77
|
-
|
78
|
-
|
79
|
-
|
77
|
+
def build_revision
|
78
|
+
if defined? Rails
|
79
|
+
path = Rails.root.join("REVISION")
|
80
|
+
if path.exist?
|
81
|
+
path.read.chomp
|
82
|
+
else
|
83
|
+
"UNKNOWN"
|
84
|
+
end
|
80
85
|
else
|
81
86
|
"UNKNOWN"
|
82
87
|
end
|
@@ -15,11 +15,23 @@ target_sha = ARGV.shift
|
|
15
15
|
|
16
16
|
client = Octokit::Client.new(access_token: ENV["GITHUB_TOKEN"])
|
17
17
|
|
18
|
-
targets = client.compare(repository, base_sha, target_sha).files.
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
18
|
+
targets = client.compare(repository, base_sha, target_sha).files.each_with_object([]) do |info, arr|
|
19
|
+
# https://docs.github.com/en/rest/commits/commits#get-a-commit
|
20
|
+
case info.status
|
21
|
+
when "modified", "added", "removed"
|
22
|
+
arr << { filename: info.filename, status: info.status }
|
23
|
+
when "renamed"
|
24
|
+
arr << { filename: info.filename, status: "added" }
|
25
|
+
arr << { filename: info.previous_filename, status: "removed" }
|
26
|
+
when "copied"
|
27
|
+
arr << { filename: info.filename, status: "added" }
|
28
|
+
when "changed"
|
29
|
+
arr << { filename: info.filename, status: "modified" }
|
30
|
+
when "unchanged"
|
31
|
+
# do nothing
|
32
|
+
else
|
33
|
+
raise "Unknown status: #{info.status}"
|
34
|
+
end
|
23
35
|
end
|
24
36
|
|
25
37
|
puts JSON.dump(targets)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: affected_tests
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shia
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-08-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rotoscope
|
@@ -39,6 +39,7 @@ files:
|
|
39
39
|
- Rakefile
|
40
40
|
- lib/affected_tests.rb
|
41
41
|
- lib/affected_tests/differ.rb
|
42
|
+
- lib/affected_tests/map_merger.rb
|
42
43
|
- lib/affected_tests/rspec.rb
|
43
44
|
- lib/affected_tests/version.rb
|
44
45
|
- scripts/calculate-target-tests
|