Skip to content

Commit 7c680c6

Browse files
authored
Add cargo make tasks for packaging/publishing (#143)
This commit adds cargo make tasks for packaging and publishing, including generating release notes
1 parent 0523a68 commit 7c680c6

File tree

3 files changed

+76
-3
lines changed

3 files changed

+76
-3
lines changed

Makefile.toml

Lines changed: 72 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ default_to_workspace = false
66
STACK_VERSION = "8.0.0-SNAPSHOT"
77
# Determines the distribution of docker container used. Either xpack or oss
88
TEST_SUITE = "xpack"
9+
# Set publish flags to dry-run by default, to force user to explicitly define for publishing
10+
CARGO_MAKE_CARGO_PUBLISH_FLAGS = "--dry-run"
911

1012
[tasks.set-oss-env]
1113
category = "Elasticsearch"
@@ -81,6 +83,19 @@ condition = { env_set = [ "CI" ] }
8183
script = ["cat test_results/results.json | cargo2junit > test_results/cargo-junit.xml"]
8284
dependencies = ["install-cargo2junit"]
8385

86+
[tasks.publish-elasticsearch]
87+
description = "Runs the cargo publish command."
88+
category = "Elasticsearch"
89+
private = true
90+
script_runner = "@duckscript"
91+
script = [
92+
"""
93+
cd elasticsearch
94+
echo "publishing elasticsearch crate: cargo publish %{CARGO_MAKE_CARGO_PUBLISH_FLAGS}"
95+
exec cargo publish %{CARGO_MAKE_CARGO_PUBLISH_FLAGS}
96+
"""
97+
]
98+
8499
# ============
85100
# Public tasks
86101
# ============
@@ -139,6 +154,46 @@ description = "Generates Elasticsearch client from REST API specs"
139154
dependencies = ["run-api-generator"]
140155
run_task = "format"
141156

157+
[tasks.docs]
158+
description = "Generate Elasticsearch client documentation and opens in browser"
159+
clear = true
160+
category = "Elasticsearch"
161+
command = "cargo"
162+
args = ["doc", "-p", "elasticsearch", "--no-deps", "--open"]
163+
164+
[tasks.generate-release-notes]
165+
category = "Elasticsearch"
166+
description = """
167+
Generates release notes for Elasticsearch client using a common release notes generator docker image.
168+
Assumes the clients-team repo is checked out as a sibling directory of elasticsearch-rs
169+
"""
170+
condition = { env_set = ["OLD_VERSION", "NEW_VERSION"], files_exist = [ "${CARGO_MAKE_WORKING_DIRECTORY}/../clients-team/scripts/release-notes-generator/Dockerfile" ] }
171+
script_runner = "@shell"
172+
script = [
173+
"""
174+
cd ./../clients-team/scripts/release-notes-generator
175+
docker build --file ./Dockerfile --tag clients-team/release_notes_generator .
176+
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}
177+
"""
178+
]
179+
180+
[tasks.publish]
181+
clear = true
182+
dependencies = [ "publish-elasticsearch" ]
183+
run_task = "generate-release-notes"
184+
185+
[tasks.package]
186+
clear = true
187+
description = "Runs the cargo package command for elasticsearch crate."
188+
category = "Elasticsearch"
189+
script_runner = "@duckscript"
190+
script = [
191+
"""
192+
cd elasticsearch
193+
echo "packaging elasticsearch crate: cargo package %{CARGO_MAKE_CARGO_PACKAGE_FLAGS}"
194+
cargo package %{CARGO_MAKE_CARGO_PACKAGE_FLAGS}
195+
"""
196+
]
142197

143198
[tasks.default]
144199
clear = true
@@ -148,10 +203,18 @@ script = ['''
148203
echo "- generate-api: Generates Elasticsearch client from REST API specs"
149204
echo "- start-elasticsearch: Starts Elasticsearch docker container with the given version and distribution"
150205
echo "- stop-elasticsearch: Stops Elasticsearch docker container, if running"
206+
echo
151207
echo "- test-yaml: Generates and runs yaml_test_runner package xpack/oss tests against a given Elasticsearch version"
152208
echo "- test-generator: Generates and runs api_generator package tests"
153209
echo "- test: Runs elasticsearch package tests against a given Elasticsearch version"
154210
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
155218
echo "Most tasks use these environment variables:"
156219
echo "- STACK_VERSION (default '$STACK_VERSION'): the version of Elasticsearch"
157220
echo "- TEST_SUITE ('oss' or 'xpack', default '$TEST_SUITE'): the distribution of Elasticsearch"
@@ -173,9 +236,16 @@ script = ['''
173236
echo - test-generator: Generates and runs api_generator package tests
174237
echo - test: Runs elasticsearch package tests against a given Elasticsearch version
175238
echo.
239+
echo - generate-release-notes: Generates release notes for elasticsearch crate
240+
echo pass OLD_VERSION and NEW_VERSION environment variables to match release version GitHub labels e.g. v7.9.0-alpha.1
241+
echo - package: Packages the elasticsearch crate.
242+
echo package flags can be overridden with CARGO_MAKE_CARGO_PACKAGE_FLAGS environment variable
243+
echo - publish: Publishes the elasticsearch crate.
244+
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.
176246
echo Most tasks use these environment variables:
177-
echo - STACK_VERSION (default '$STACK_VERSION'): the version of Elasticsearch
178-
echo - TEST_SUITE ('oss' or 'xpack', default '$TEST_SUITE'): the distribution of Elasticsearch
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
179249
echo - CI (default not set): set when running on CI to determine whether to start Elasticsearch and format test output as JSON
180250
echo.
181251
echo Run 'cargo make --list-all-steps' for a complete list of available tasks.

api_generator/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
[package]
22
name = "api_generator"
33
version = "8.0.0-alpha.1"
4+
publish = false
45
description = "Generates source code for elasticsearch package, from the Elasticsearch REST API specs"
6+
repository = "https://github.com/elastic/elasticsearch-rs"
57
authors = ["Elastic and Contributors"]
68
edition = "2018"
79
license = "Apache-2.0"
8-
publish = false
910

1011
[dependencies]
1112
array_tool = "1.0.3"

yaml_test_runner/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
[package]
22
name = "yaml_test_runner"
33
version = "8.0.0-alpha.1"
4+
publish = false
45
edition = "2018"
56
authors = ["Elastic and Contributors"]
67
description = "Generates and runs tests from Elasticsearch's YAML test specs"
78
repository = "https://github.com/elastic/elasticsearch-rs"
9+
license = "Apache-2.0"
810

911
[dependencies]
1012
elasticsearch = { path = "./../elasticsearch" }

0 commit comments

Comments
 (0)