forked from hyperdevs-team/mini-swift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDangerFile
59 lines (48 loc) · 1.93 KB
/
DangerFile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
require 'xcodeproj'
# FUNCTION HELPERS
def read_platform_from_testreport_file(path:)
path.dirname.to_s.split('/')[-2]
end
#FILE HELPERS
gitfiles = (git.modified_files + git.added_files).uniq
output_dir = "./output"
build_results = []
test_reports = []
if File.directory?(output_dir)
Find.find(output_dir) do |path|
build_results << path if path =~ /.*\.xcresult$/
test_reports << path if path =~ /.*report.junit$/
end
else
fail "The #{output_dir} dir is empty, usually this means that no flavor has been compiled"
end
# CHECK REPORTS:
fail "Not all targets could be compiled. Check if any flavor dont build. (We have #{build_results.length} builds)" unless build_results.length == 3
#BASIC CHECKS:
warn 'Big PR, try to keep changes smaller if you can 😜' if git.lines_of_code > 500
fail 'This PR does not have any assignees yet.' unless github.pr_json["assignee"]
#BUILD PARSE:
build_results.each do |path|
path = Pathname(path)
xcode_summary.report path.to_s
end
test_reports.each do |path|
path = Pathname(path)
test_report_name = read_platform_from_testreport_file(path: path)
junit.parse path.to_s
junit.report
all_test = junit.tests.map(&:attributes)
slowest_test = all_test.sort_by { |attributes| attributes[:time].to_f }.last
fail "**#{test_report_name}** don't report any test! Please check the log and see if the target are crashing or something" if all_test.empty?
message "⌛️ **[#{test_report_name}]** Slowest test: #{slowest_test[:name]} took #{'%.3f' % slowest_test[:time]} seconds" if all_test.any?
end
#SWIFTLINT
swiftlint.lint_all_files = true
swiftlint.config_file = '.swiftlint.yml'
swiftlint.lint_files fail_on_error: true
#TEST EVOLUTION CHECK:
has_code_changes = !gitfiles.grep(/^Sources/).empty?
has_tests_changes = !gitfiles.grep(/^Tests/).empty?
if has_code_changes
warn('You have changes in code but there is no changes in any test... do you sleep well at night? 🤨') if !has_tests_changes
end