This repository has been archived by the owner on Sep 1, 2023. It is now read-only.
forked from DataDog/integrations-core
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRakefile
183 lines (155 loc) · 5.12 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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#!/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_check_files
Dir.glob("#{ENV['SDK_HOME']}/*/check.py").collect do |file_path|
check_basename = "#{File.basename(File.dirname(file_path))}.py"
[check_basename, file_path]
end.entries
end
def find_yaml_confs
yaml_confs = Dir.glob("#{ENV['SDK_HOME']}/*/conf.yaml.example").collect do |file_path|
yaml_basename = "#{File.basename(File.dirname(file_path))}.yaml.example"
[yaml_basename, file_path]
end.entries
yaml_confs += Dir.glob("#{ENV['SDK_HOME']}/*/conf/*.yaml.example").collect do |file_path|
yaml_basename = File.basename(file_path)
[yaml_basename, file_path]
end.entries
yaml_confs
end
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 find_inconsistencies(files, dd_agent_base_dir)
inconsistencies = []
files.each do |file_basename, file_path|
file_content = File.read(file_path)
dd_agent_file_path = File.join(
ENV['SDK_HOME'],
'embedded',
'dd-agent',
dd_agent_base_dir,
file_basename
)
unless File.exist?(dd_agent_file_path)
inconsistencies << "#{file_basename} not found in dd-agent/#{dd_agent_base_dir}/"
next
end
if file_content != File.read(dd_agent_file_path)
inconsistencies << file_basename
end
end
inconsistencies
end
def print_inconsistencies(display_name, inconsistencies)
if inconsistencies.empty?
puts "No #{display_name} inconsistencies found"
else
puts "## #{display_name} inconsistencies:"
puts inconsistencies.join("\n")
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 'Outputs the checks/example configs of this repo that do not match the ones in `dd-agent` (temporary task)'
task dd_agent_consistency: [:pull_latest_agent] do
print_inconsistencies(
'check file',
find_inconsistencies(find_check_files, 'checks.d')
)
print_inconsistencies(
'yaml example file',
find_inconsistencies(find_yaml_confs, 'conf.d')
)
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