Repository navigation
Expand file tree
/
Copy pathRakefile
More file actions
54 lines (48 loc) · 1.58 KB
/
Copy pathRakefile
File metadata and controls
54 lines (48 loc) · 1.58 KB
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
require 'net/http'
require 'open3'
RED = "\033[31m".freeze
GREEN = "\033[32m".freeze
RESET = "\033[0m".freeze
def run_command(cmd, silent: true, print_command: false, report_status: false)
puts "#{GREEN}Running #{cmd}#{RESET}" if print_command
output = ''
Open3.popen2e(cmd) do |_stdin, stdout_stderr, thread|
stdout_stderr.each do |line|
puts line unless silent
output += line
end
exitcode = thread.value.exitstatus
unless exitcode.zero?
err = "#{RED}Command failed! Command: #{cmd}, Exit code: #{exitcode}"
# Print details if we were running silent
err += "\nOutput:\n#{output}" if silent
err += RESET
abort err
end
puts "#{GREEN}Command finished with status #{exitcode}#{RESET}" if report_status
end
output.chomp
end
def http(url)
uri = URI(url)
Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https') do |h|
req = Net::HTTP::Get.new(uri)
req['User-Agent'] = 'openvox_puppet_runtime/1.0'
res = h.request(req)
raise "HTTP #{res.code} #{uri}" unless res.is_a?(Net::HTTPSuccess)
res.body
end
end
begin
require 'rubocop/rake_task'
rescue LoadError
# Do nothing if no required gem installed
else
RuboCop::RakeTask.new(:rubocop) do |task|
# These make the rubocop experience maybe slightly less terrible
task.options = ['--display-cop-names', '--display-style-guide', '--extra-details']
# Use Rubocop's Github Actions formatter if possible
task.formatters << 'github' if ENV['GITHUB_ACTIONS'] == 'true'
end
end
Dir.glob(File.join('tasks/**/*.rake')).each { |file| load file }