forked from elastic/elasticsearch-rs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile.toml
353 lines (314 loc) · 12.5 KB
/
Makefile.toml
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
[config]
default_to_workspace = false
[env]
# Determines the version of Elasticsearch docker container used
STACK_VERSION = { value = "8.0.0-SNAPSHOT", condition = { env_not_set = ["STACK_VERSION"] }}
# Determines the distribution of docker container used. Either platinum or free
TEST_SUITE = { value = "free", condition = { env_not_set = ["TEST_SUITE"] }}
# Set publish flags to dry-run by default, to force user to explicitly define for publishing
CARGO_MAKE_CARGO_PUBLISH_FLAGS = "--dry-run"
# RUST_BACKTRACE is set to "full" in cargo make's builtin makefiles/stable.toml
RUST_BACKTRACE = { value = "0", condition = { env_not_set = ["RUST_BACKTRACE"]}}
[tasks.set-free-env]
category = "Elasticsearch"
description = "Sets ELASTICSEARCH_URL environment variable if not already set for later tasks when free test suite used"
private = true
condition = { env = { "TEST_SUITE" = "free" }, env_not_set = ["ELASTICSEARCH_URL"] }
env = { "ELASTICSEARCH_URL" = "http://elastic:changeme@localhost:9200" }
[tasks.set-platinum-env]
category = "Elasticsearch"
description = "Sets ELASTICSEARCH_URL environment variable if not already set for later tasks when platinum test suite used"
private = true
condition = { env = { "TEST_SUITE" = "platinum" }, env_not_set = ["ELASTICSEARCH_URL"] }
env = { "ELASTICSEARCH_URL" = "https://elastic:changeme@localhost:9200" }
[tasks.download-specs]
category = "Elasticsearch"
description = '''Download Rest API specs and YAML tests'''
private = true
command = "cargo"
# cargo-make insists on installing cargo-xtask and ignores .cargo/config.toml
#args = ["xtask", "download-specs", "--url", "${ELASTICSEARCH_URL}"]
args = ["run", "-q", "-p", "xtask", "--", "download-specs", "--url", "${ELASTICSEARCH_URL}"]
dependencies = ["start-elasticsearch"]
[tasks.run-yaml-test-runner]
category = "Elasticsearch"
description = '''
Runs yaml_test_runner package to generate tests from yaml files for a given Elasticsearch commit.
The commit to use is retrieved from the running Elasticsearch instance
'''
private = true
command = "cargo"
args = ["run", "-p", "yaml_test_runner", "--", "-u", "${ELASTICSEARCH_URL}"]
dependencies = ["download-specs"]
[tasks.test-yaml-test-runner]
category = "Elasticsearch"
private = true
condition = { env_set = [ "ELASTICSEARCH_URL" ], env_false = ["CARGO_MAKE_CI"] }
command = "cargo"
args = ["test", "-p", "yaml_test_runner", "--", "--test-threads", "1"]
dependencies = ["generate-yaml-tests"]
[tasks.test-yaml-test-runner-ci]
category = "Elasticsearch"
private = true
condition = { env_set = [ "ELASTICSEARCH_URL" ], env_true = ["CARGO_MAKE_CI"] }
script = ["cargo test -p yaml_test_runner -- --test-threads 1 -Z unstable-options --format json | tee test_results/results.json"]
dependencies = ["generate-yaml-tests"]
[tasks.test-elasticsearch]
category = "Elasticsearch"
private = true
condition = { env_set = [ "ELASTICSEARCH_URL" ], env = { "TEST_SUITE" = "platinum" } }
command = "cargo"
args = ["test", "-p", "elasticsearch"]
dependencies = ["start-elasticsearch"]
[tasks.run-api-generator]
category = "Elasticsearch"
private = true
command = "cargo"
args = ["run", "-p", "api_generator"]
dependencies = ["download-specs"]
[tasks.create-test-results-dir]
category = "Elasticsearch"
private = true
condition = { env_true = [ "CARGO_MAKE_CI" ] }
script = ["[ -d test_results ] || mkdir -p test_results"]
[tasks.install-cargo2junit]
category = "Elasticsearch"
private = true
script = ["cargo install cargo2junit"]
[tasks.convert-test-results-junit]
category = "Elasticsearch"
private = true
condition = { env_true = [ "CARGO_MAKE_CI" ] }
script = ["cat test_results/results.json | cargo2junit > test_results/cargo-junit.xml"]
dependencies = ["install-cargo2junit"]
[tasks.run-elasticsearch]
category = "Elasticsearch"
private = true
condition = { env_set = [ "STACK_VERSION", "TEST_SUITE" ], env_false = ["CARGO_MAKE_CI"] }
dependencies = ["set-free-env", "set-platinum-env"]
[tasks.run-elasticsearch.linux]
command = "./.ci/run-elasticsearch.sh"
[tasks.run-elasticsearch.mac]
command = "./.ci/run-elasticsearch.sh"
[tasks.run-elasticsearch.windows]
script_runner = "cmd"
script = [
'''
bash -c "STACK_VERSION=%STACK_VERSION% TEST_SUITE=%TEST_SUITE% DETACH=%DETACH% CLEANUP=%CLEANUP% bash .ci/run-elasticsearch.sh"
'''
]
[tasks.publish-elasticsearch]
description = "Runs the cargo publish command."
category = "Elasticsearch"
private = true
script_runner = "@duckscript"
script = [
"""
cd elasticsearch
echo "publishing elasticsearch crate: cargo publish %{CARGO_MAKE_CARGO_PUBLISH_FLAGS}"
if is_empty %{CARGO_MAKE_CARGO_PUBLISH_FLAGS}
exec cargo publish
else
exec cargo publish %{CARGO_MAKE_CARGO_PUBLISH_FLAGS}
end
"""
]
# ============
# Public tasks
# ============
[tasks.start-elasticsearch]
extend = "run-elasticsearch"
private = false
description = "Starts Elasticsearch docker container with the given version and distribution"
env = { "CLEANUP" = false, "DETACH" = true }
[tasks.stop-elasticsearch]
extend = "run-elasticsearch"
private = false
description = "Stops Elasticsearch docker container, if running"
env = { "CLEANUP" = true, "DETACH" = false }
[tasks.test-yaml]
category = "Elasticsearch"
description = "Generates and runs yaml_test_runner package platinum/free tests against a given Elasticsearch version"
condition = { env_set = [ "STACK_VERSION", "TEST_SUITE" ] }
dependencies = ["generate-yaml-tests", "create-test-results-dir", "test-yaml-test-runner", "test-yaml-test-runner-ci", "convert-test-results-junit"]
run_task = "stop-elasticsearch"
[tasks.test-generator]
category = "Elasticsearch"
clear = true
description = "Runs api_generator tests"
command = "cargo"
args = ["test", "-p", "api_generator"]
[tasks.test]
category = "Elasticsearch"
clear = true
description = "Runs elasticsearch package tests against a given Elasticsearch version"
env = { "TEST_SUITE" = { value = "platinum", condition = { env_set = ["TEST_SUITE"] } } }
dependencies = ["test-elasticsearch"]
run_task = "stop-elasticsearch"
[tasks.generate-yaml-tests]
category = "Elasticsearch"
description = "Generates Elasticsearch client tests from YAML tests"
dependencies = ["run-yaml-test-runner"]
run_task = "format"
[tasks.generate-api]
category = "Elasticsearch"
description = "Generates Elasticsearch client from REST API specs"
dependencies = ["run-api-generator"]
run_task = "format"
[tasks.docs]
description = "Generate Elasticsearch client documentation and opens in browser"
clear = true
category = "Elasticsearch"
command = "cargo"
args = ["doc", "-p", "elasticsearch", "--no-deps", "--open", "--all-features"]
[tasks.generate-release-notes]
category = "Elasticsearch"
description = """
Generates release notes for Elasticsearch client using a common release notes generator docker image.
Assumes the clients-team repo is checked out as a sibling directory of elasticsearch-rs
"""
condition = { env_set = ["OLD_VERSION", "NEW_VERSION"], files_exist = [ "${CARGO_MAKE_WORKING_DIRECTORY}/../clients-team/scripts/release-notes-generator/Dockerfile" ] }
script_runner = "@shell"
script = [
"""
cd ./../clients-team/scripts/release-notes-generator
docker build --file ./Dockerfile --tag clients-team/release_notes_generator .
docker run -v "${CARGO_MAKE_WORKING_DIRECTORY}/.ci/release/config.yml:/usr/src/release_notes_generator/config.yml" --rm clients-team/release_notes_generator -o ${OLD_VERSION} -n ${NEW_VERSION}
"""
]
[tasks.publish]
clear = true
dependencies = [ "publish-elasticsearch" ]
run_task = "generate-release-notes"
[tasks.package]
clear = true
description = "Runs the cargo package command for elasticsearch crate."
category = "Elasticsearch"
script_runner = "@duckscript"
script = [
"""
cd elasticsearch
echo "packaging elasticsearch crate: cargo package %{CARGO_MAKE_CARGO_PACKAGE_FLAGS}"
if is_empty %{CARGO_MAKE_CARGO_PACKAGE_FLAGS}
exec cargo package
else
exec cargo package %{CARGO_MAKE_CARGO_PACKAGE_FLAGS}
end
"""
]
[tasks.update-version]
description = "Updates the package versions and version in docs"
condition = { env_set = ["NEW_VERSION"] }
script_runner = "@rust"
script = '''
//! ```cargo
//! [dependencies]
//! envmnt = "*"
//! glob = "0.3.0"
//! semver = "0.11.0"
//! toml_edit = "0.2.0"
//! ```
extern crate glob;
extern crate semver;
use std::fs::{File, OpenOptions};
use std::io::{Read, Write};
use std::path::Path;
use glob::glob;
use semver::Version;
fn main() {
let new_version = {
let v = envmnt::get_or_panic("NEW_VERSION");
v.parse::<Version>().expect("NEW_VERSION must be a valid semantic version")
};
let old_version = update_cargo_toml(&new_version);
update_docs(&old_version, &new_version);
}
fn update_docs(old_version: &str, new_version: &Version) {
for entry in glob("docs/*.asciidoc").unwrap()
.chain(glob("README.md").unwrap())
.chain(glob("elasticsearch/src/lib.rs").unwrap()) {
match entry {
Ok(path) => {
let mut content = read_file(&path);
content = content.replace(
&format!("elasticsearch = \"{}\"", old_version),
&format!("elasticsearch = \"{}\"", new_version.to_string()));
write_file(&path, content);
}
Err(e) => panic!("{:?}", e),
}
}
}
fn update_cargo_toml(new_version: &Version) -> String {
let mut old_version = String::new();
for entry in glob("**/Cargo.toml").unwrap() {
match entry {
Ok(path) => {
// skip workspace and target tomls
if path.starts_with("target") || path.to_string_lossy() == "Cargo.toml" {
continue;
}
let content = read_file(&path);
let mut toml = content.parse::<toml_edit::Document>().expect("Could not parse Cargo.toml");
let name = toml["package"]["name"].as_str().expect("toml has name");
// store the version from the elasticsearch package to target replacement in docs
if name == "elasticsearch" {
old_version = toml["package"]["version"]
.as_str()
.expect("toml has version")
.to_string();
}
toml["package"]["version"] = toml_edit::value(new_version.to_string());
write_file(&path, toml.to_string());
},
Err(e) => panic!("{:?}", e),
}
}
old_version
}
fn read_file<P: AsRef<Path>>(path: P) -> String {
let mut file = File::open(path).unwrap();
let mut raw_data = String::new();
file.read_to_string(&mut raw_data).unwrap();
raw_data
}
fn write_file<P: AsRef<Path>>(path: P, content: String) {
let mut file = OpenOptions::new()
.write(true)
.truncate(true)
.open(path)
.unwrap();
file.write_all(content.as_bytes()).unwrap();
}
'''
[tasks.default]
clear = true
script_runner = "@duckscript"
script = ['''
echo
echo Main tasks:
echo - generate-api: Generates Elasticsearch client from REST API specs
echo - start-elasticsearch: Starts Elasticsearch docker container with the given version and distribution
echo - stop-elasticsearch: Stops Elasticsearch docker container, if running
echo
echo - test-yaml: Generates and runs yaml_test_runner package platinum/free tests against a given Elasticsearch version
echo - test-generator: Generates and runs api_generator package tests
echo - test: Runs elasticsearch package tests against a given Elasticsearch version
echo
echo - update-version: Updates the version
echo pass NEW_VERSION environment variable for version
echo - generate-release-notes: Generates release notes for elasticsearch crate.
echo pass OLD_VERSION and NEW_VERSION environment variables to match release version GitHub labels e.g. v7.9.0-alpha.1
echo - package: Packages the elasticsearch crate.
echo package flags can be overridden with CARGO_MAKE_CARGO_PACKAGE_FLAGS environment variable
echo - publish: Publishes the elasticsearch crate.
echo By default, peforms a dry run by passing --dry-run, but publish flags can be overridden with CARGO_MAKE_CARGO_PUBLISH_FLAGS environment variable
echo
echo Most tasks use these environment variables:
echo - STACK_VERSION (default '${STACK_VERSION}'): the version of Elasticsearch
echo - TEST_SUITE ('free' or 'platinum', default '${TEST_SUITE}'): the distribution of Elasticsearch
echo - CI (default not set): set when running on CI to determine whether to start Elasticsearch and format test output as JSON
echo
echo Run 'cargo make --list-all-steps' for a complete list of available tasks.
echo
''']