Skip to content

Commit 6efacfa

Browse files
sagiegurarirusscam
andcommitted
Makefile improvements. (#142)
* Default message is now in duckscript so its same code for all platforms. no need for code duplication. * start/stop search task has a base task so common code is there. * start/stop search task no longer has a windows specific implementation * Move CI env var which isn't supported for all CI vendors to CARGO_MAKE_CI which supports all. * Update Makefile.toml Co-authored-by: Russ Cam <russ.cam@elastic.co> (cherry picked from commit 51fd5da)
1 parent 9aa67ac commit 6efacfa

File tree

1 file changed

+35
-59
lines changed

1 file changed

+35
-59
lines changed

Makefile.toml

Lines changed: 35 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,22 @@ Runs yaml_test_runner package to generate tests from yaml files for a given Elas
3030
The commit to use is retrieved from the running Elasticsearch instance
3131
'''
3232
private = true
33-
script = ["cargo run -p yaml_test_runner -- -u ${ELASTICSEARCH_URL}"]
33+
command = "cargo"
34+
args = ["run", "-p", "yaml_test_runner", "--", "-u", "${ELASTICSEARCH_URL}"]
3435
dependencies = ["start-elasticsearch"]
3536

36-
[tasks.run-yaml-test-runner.windows]
37-
script = ["cargo run -p yaml_test_runner -- -u %ELASTICSEARCH_URL%"]
38-
3937
[tasks.test-yaml-test-runner]
4038
category = "Elasticsearch"
4139
private = true
42-
condition = { env_set = [ "ELASTICSEARCH_URL" ], env_not_set = ["CI"] }
40+
condition = { env_set = [ "ELASTICSEARCH_URL" ], env_false = ["CARGO_MAKE_CI"] }
4341
command = "cargo"
4442
args = ["test", "-p", "yaml_test_runner", "--", "--test-threads=1"]
4543
dependencies = ["generate-yaml-tests"]
4644

4745
[tasks.test-yaml-test-runner-ci]
4846
category = "Elasticsearch"
4947
private = true
50-
condition = { env_set = [ "ELASTICSEARCH_URL", "CI" ] }
48+
condition = { env_set = [ "ELASTICSEARCH_URL" ], env_true = ["CARGO_MAKE_CI"] }
5149
script = ["cargo test -p yaml_test_runner -- --test-threads=1 -Z unstable-options --format json | tee test_results/results.json"]
5250
dependencies = ["generate-yaml-tests"]
5351

@@ -68,7 +66,7 @@ args = ["run", "-p", "api_generator"]
6866
[tasks.create-test-results-dir]
6967
category = "Elasticsearch"
7068
private = true
71-
condition = { env_set = [ "CI" ] }
69+
condition = { env_true = [ "CARGO_MAKE_CI" ] }
7270
script = ["[ -d test_results ] || mkdir -p test_results"]
7371

7472
[tasks.install-cargo2junit]
@@ -79,10 +77,25 @@ script = ["cargo install cargo2junit"]
7977
[tasks.convert-test-results-junit]
8078
category = "Elasticsearch"
8179
private = true
82-
condition = { env_set = [ "CI" ] }
80+
condition = { env_true = [ "CARGO_MAKE_CI" ] }
8381
script = ["cat test_results/results.json | cargo2junit > test_results/cargo-junit.xml"]
8482
dependencies = ["install-cargo2junit"]
8583

84+
[tasks.run-elasticsearch]
85+
category = "Elasticsearch"
86+
condition = { env_set = [ "STACK_VERSION", "TEST_SUITE" ], env_false = ["CARGO_MAKE_CI"] }
87+
script_runner = "bash"
88+
script = { file = "./.ci/run-elasticsearch.sh" }
89+
dependencies = ["set-oss-env", "set-xpack-env"]
90+
91+
[tasks.run-elasticsearch.windows]
92+
script_runner = "cmd"
93+
script = [
94+
'''
95+
bash -c "STACK_VERSION=%STACK_VERSION% TEST_SUITE=%TEST_SUITE% DETACH=%DETACH% CLEANUP=%CLEANUP% bash .ci/run-elasticsearch.sh"
96+
'''
97+
]
98+
8699
[tasks.publish-elasticsearch]
87100
description = "Runs the cargo publish command."
88101
category = "Elasticsearch"
@@ -101,24 +114,14 @@ exec cargo publish %{CARGO_MAKE_CARGO_PUBLISH_FLAGS}
101114
# ============
102115

103116
[tasks.start-elasticsearch]
104-
category = "Elasticsearch"
117+
extend = "run-elasticsearch"
105118
description = "Starts Elasticsearch docker container with the given version and distribution"
106-
condition = { env_set = [ "STACK_VERSION", "TEST_SUITE" ], env_not_set = ["CI"] }
107-
script = ["DETACH=true bash .ci/run-elasticsearch.sh"]
108-
dependencies = ["set-oss-env", "set-xpack-env"]
109-
110-
[tasks.start-elasticsearch.windows]
111-
script = ["bash -c \"STACK_VERSION=%STACK_VERSION% TEST_SUITE=%TEST_SUITE% DETACH=true bash .ci/run-elasticsearch.sh\""]
119+
env = { "CLEANUP" = false, "DETACH" = true }
112120

113121
[tasks.stop-elasticsearch]
114-
category = "Elasticsearch"
122+
extend = "run-elasticsearch"
115123
description = "Stops Elasticsearch docker container, if running"
116-
condition = { env_set = [ "STACK_VERSION", "TEST_SUITE" ], env_not_set = ["CI"] }
117-
script = ["CLEANUP=true bash .ci/run-elasticsearch.sh"]
118-
dependencies = ["set-oss-env", "set-xpack-env"]
119-
120-
[tasks.stop-elasticsearch.windows]
121-
script = ["bash -c \"STACK_VERSION=%STACK_VERSION% TEST_SUITE=%TEST_SUITE% CLEANUP=true bash .ci/run-elasticsearch.sh\""]
124+
env = { "CLEANUP" = true, "DETACH" = false }
122125

123126
[tasks.test-yaml]
124127
category = "Elasticsearch"
@@ -197,57 +200,30 @@ cargo package %{CARGO_MAKE_CARGO_PACKAGE_FLAGS}
197200

198201
[tasks.default]
199202
clear = true
203+
script_runner = "@duckscript"
200204
script = ['''
201205
echo
202-
echo "Main tasks:"
203-
echo "- generate-api: Generates Elasticsearch client from REST API specs"
204-
echo "- start-elasticsearch: Starts Elasticsearch docker container with the given version and distribution"
205-
echo "- stop-elasticsearch: Stops Elasticsearch docker container, if running"
206-
echo
207-
echo "- test-yaml: Generates and runs yaml_test_runner package xpack/oss tests against a given Elasticsearch version"
208-
echo "- test-generator: Generates and runs api_generator package tests"
209-
echo "- test: Runs elasticsearch package tests against a given Elasticsearch version"
210-
echo
211-
echo "- generate-release-notes: Generates release notes for elasticsearch crate."
212-
echo " pass OLD_VERSION and NEW_VERSION environment variables to match release version GitHub labels e.g. v7.9.0-alpha.1"
213-
echo "- package: Packages the elasticsearch crate."
214-
echo " package flags can be overridden with CARGO_MAKE_CARGO_PACKAGE_FLAGS environment variable"
215-
echo "- publish: Publishes the elasticsearch crate."
216-
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"
217-
echo
218-
echo "Most tasks use these environment variables:"
219-
echo "- STACK_VERSION (default '$STACK_VERSION'): the version of Elasticsearch"
220-
echo "- TEST_SUITE ('oss' or 'xpack', default '$TEST_SUITE'): the distribution of Elasticsearch"
221-
echo "- CI (default not set): set when running on CI to determine whether to start Elasticsearch and format test output as JSON"
222-
echo
223-
echo "Run 'cargo make --list-all-steps' for a complete list of available tasks."
224-
echo
225-
''']
226-
227-
[tasks.default.windows]
228-
script = ['''
229-
@echo off
230-
echo.
231206
echo Main tasks:
232207
echo - generate-api: Generates Elasticsearch client from REST API specs
233208
echo - start-elasticsearch: Starts Elasticsearch docker container with the given version and distribution
234209
echo - stop-elasticsearch: Stops Elasticsearch docker container, if running
210+
echo
235211
echo - test-yaml: Generates and runs yaml_test_runner package xpack/oss tests against a given Elasticsearch version
236212
echo - test-generator: Generates and runs api_generator package tests
237213
echo - test: Runs elasticsearch package tests against a given Elasticsearch version
238-
echo.
239-
echo - generate-release-notes: Generates release notes for elasticsearch crate
214+
echo
215+
echo - generate-release-notes: Generates release notes for elasticsearch crate.
240216
echo pass OLD_VERSION and NEW_VERSION environment variables to match release version GitHub labels e.g. v7.9.0-alpha.1
241217
echo - package: Packages the elasticsearch crate.
242218
echo package flags can be overridden with CARGO_MAKE_CARGO_PACKAGE_FLAGS environment variable
243219
echo - publish: Publishes the elasticsearch crate.
244220
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
245-
echo.
221+
echo
246222
echo Most tasks use these environment variables:
247-
echo - STACK_VERSION (default '%STACK_VERSION%'): the version of Elasticsearch
248-
echo - TEST_SUITE ('oss' or 'xpack', default '%TEST_SUITE%'): the distribution of Elasticsearch
223+
echo - STACK_VERSION (default '${STACK_VERSION}'): the version of Elasticsearch
224+
echo - TEST_SUITE ('oss' or 'xpack', default '${TEST_SUITE}'): the distribution of Elasticsearch
249225
echo - CI (default not set): set when running on CI to determine whether to start Elasticsearch and format test output as JSON
250-
echo.
226+
echo
251227
echo Run 'cargo make --list-all-steps' for a complete list of available tasks.
252-
echo.
253-
''']
228+
echo
229+
''']

0 commit comments

Comments
 (0)