-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
159 lines (129 loc) · 3.21 KB
/
Rakefile
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# frozen_string_literal: true
#
# Helpers
#
def log(text)
$stderr.puts ">>> #{text}"
end
def cmd(*command)
$stderr.print "$ "
sh(*command)
end
def with_test_branch
brew_directory = `brew --repo`.strip
test_branch = "test-#{Time.now.to_i}"
Dir.chdir(brew_directory) do
current_branch = `git branch --show-current`.strip
status = `git status --short`.strip
unless status.empty?
abort <<~ERROR
The Brew repo has changes in progress according to `git status`.
Stash or commit your work before running tests.
-----
$ git status --short
#{status}
-----
ERROR
end
begin
log "Setup"
sh "git", "branch", test_branch, "master"
sh "git", "switch", test_branch
log "Test"
yield
ensure
log "Cleanup"
sh "git", "switch", current_branch
sh "git", "branch", "-D", test_branch
end
end
end
#
# Tasks
#
task default: %w[tasks]
task :tasks do
puts "Tasks"
puts "-----"
Rake.application.tasks.each do |task|
puts "- #{task}"
end
end
namespace "lint" do
task :check do
cmd "brew", "style", "apainintheneck/dev-utils"
end
task :fix do
cmd "brew", "style", "apainintheneck/dev-utils", "--fix"
end
end
namespace "readme" do
task :outdated do
ruby "scripts/generate_readme.rb"
sh "diff", "README.md", "README.md.new"
ensure
rm_f "README.md.new"
end
task :generate do
ruby "scripts/generate_readme.rb"
mv "README.md.new", "README.md"
ensure
rm_f "README.md.new"
end
end
namespace "test" do
task :"api-readall-test" do
cmd "brew", "api-readall-test", "--verbose"
end
task :"branch-compare" do
with_test_branch do
cmd "brew", "branch-compare", "--debug", "--", "help"
end
end
task :"generate-api-diff" do
with_test_branch do
cmd "brew", "generate-api-diff", "--debug", "--cask"
cmd "brew", "generate-api-diff", "--debug", "--formula"
end
end
task :"service-diff" do
with_test_branch do
cmd "brew", "service-diff", "--debug"
end
end
task :"startup-stats" do
cmd "brew", "startup-stats", "--require", "tap"
end
task :all do
%w[
test:api-readall-test
test:branch-compare
test:generate-api-diff
test:service-diff
test:startup-stats
].each_with_index do |task, index|
puts "--------------------" if index.positive?
Rake::Task[task].invoke
end
end
end
INTEGRATION_TESTS_FILE = ".github/workflows/integration_tests.yml"
RAKE_TEST_REGEX = /^\s+- run:\s+rake\s+test:([a-zA-Z_-]+)\s*$/
task :"missing-tests" do
abort "Missing integration test file: #{INTEGRATION_TESTS_FILE}" unless File.exist?(INTEGRATION_TESTS_FILE)
integration_tests = File.foreach(INTEGRATION_TESTS_FILE).filter_map do |line|
line[RAKE_TEST_REGEX, 1]
end
tap_commands = Dir.children("cmd").map do |file|
file.chomp(".rb")
end
missing_tests = tap_commands - integration_tests
unless missing_tests.empty?
missing_test_list = missing_tests.map { |test| "- #{test}" }.join("\n")
abort <<~EOS
Missing integration tests for the following commands:
#{missing_test_list}
Add tests to the #{INTEGRATION_TESTS_FILE} file.
EOS
end
end