Skip to content

Commit 19a4a8a

Browse files
authored
add evergreen CI (#142)
1 parent 3654859 commit 19a4a8a

File tree

9 files changed

+254
-11
lines changed

9 files changed

+254
-11
lines changed

.evergreen/check-clippy.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/sh
2+
3+
set -o errexit
4+
5+
. ~/.cargo/env
6+
cargo clippy --all-targets --all-features -p mongodb -- -D warnings

.evergreen/check-rustfmt.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/sh
2+
3+
set -o errexit
4+
5+
. ~/.cargo/env
6+
cargo +nightly fmt -- --check

.evergreen/config.yml

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
########################################
2+
# Evergreen Template for MongoDB Drivers
3+
########################################
4+
5+
# When a task that used to pass starts to fail
6+
# Go through all versions that may have been skipped to detect
7+
# when the task started failing
8+
stepback: true
9+
10+
# Mark a failure as a system/bootstrap failure (purple box) rather then a task
11+
# failure by default.
12+
# Actual testing tasks are marked with `type: test`
13+
command_type: system
14+
15+
# Protect ourself against rogue test case, or curl gone wild, that runs forever
16+
# 12 minutes is the longest we'll ever run
17+
exec_timeout_secs: 3600 # 12 minutes is the longest we'll ever run
18+
19+
# What to do when evergreen hits the timeout (`post:` tasks are run automatically)
20+
timeout:
21+
- command: shell.exec
22+
params:
23+
script: |
24+
ls -la
25+
26+
functions:
27+
"fetch source":
28+
# Executes git clone and applies the submitted patch, if any
29+
- command: git.get_project
30+
params:
31+
directory: "src"
32+
# Applies the subitted patch, if any
33+
# Deprecated. Should be removed. But still needed for certain agents (ZAP)
34+
- command: git.apply_patch
35+
# Make an evergreen exapanstion file with dynamic values
36+
- command: shell.exec
37+
params:
38+
working_dir: "src"
39+
script: |
40+
# Get the current unique version of this checkout
41+
if [ "${is_patch}" = "true" ]; then
42+
CURRENT_VERSION=$(git describe)-patch-${version_id}
43+
else
44+
CURRENT_VERSION=latest
45+
fi
46+
47+
export PROJECT_DIRECTORY="$(pwd)"
48+
49+
cat <<EOT > expansion.yml
50+
CURRENT_VERSION: "$CURRENT_VERSION"
51+
PROJECT_DIRECTORY: "$PROJECT_DIRECTORY"
52+
PREPARE_SHELL: |
53+
set -o errexit
54+
set -o xtrace
55+
export PROJECT_DIRECTORY="$PROJECT_DIRECTORY"
56+
57+
export PROJECT="${project}"
58+
EOT
59+
# See what we've done
60+
cat expansion.yml
61+
62+
# Load the expansion file to make an evergreen variable with the current unique version
63+
- command: expansions.update
64+
params:
65+
file: src/expansion.yml
66+
67+
"install dependencies":
68+
command: shell.exec
69+
params:
70+
working_dir: "src"
71+
script: |
72+
${PREPARE_SHELL}
73+
.evergreen/install-dependencies.sh
74+
75+
"run tests":
76+
- command: shell.exec
77+
type: test
78+
params:
79+
shell: bash
80+
working_dir: "src"
81+
script: |
82+
${PREPARE_SHELL}
83+
.evergreen/run-tests.sh
84+
85+
"run u2i tests":
86+
- command: shell.exec
87+
type: test
88+
params:
89+
shell: bash
90+
working_dir: "src"
91+
script: |
92+
${PREPARE_SHELL}
93+
.evergreen/run-tests-u2i.sh
94+
95+
"run serde tests":
96+
- command: shell.exec
97+
type: test
98+
params:
99+
shell: bash
100+
working_dir: "src"
101+
script: |
102+
${PREPARE_SHELL}
103+
.evergreen/run-tests-u2i-serde.sh
104+
105+
"check rustfmt":
106+
- command: shell.exec
107+
type: test
108+
params:
109+
shell: bash
110+
working_dir: "src"
111+
script: |
112+
${PREPARE_SHELL}
113+
.evergreen/check-rustfmt.sh
114+
115+
"check clippy":
116+
- command: shell.exec
117+
type: test
118+
params:
119+
shell: bash
120+
working_dir: "src"
121+
script: |
122+
${PREPARE_SHELL}
123+
.evergreen/check-clippy.sh
124+
125+
"init test-results":
126+
- command: shell.exec
127+
params:
128+
script: |
129+
${PREPARE_SHELL}
130+
echo '{"results": [{ "status": "FAIL", "test_file": "Build", "log_raw": "No test-results.json found was created" } ]}' > ${PROJECT_DIRECTORY}/test-results.json
131+
132+
pre:
133+
- func: "fetch source"
134+
- func: "install dependencies"
135+
136+
post:
137+
- func: "cleanup"
138+
139+
tasks:
140+
- name: "test"
141+
commands:
142+
- func: "run tests"
143+
144+
- name: "test-u2i"
145+
commands:
146+
- func: "run u2i tests"
147+
148+
- name: "test-serde"
149+
commands:
150+
- func: "run serde tests"
151+
152+
- name: "check-rustfmt"
153+
commands:
154+
- func: "check rustfmt"
155+
156+
- name: "check-clippy"
157+
commands:
158+
- func: "check clippy"
159+
160+
-
161+
name: "tests"
162+
display_name: "Tests"
163+
run_on:
164+
- ubuntu1804-test
165+
tasks:
166+
- name: "test"
167+
- name: "test-u2i"
168+
- name: "test-serde"
169+
170+
-
171+
name: "lint"
172+
display_name: "Lint"
173+
run_on:
174+
- ubuntu1804-test
175+
tasks:
176+
- name: "check-clippy"
177+
- name: "check-rustfmt"
178+

.evergreen/install-dependencies.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/sh
2+
3+
rm -rf ~/.rustup
4+
curl https://sh.rustup.rs -sSf | sh -s -- -y --no-modify-path
5+
6+
echo "export CARGO_NET_GIT_FETCH_WITH_CLI=true" >> ~/.cargo/env
7+
. ~/.cargo/env
8+
rustup toolchain install nightly -c rustfmt

.evergreen/run-tests-serde.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/sh
2+
3+
set -o errexit
4+
5+
. ~/.cargo/env
6+
cd serde-tests
7+
RUST_BACKTRACE=1 cargo test

.evergreen/run-tests-u2i.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/sh
2+
3+
set -o errexit
4+
5+
. ~/.cargo/env
6+
RUST_BACKTRACE=1 cargo test --features u2i

.evergreen/run-tests.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/sh
2+
3+
set -o errexit
4+
5+
. ~/.cargo/env
6+
RUST_BACKTRACE=1 cargo test

README.md

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
[![Build Status](https://img.shields.io/travis/zonyitoo/bson-rs.svg)](https://travis-ci.org/zonyitoo/bson-rs)
44
[![crates.io](https://img.shields.io/crates/v/bson.svg)](https://crates.io/crates/bson)
55
[![crates.io](https://img.shields.io/crates/l/bson.svg)](https://crates.io/crates/bson)
6-
[![dependency status](https://deps.rs/repo/github/zonyitoo/bson-rs/status.svg)](https://deps.rs/repo/github/zonyitoo/bson-rs)
6+
[![dependency status](https://deps.rs/repo/github/zonyitoo/bson-rs/status.svg)](https://deps.rs/repo/github/mongodb/bson-rust)
77

88
Encoding and decoding support for BSON in Rust
99

@@ -92,3 +92,32 @@ fn test_compat_u2f() {
9292
```
9393

9494
In this example, we added an attribute `#[serde(with = "bson::compat::u2f")]` on field `x`, which will tell `serde` to use the `bson::compat::u2f::serialize` and `bson::compat::u2f::deserialize` methods to process this field.
95+
96+
## Contributing
97+
98+
We encourage and would happily accept contributions in the form of GitHub pull requests. Before opening one, be sure to run the tests locally; check out the [testing section](#running-the-tests) for information on how to do that. Once you open a pull request, your branch will be run against the same testing matrix that we use for our [continuous integration](#continuous-integration) system, so it is usually sufficient to only run the integration tests locally against a standalone. Remember to always run the linter tests before opening a pull request.
99+
100+
## Running the tests
101+
102+
### Integration and unit tests
103+
104+
To actually run the tests, you can use `cargo` like you would in any other crate:
105+
```bash
106+
cargo test --verbose # runs against localhost:27017
107+
```
108+
109+
### Linter Tests
110+
Our linter tests use the nightly version of `rustfmt` to verify that the source is formatted properly and the stable version of `clippy` to statically detect any common mistakes.
111+
You can use `rustup` to install them both:
112+
```bash
113+
rustup component add clippy --toolchain stable
114+
rustup component add rustfmt --toolchain nightly
115+
```
116+
To run the linter tests, run the `check-clippy.sh` and `check-rustfmt.sh` scripts in the `.evergreen` directory:
117+
```bash
118+
bash .evergreen/check-clippy.sh && bash .evergreen/check-rustfmt.sh
119+
```
120+
121+
## Continuous Integration
122+
Commits to master are run automatically on [evergreen](https://evergreen.mongodb.com/waterfall/rust-bson).
123+

rustfmt.toml

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
max_width = 120
2-
indent_style = "Visual"
3-
#fn_call_width = 120
4-
reorder_imports = true
5-
reorder_imports_in_group = true
6-
reorder_imported_names = true
1+
combine_control_expr = false
2+
comment_width = 100
73
condense_wildcard_suffixes = true
8-
#fn_args_layout = "Visual"
9-
#fn_call_style = "Visual"
10-
#chain_indent = "Visual"
4+
format_strings = true
115
normalize_comments = true
12-
use_try_shorthand = true
6+
use_try_shorthand = true
7+
wrap_comments = true
8+
merge_imports = true
9+
imports_layout = "HorizontalVertical"

0 commit comments

Comments
 (0)