forked from opensearch-project/opensearch-rs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile.toml
353 lines (313 loc) · 11.2 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 OpenSearch docker container used
STACK_VERSION = { value = "latest", condition = { env_not_set = ["STACK_VERSION"] } }
# 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"] } }
SECURE_INTEGRATION = { value = "true", condition = { env_not_set = ["SECURE_INTEGRATION"] } }
OPENSEARCH_PROTOCOL = { source = "${SECURE_INTEGRATION}", default_value = "https", mapping = { false = "http", true = "https" } }
OPENSEARCH_URL = { value = "${OPENSEARCH_PROTOCOL}://localhost:9200", condition = { env_not_set = ["OPENSEARCH_URL"] } }
######################
# OpenSearch Helpers #
######################
[tasks.generate-certs]
category = "OpenSearch"
description = "Generates SSL certificates used for integration tests"
command = "bash"
args = ["./.ci/generate-certs.sh"]
[tasks.run-opensearch]
category = "OpenSearch"
private = true
condition = { env_set = [ "STACK_VERSION"], env_false = ["CARGO_MAKE_CI"] }
command = "bash"
args = ["./.ci/run-opensearch.sh"]
[tasks.run-opensearch.windows]
script_runner = "cmd"
script = ['''
bash -c "STACK_VERSION=%STACK_VERSION% DETACH=%DETACH% CLEANUP=%CLEANUP% bash .ci/run-opensearch.sh"
''']
[tasks.start-opensearch]
extend = "run-opensearch"
private = false
description = "Starts OpenSearch docker container with the given version and distribution"
env = { CLEANUP = false, DETACH = true }
[tasks.stop-opensearch]
extend = "run-opensearch"
private = false
description = "Stops OpenSearch docker container, if running"
env = { CLEANUP = true, DETACH = false }
###################
# Code Generation #
###################
[tasks.generate-yaml-tests-inner]
category = "OpenSearch"
private = true
command = "cargo"
args = ["run", "-p", "yaml_test_runner", "--", "-u", "${OPENSEARCH_URL}"]
[tasks.generate-yaml-tests]
category = "OpenSearch"
description = "Generates OpenSearch client tests from YAML tests"
dependencies = ["start-opensearch", "generate-yaml-tests-inner", "format"]
run_task = "stop-opensearch"
[tasks.generate-api-inner]
category = "OpenSearch"
private = true
command = "cargo"
args = ["run", "-p", "api_generator"]
[tasks.generate-api]
category = "OpenSearch"
description = "Generates OpenSearch client from REST API specs"
dependencies = ["generate-api-inner"]
run_task = "format"
################
# Test Helpers #
################
[tasks.create-test-results-dir]
category = "OpenSearch"
private = true
condition = { env_true = [ "CARGO_MAKE_CI" ] }
script = ["[ -d test_results ] || mkdir -p test_results"]
[tasks.set-coverage-vars]
description = "Set environment variables to enable coverage data"
private = true
condition = { env_true = [ "CARGO_MAKE_CI" ] }
env = { RUSTFLAGS = "-C instrument-coverage", LLVM_PROFILE_FILE = "${CARGO_MAKE_WORKING_DIRECTORY}/test_results/opensearch-%m.profraw" }
[tasks.convert-coverage-data]
description = "Convert coverage data to lcov format"
private = true
condition = { env_true = [ "CARGO_MAKE_CI" ] }
command = "grcov"
args = ["./test_results", "-s", ".", "--binary-path", "./target/debug", "-t", "lcov", "--branch", "--ignore-not-existing", "--llvm", "-o", "./test_results/opensearch.lcov"]
#########
# Tests #
#########
[tasks.test-yaml-inner]
category = "OpenSearch"
private = true
command = "cargo"
args = ["test", "-p", "yaml_test_runner", "--", "--test-threads", "1"]
[tasks.test-yaml]
category = "OpenSearch"
description = "Generates and runs yaml_test_runner package tests against a given OpenSearch version"
condition = { env_set = [ "STACK_VERSION"] }
dependencies = [
"set-coverage-vars",
"create-test-results-dir",
"start-opensearch",
"generate-yaml-tests-inner",
"format",
"test-yaml-inner",
"convert-coverage-data"
]
run_task = "stop-opensearch"
[tasks.test-inner]
category = "OpenSearch"
private = true
command = "cargo"
args = [
"test",
"--no-fail-fast",
"--workspace",
"@@split(CARGO_MAKE_TASK_ARGS,;)"
]
[tasks.test]
clear = true
category = "OpenSearch"
description = "Runs all tests (except YAML) against a given OpenSearch version"
dependencies = [
"set-coverage-vars",
"create-test-results-dir",
"start-opensearch",
"test-inner",
"convert-coverage-data"
]
run_task = "stop-opensearch"
[tasks.unittest-inner]
category = "OpenSearch"
private = true
command = "cargo"
args = ["test", "--lib", "--bins"]
[tasks.unittest]
category = "OpenSearch"
description = "Runs workspace unit tests"
dependencies = ["set-coverage-vars", "create-test-results-dir", "unittest-inner"]
run_task = "convert-coverage-data"
#################
# Documentation #
#################
[tasks.docs]
description = "Generate OpenSearch client documentation and opens in browser"
clear = true
category = "OpenSearch"
command = "cargo"
args = ["doc", "-p", "opensearch", "--no-deps", "--open", "--all-features"]
##############
# Publishing #
##############
[tasks.generate-release-notes]
category = "OpenSearch"
description = """
Generates release notes for OpenSearch client using a common release notes generator docker image.
Assumes the clients-team repo is checked out as a sibling directory of opensearch-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-opensearch]
description = "Runs the cargo publish command."
category = "OpenSearch"
private = true
script_runner = "@duckscript"
script = [
"""
cd opensearch
echo "publishing opensearch 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
"""
]
[tasks.publish]
clear = true
dependencies = [ "publish-opensearch" ]
run_task = "generate-release-notes"
[tasks.package]
clear = true
description = "Runs the cargo package command for opensearch crate."
category = "OpenSearch"
script_runner = "@duckscript"
script = [
"""
cd opensearch
echo "packaging opensearch 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"
//! ```
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("opensearch/src/lib.rs").unwrap()) {
match entry {
Ok(path) => {
let mut content = read_file(&path);
content = content.replace(
&format!("opensearch = \"{}\"", old_version),
&format!("opensearch = \"{}\"", 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 opensearch package to target replacement in docs
if name == "opensearch" {
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 OpenSearch client from REST API specs
echo - start-opensearch: Starts OpenSearch docker container with the given version and distribution
echo - stop-opensearch: Stops OpenSearch docker container, if running
echo
echo - test-yaml: Generates and runs yaml_test_runner package platinum/free tests against a given OpenSearch version
echo - test-generator: Generates and runs api_generator package tests
echo - test: Runs opensearch package tests against a given OpenSearch version
echo
echo - update-version: Updates the version
echo pass NEW_VERSION environment variable for version
echo - generate-release-notes: Generates release notes for opensearch 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 opensearch crate.
echo package flags can be overridden with CARGO_MAKE_CARGO_PACKAGE_FLAGS environment variable
echo - publish: Publishes the opensearch 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 OpenSearch
echo - CI (default not set): set when running on CI to determine whether to start OpenSearch and format test output as JSON
echo
echo Run 'cargo make --list-all-steps' for a complete list of available tasks.
echo
''']