forked from DataDog/integrations-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
121 lines (98 loc) · 3.33 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
#!/usr/bin/env rake
require 'rake'
unless ENV['CI']
rakefile_dir = File.dirname(__FILE__)
ENV['TRAVIS_BUILD_DIR'] = rakefile_dir
ENV['INTEGRATIONS_DIR'] = File.join(rakefile_dir, 'embedded')
ENV['PIP_CACHE'] = File.join(rakefile_dir, '.cache/pip')
ENV['VOLATILE_DIR'] = '/tmp/integration-sdk-testing'
ENV['CONCURRENCY'] = ENV['CONCURRENCY'] || '2'
ENV['NOSE_FILTER'] = ENV['NOSE_FILTER'] || 'not windows'
ENV['RUN_VENV'] = 'true'
ENV['SDK_TESTING'] = 'true'
end
ENV['SDK_HOME'] = File.dirname(__FILE__)
spec = Gem::Specification.find_by_name 'datadog-sdk-testing'
load "#{spec.gem_dir}/lib/tasks/sdk.rake"
def find_changelogs
changelogs = Dir.glob("#{ENV['SDK_HOME']}/*/CHANGELOG.md").collect do |file_path|
file_path
end.entries
changelogs
end
def release_date(rel_date)
changelogs = find_changelogs
changelogs.each do |f|
changelog_out = File.read(f).gsub(/unreleased|Unreleased/, rel_date.to_s)
File.open(f, 'w') do |out|
out << changelog_out
end
end
end
def os
case RUBY_PLATFORM
when /linux/
'linux'
when /darwin/
'mac_os'
when /x64-mingw32/
'windows'
else
raise 'Unsupported OS'
end
end
desc 'Set (today\'s) release date for Unreleased checks'
task :release_date do
release_date(
Time.now.strftime('%Y-%m-%d')
)
end
desc 'Copy checks and configuration files over the given paths, optionally merging requirements files into one'
task :copy_checks do
conf_dir = ENV['conf_dir']
raise "please specify 'conf_dir' param" if conf_dir.to_s.empty?
mkdir_p File.join(conf_dir, 'auto_conf')
checks_dir = ENV['checks_dir']
raise "please specify 'checks_dir' param" if checks_dir.to_s.empty?
mkdir_p checks_dir
all_reqs_file = nil
merge_to = ENV['merge_requirements_to']
unless merge_to.to_s.empty?
all_reqs_file = File.open(File.join(merge_to, 'check_requirements.txt'), 'w+')
end
Dir.glob('*/').each do |check|
check.slice! '/'
# Check the manifest to be sure that this check is enabled on this system
# or skip this iteration
manifest_file_path = "#{check}/manifest.json"
# If there is no manifest file, then we should assume the folder does not
# contain a working check and move onto the next
File.exist?(manifest_file_path) || next
manifest = JSON.parse(File.read(manifest_file_path))
manifest['supported_os'].include?(os) || next
# Copy the checks over
if File.exist? "#{check}/check.py"
copy "#{check}/check.py", "#{checks_dir}/#{check}.py"
end
# Copy the check config to the conf directories
if File.exist? "#{check}/conf.yaml.example"
copy "#{check}/conf.yaml.example", "#{conf_dir}/#{check}.yaml.example"
end
# Copy the default config, if it exists
if File.exist? "#{check}/conf.yaml.default"
copy "#{check}/conf.yaml.default", "#{conf_dir}/#{check}.yaml.default"
end
# We don't have auto_conf on windows yet
if os != 'windows'
if File.exist? "#{check}/auto_conf.yaml"
copy "#{check}/auto_conf.yaml", "#{conf_dir}/auto_conf/#{check}.yaml"
end
end
next unless all_reqs_file && File.exist?("#{check}/requirements.txt") && !manifest['use_omnibus_reqs']
reqs = File.open("#{check}/requirements.txt", 'r').read
reqs.each_line do |line|
all_reqs_file.puts line if line[0] != '#'
end
end
all_reqs_file.close if all_reqs_file
end