Skip to content

Commit 776fc9a

Browse files
committed
Update CI to use cargo make (#136)
This commit simplifies the CI test flow by - Using rust latest docker image as base image - Using cargo make to run the testing process pull the docker image before building to ensure that latest tag is the latest release. It appears that the -Z unstable-options --format json works on rust stable channel, despite rust documentation to the contrary. It also replaces the use of ES_TEST_SERVER with ELASTICSEARCH_URL, for consistency (cherry picked from commit 6c13b1d)
1 parent cd3d427 commit 776fc9a

File tree

11 files changed

+76
-85
lines changed

11 files changed

+76
-85
lines changed

.ci/DockerFile

Lines changed: 8 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,26 @@
1-
# rust nightly docker image is currently broken for this project.
2-
# Use a known, good nightly version. Since there are no docker images for specific nightly versions, build from
3-
# scratch, using the same commands as the rust docker image with
4-
# - specific nightly version that works (see RUST_TOOLCHAIN)
5-
# - Added openssl, libssl-dev and pkg-config packages to compile native-tls
6-
# FROM rustlang/rust:${RUST_TOOLCHAIN}
7-
FROM debian:stretch-slim
1+
# Use rust latest stable along with
2+
# - openssl, libssl-dev and pkg-config packages to compile native-tls
3+
# - cargo make and cargo2junit
4+
ARG RUST_TOOLCHAIN=latest
85

9-
ARG RUST_TOOLCHAIN=nightly-2020-07-27
10-
11-
ENV RUSTUP_HOME=/usr/local/rustup \
12-
CARGO_HOME=/usr/local/cargo \
13-
PATH=/usr/local/cargo/bin:$PATH \
14-
RUST_TOOLCHAIN=$RUST_TOOLCHAIN
6+
FROM rust:${RUST_TOOLCHAIN}
157

168
RUN set -eux; \
179
apt-get update; \
1810
apt-get install -y --no-install-recommends \
19-
ca-certificates \
20-
gcc \
21-
libc6-dev \
22-
wget \
2311
openssl \
2412
libssl-dev \
2513
pkg-config \
2614
; \
27-
\
28-
url="https://static.rust-lang.org/rustup/dist/x86_64-unknown-linux-gnu/rustup-init"; \
29-
wget "$url"; \
30-
chmod +x rustup-init; \
31-
./rustup-init -y --no-modify-path --default-toolchain nightly; \
32-
rm rustup-init; \
33-
chmod -R a+w $RUSTUP_HOME $CARGO_HOME; \
34-
rustup toolchain install $RUST_TOOLCHAIN; \
35-
rustup default $RUST_TOOLCHAIN; \
36-
rustup --version; \
37-
cargo --version; \
38-
rustc --version; \
39-
cargo install cargo2junit; \
40-
\
41-
apt-get remove -y --auto-remove \
42-
wget \
43-
; \
44-
rm -rf /var/lib/apt/lists/*;
45-
46-
# required to workaround a current issue with rustfmt-nightly
47-
ENV CFG_RELEASE=nightly
48-
ENV CFG_RELEASE_CHANNEL=nightly
15+
cargo install --force cargo-make; \
16+
cargo install cargo2junit;
4917

5018
# create app directory
5119
WORKDIR /usr/src/elasticsearch-rs
5220

5321
COPY .ci/certs ./.ci/certs
5422
COPY Cargo.toml ./Cargo.toml
23+
COPY Makefile.toml ./Makefile.toml
5524
COPY README.md ./README.md
5625
COPY api_generator ./api_generator
5726
COPY elasticsearch/Cargo.toml ./elasticsearch/Cargo.toml

.ci/run-repository.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,22 @@ echo -e "\033[34;1mINFO:\033[0m RUST_TOOLCHAIN ${RUST_TOOLCHAIN}\033[0m"
2222

2323
echo -e "\033[1m>>>>> Build [elastic/elasticsearch-rs container] >>>>>>>>>>>>>>>>>>>>>>>>>>>>>\033[0m"
2424

25+
docker pull rust:"${RUST_TOOLCHAIN}"
26+
2527
docker build --build-arg RUST_TOOLCHAIN="${RUST_TOOLCHAIN}" --file .ci/DockerFile --tag elastic/elasticsearch-rs .
2628

2729
echo -e "\033[1m>>>>> Run [elastic/elasticsearch-rs container] >>>>>>>>>>>>>>>>>>>>>>>>>>>>>\033[0m"
2830

2931
repo=$(realpath $(dirname $(realpath -s $0))/../)
3032

31-
# ES_TEST_SERVER env var is needed for cargo test
3233
docker run \
3334
--network=${network_name} \
34-
--env "ES_TEST_SERVER=${ELASTICSEARCH_URL}" \
35+
--env "TEST_SUITE=${TEST_SUITE}" \
36+
--env "STACK_VERSION=${STACK_VERSION}" \
37+
--env "ELASTICSEARCH_URL=${ELASTICSEARCH_URL}" \
38+
--env "CI=true" \
3539
--name test-runner \
3640
--volume ${repo}/test_results:/usr/src/elasticsearch-rs/test_results \
3741
--rm \
3842
elastic/elasticsearch-rs \
39-
/bin/bash -c \
40-
"cargo run -p yaml_test_runner -- -u \"${ELASTICSEARCH_URL}\"; \\
41-
mkdir -p test_results; \\
42-
cargo test -p yaml_test_runner -- --test-threads=1 -Z unstable-options --format json | tee test_results/results.json; \\
43-
cat test_results/results.json | cargo2junit > test_results/cargo-junit.xml"
43+
/bin/bash -c "cargo make test-yaml"

.ci/test-matrix.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ TEST_SUITE:
88
- xpack
99

1010
RUST_TOOLCHAIN:
11-
- nightly-2020-07-27
11+
- latest
1212

1313
exclude: ~

CONTRIBUTING.md

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,11 @@ The project makes use of the following, which should be installed
4040

4141
### Cargo make
4242

43-
Cargo make is used to define and configure a set of tasks, and run them as a flow. To see all of the tasks defined
43+
Cargo make is used to define and configure a set of tasks, and run them as a flow. To see all of the Elasticsearch
44+
category tasks defined
4445

4546
```sh
46-
cargo make --list-all-steps
47+
cargo make
4748
```
4849

4950
The `Elasticsearch` category of steps are specifically defined for this project and are defined in
@@ -69,7 +70,7 @@ The `Elasticsearch` category of steps are specifically defined for this project
6970
a snapshot release like `7.x-SNAPSHOT`
7071

7172
```sh
72-
cargo make test --env STACK_VERSION=<e.g. 7.9.0>
73+
cargo make test --env STACK_VERSION=7.9.0
7374
```
7475

7576
- Run YAML tests
@@ -81,7 +82,7 @@ The `Elasticsearch` category of steps are specifically defined for this project
8182
- `TEST_SUITE`: Elasticsearch distribution of `oss` or `xpack`
8283

8384
```sh
84-
cargo make test-yaml --env STACK_VERSION=<e.g. 7.9.0> --env TEST_SUITE=<xpack or oss>
85+
cargo make test-yaml --env STACK_VERSION=7.9.0 --env TEST_SUITE=oss
8586
```
8687

8788
### Packages
@@ -110,7 +111,9 @@ can be `to_string()`'ed and written to disk, and this is used to create much of
110111
A small executable that downloads YAML tests from GitHub and generates client tests from the YAML tests. The
111112
version of YAML tests to download are determined from the commit hash of a running Elasticsearch instance.
112113

113-
The `yaml_test_runner` package can be run with `cargo test` to run the generated client tests.
114+
The `yaml_test_runner` package can be run with `cargo make test-yaml` to run the generated client tests,
115+
passing environment variables `TEST_SUITE` and `STACK_VERSION` to control the distribution and version,
116+
respectively.
114117

115118
### Design principles
116119

@@ -141,21 +144,13 @@ The `quote` and `syn` crates help
141144
An id must always be provided for a delete script API call, so the `delete_script()` function
142145
must accept it as a value.
143146
144-
### Current development setup
145-
146-
The required toolchain for packages in the workspace are controlled
147-
by a `rust-toolchain` file in the root of each package.
148-
149-
`elasticsearch` package compiles and runs with rust stable.
150-
`api_generator` and `yaml_test_runner` packages require rust nightly.
151-
152147
### Coding style guide
153148
154149
The repository adheres to the styling enforced by `rustfmt`.
155150
156151
#### Formatting
157152
158-
Rust code can be formatted using [`rustfmt`](https://github.com/rust-lang/rustfmt). Follow the instructions to install.
153+
Rust code can be formatted using [`rustfmt`](https://github.com/rust-lang/rustfmt) through cargo make.
159154
160155
To format all packages in a workspace, from the workspace root
161156
@@ -167,7 +162,7 @@ It is strongly recommended to run this before opening a PR.
167162

168163
#### Clippy
169164

170-
[Clippy](https://github.com/rust-lang/rust-clippy) is a bunch of lints to catch common mistakes and improve your Rust code! Follow the instructions to install.
165+
[Clippy](https://github.com/rust-lang/rust-clippy) is a bunch of lints to catch common mistakes and improve your Rust code!
171166

172167
Run clippy before opening a PR
173168

Makefile.toml

Lines changed: 44 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,22 @@ TEST_SUITE = "xpack"
99

1010
[tasks.set-oss-env]
1111
category = "Elasticsearch"
12-
description = "Sets ELASTICSEARCH_URL environment variable for later tasks when oss test suite used"
12+
description = "Sets ELASTICSEARCH_URL environment variable if not already set for later tasks when oss test suite used"
1313
private = true
14-
condition = { env = { "TEST_SUITE" = "oss" } }
14+
condition = { env = { "TEST_SUITE" = "oss" }, env_not_set = ["ELASTICSEARCH_URL"] }
1515
env = { "ELASTICSEARCH_URL" = "http://localhost:9200" }
1616

1717
[tasks.set-xpack-env]
1818
category = "Elasticsearch"
19-
description = "Sets ELASTICSEARCH_URL environment variable for later tasks when xpack test suite used"
19+
description = "Sets ELASTICSEARCH_URL environment variable if not already set for later tasks when xpack test suite used"
2020
private = true
21-
condition = { env = { "TEST_SUITE" = "xpack" } }
21+
condition = { env = { "TEST_SUITE" = "xpack" }, env_not_set = ["ELASTICSEARCH_URL"] }
2222
env = { "ELASTICSEARCH_URL" = "https://elastic:changeme@localhost:9200" }
2323

2424
[tasks.run-yaml-test-runner]
2525
category = "Elasticsearch"
2626
description = '''
27-
Runs yaml_test_runner crate to generate tests from yaml files for a given Elasticsearch commit.
27+
Runs yaml_test_runner package to generate tests from yaml files for a given Elasticsearch commit.
2828
The commit to use is retrieved from the running Elasticsearch instance
2929
'''
3030
private = true
@@ -37,17 +37,22 @@ script = ["cargo run -p yaml_test_runner -- -u %ELASTICSEARCH_URL%"]
3737
[tasks.test-yaml-test-runner]
3838
category = "Elasticsearch"
3939
private = true
40-
condition = { env_set = [ "ELASTICSEARCH_URL" ] }
41-
env = { "ES_TEST_SERVER" = "${ELASTICSEARCH_URL}" }
40+
condition = { env_set = [ "ELASTICSEARCH_URL" ], env_not_set = ["CI"] }
4241
command = "cargo"
4342
args = ["test", "-p", "yaml_test_runner", "--", "--test-threads=1"]
4443
dependencies = ["generate-yaml-tests"]
4544

45+
[tasks.test-yaml-test-runner-ci]
46+
category = "Elasticsearch"
47+
private = true
48+
condition = { env_set = [ "ELASTICSEARCH_URL", "CI" ] }
49+
script = ["cargo test -p yaml_test_runner -- --test-threads=1 -Z unstable-options --format json | tee test_results/results.json"]
50+
dependencies = ["generate-yaml-tests"]
51+
4652
[tasks.test-elasticsearch]
4753
category = "Elasticsearch"
4854
private = true
4955
condition = { env_set = [ "ELASTICSEARCH_URL" ], env = { "TEST_SUITE" = "xpack" } }
50-
env = { "ES_TEST_SERVER" = "${ELASTICSEARCH_URL}" }
5156
command = "cargo"
5257
args = ["test", "-p", "elasticsearch"]
5358
dependencies = ["start-elasticsearch"]
@@ -58,14 +63,32 @@ private = true
5863
command = "cargo"
5964
args = ["run", "-p", "api_generator"]
6065

66+
[tasks.create-test-results-dir]
67+
category = "Elasticsearch"
68+
private = true
69+
condition = { env_set = [ "CI" ] }
70+
script = ["[ -d test_results ] || mkdir -p test_results"]
71+
72+
[tasks.install-cargo2junit]
73+
category = "Elasticsearch"
74+
private = true
75+
script = ["cargo install cargo2junit"]
76+
77+
[tasks.convert-test-results-junit]
78+
category = "Elasticsearch"
79+
private = true
80+
condition = { env_set = [ "CI" ] }
81+
script = ["cat test_results/results.json | cargo2junit > test_results/cargo-junit.xml"]
82+
dependencies = ["install-cargo2junit"]
83+
6184
# ============
6285
# Public tasks
6386
# ============
6487

6588
[tasks.start-elasticsearch]
6689
category = "Elasticsearch"
6790
description = "Starts Elasticsearch docker container with the given version and distribution"
68-
condition = { env_set = [ "STACK_VERSION", "TEST_SUITE" ] }
91+
condition = { env_set = [ "STACK_VERSION", "TEST_SUITE" ], env_not_set = ["CI"] }
6992
script = ["DETACH=true bash .ci/run-elasticsearch.sh"]
7093
dependencies = ["set-oss-env", "set-xpack-env"]
7194

@@ -75,7 +98,7 @@ script = ["bash -c \"STACK_VERSION=%STACK_VERSION% TEST_SUITE=%TEST_SUITE% DETAC
7598
[tasks.stop-elasticsearch]
7699
category = "Elasticsearch"
77100
description = "Stops Elasticsearch docker container, if running"
78-
condition = { env_set = [ "STACK_VERSION", "TEST_SUITE" ] }
101+
condition = { env_set = [ "STACK_VERSION", "TEST_SUITE" ], env_not_set = ["CI"] }
79102
script = ["CLEANUP=true bash .ci/run-elasticsearch.sh"]
80103
dependencies = ["set-oss-env", "set-xpack-env"]
81104

@@ -84,9 +107,9 @@ script = ["bash -c \"STACK_VERSION=%STACK_VERSION% TEST_SUITE=%TEST_SUITE% CLEAN
84107

85108
[tasks.test-yaml]
86109
category = "Elasticsearch"
87-
description = "Generates and runs yaml_test_runner crate xpack/oss tests against a given Elasticsearch version"
110+
description = "Generates and runs yaml_test_runner package xpack/oss tests against a given Elasticsearch version"
88111
condition = { env_set = [ "STACK_VERSION", "TEST_SUITE" ] }
89-
dependencies = ["generate-yaml-tests", "test-yaml-test-runner"]
112+
dependencies = ["generate-yaml-tests", "create-test-results-dir", "test-yaml-test-runner", "test-yaml-test-runner-ci", "convert-test-results-junit"]
90113
run_task = "stop-elasticsearch"
91114

92115
[tasks.test-generator]
@@ -99,7 +122,7 @@ args = ["test", "-p", "api_generator"]
99122
[tasks.test]
100123
category = "Elasticsearch"
101124
clear = true
102-
description = "Runs Elasticsearch crate tests against a given Elasticsearch version"
125+
description = "Runs elasticsearch package tests against a given Elasticsearch version"
103126
env = { "TEST_SUITE" = { value = "xpack", condition = { env_set = ["TEST_SUITE"] } } }
104127
dependencies = ["test-elasticsearch"]
105128
run_task = "stop-elasticsearch"
@@ -125,12 +148,14 @@ script = ['''
125148
echo "- generate-api: Generates Elasticsearch client from REST API specs"
126149
echo "- start-elasticsearch: Starts Elasticsearch docker container with the given version and distribution"
127150
echo "- stop-elasticsearch: Stops Elasticsearch docker container, if running"
128-
echo "- test-yaml: Generates and runs yaml_test_runner crate xpack/oss tests against a given Elasticsearch version"
129-
echo "- test: Runs Elasticsearch crate tests against a given Elasticsearch version"
151+
echo "- test-yaml: Generates and runs yaml_test_runner package xpack/oss tests against a given Elasticsearch version"
152+
echo "- test-generator: Generates and runs api_generator package tests"
153+
echo "- test: Runs elasticsearch package tests against a given Elasticsearch version"
130154
echo
131155
echo "Most tasks use these environment variables:"
132156
echo "- STACK_VERSION (default '$STACK_VERSION'): the version of Elasticsearch"
133157
echo "- TEST_SUITE ('oss' or 'xpack', default '$TEST_SUITE'): the distribution of Elasticsearch"
158+
echo "- CI (default not set): set when running on CI to determine whether to start Elasticsearch and format test output as JSON"
134159
echo
135160
echo "Run 'cargo make --list-all-steps' for a complete list of available tasks."
136161
echo
@@ -144,12 +169,14 @@ script = ['''
144169
echo - generate-api: Generates Elasticsearch client from REST API specs
145170
echo - start-elasticsearch: Starts Elasticsearch docker container with the given version and distribution
146171
echo - stop-elasticsearch: Stops Elasticsearch docker container, if running
147-
echo - test-yaml: Generates and runs yaml_test_runner crate xpack/oss tests against a given Elasticsearch version
148-
echo - test: Runs Elasticsearch crate tests against a given Elasticsearch version
172+
echo - test-yaml: Generates and runs yaml_test_runner package xpack/oss tests against a given Elasticsearch version
173+
echo - test-generator: Generates and runs api_generator package tests
174+
echo - test: Runs elasticsearch package tests against a given Elasticsearch version
149175
echo.
150176
echo Most tasks use these environment variables:
151177
echo - STACK_VERSION (default '$STACK_VERSION'): the version of Elasticsearch
152178
echo - TEST_SUITE ('oss' or 'xpack', default '$TEST_SUITE'): the distribution of Elasticsearch
179+
echo - CI (default not set): set when running on CI to determine whether to start Elasticsearch and format test output as JSON
153180
echo.
154181
echo Run 'cargo make --list-all-steps' for a complete list of available tasks.
155182
echo.

elasticsearch/examples/cat_indices.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub async fn main() -> Result<(), Box<dyn std::error::Error>> {
4545

4646
fn create_client() -> Result<Elasticsearch, Error> {
4747
fn cluster_addr() -> String {
48-
match std::env::var("ES_TEST_SERVER") {
48+
match std::env::var("ELASTICSEARCH_URL") {
4949
Ok(server) => server,
5050
Err(_) => DEFAULT_ADDRESS.into(),
5151
}

elasticsearch/examples/index_questions_answers/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ async fn create_index_if_not_exists(client: &Elasticsearch, delete: bool) -> Res
362362

363363
fn create_client() -> Result<Elasticsearch, Error> {
364364
fn cluster_addr() -> String {
365-
match std::env::var("ES_TEST_SERVER") {
365+
match std::env::var("ELASTICSEARCH_URL") {
366366
Ok(server) => server,
367367
Err(_) => DEFAULT_ADDRESS.into(),
368368
}

elasticsearch/examples/search_questions/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ pub async fn main() -> Result<(), Box<dyn std::error::Error>> {
112112

113113
fn create_client() -> Result<Elasticsearch, Error> {
114114
fn cluster_addr() -> String {
115-
match std::env::var("ES_TEST_SERVER") {
115+
match std::env::var("ELASTICSEARCH_URL") {
116116
Ok(server) => server,
117117
Err(_) => DEFAULT_ADDRESS.into(),
118118
}

elasticsearch/examples/search_questions_answers/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ pub async fn main() -> Result<(), Box<dyn std::error::Error>> {
9999

100100
fn create_client() -> Result<Elasticsearch, Error> {
101101
fn cluster_addr() -> String {
102-
match std::env::var("ES_TEST_SERVER") {
102+
match std::env::var("ELASTICSEARCH_URL") {
103103
Ok(server) => server,
104104
Err(_) => DEFAULT_ADDRESS.into(),
105105
}

elasticsearch/tests/common/client.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use url::Url;
3636
/// Gets the address to the Elasticsearch instance from environment variables
3737
/// and assumes an instance running locally on the default port otherwise
3838
pub fn cluster_addr() -> String {
39-
match std::env::var("ES_TEST_SERVER") {
39+
match std::env::var("ELASTICSEARCH_URL") {
4040
Ok(server) => server,
4141
Err(_) => DEFAULT_ADDRESS.into(),
4242
}

0 commit comments

Comments
 (0)