[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 ./.ci/generate-certs.sh" [tasks.run-opensearch] category = "OpenSearch" private = true condition = { env_set = [ "STACK_VERSION"], env_false = ["CARGO_MAKE_CI"] } [tasks.run-opensearch.linux] command = "./.ci/run-opensearch.sh" [tasks.run-opensearch.mac] command = "./.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::().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::().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>(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>(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 ''']