Skip to content

Commit 178c532

Browse files
authored
Merge pull request #297 from meilisearch/fix-doc
Improve the documentation, the CI and fix Clippy
2 parents 1161fcc + 072bc7c commit 178c532

20 files changed

+189
-103
lines changed

.github/workflows/rust.yml

Lines changed: 66 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ on: [pull_request]
33

44
name: Rust
55
jobs:
6-
test:
6+
heed-test:
77
name: Test the heed project
88
runs-on: ${{ matrix.os }}
99
strategy:
@@ -13,7 +13,30 @@ jobs:
1313
- os: ubuntu-latest
1414
- os: windows-latest
1515
- os: macos-latest
16+
steps:
17+
- uses: actions/checkout@v2
18+
with:
19+
submodules: recursive
20+
- uses: actions-rs/toolchain@v1
21+
with:
22+
profile: minimal
23+
toolchain: stable
24+
override: true
25+
- name: Run cargo test
26+
run: |
27+
cargo clean
28+
cargo test
1629
30+
heed3-test:
31+
name: Test the heed3 project
32+
runs-on: ${{ matrix.os }}
33+
strategy:
34+
matrix:
35+
os: [ubuntu-latest, windows-latest, macos-latest]
36+
include:
37+
- os: ubuntu-latest
38+
- os: windows-latest
39+
- os: macos-latest
1740
steps:
1841
- uses: actions/checkout@v2
1942
with:
@@ -26,6 +49,7 @@ jobs:
2649
- name: Run cargo test
2750
run: |
2851
cargo clean
52+
bash convert-to-heed3.sh
2953
cargo test
3054
3155
check-heed3:
@@ -38,7 +62,6 @@ jobs:
3862
- os: ubuntu-latest
3963
- os: windows-latest
4064
- os: macos-latest
41-
4265
steps:
4366
- uses: actions/checkout@v2
4467
with:
@@ -65,7 +88,6 @@ jobs:
6588
include:
6689
- os: ubuntu-latest
6790
- os: macos-latest
68-
6991
steps:
7092
- uses: actions/checkout@v2
7193
with:
@@ -75,7 +97,16 @@ jobs:
7597
profile: minimal
7698
toolchain: stable
7799
override: true
100+
- id: check_toml
101+
run: |
102+
if grep -q 'name = "heed3"' heed/Cargo.toml; then
103+
echo "should_skip=true" >> $GITHUB_OUTPUT
104+
else
105+
echo "should_skip=false" >> $GITHUB_OUTPUT
106+
fi
78107
- name: Run cargo test
108+
# Skip it if the CI is running with the heed3 Cargo.toml
109+
if: ${{ steps.check_toml.outputs.should_skip == 'false' }}
79110
run: |
80111
cargo clean
81112
cargo check --all-features -p heed
@@ -91,7 +122,6 @@ jobs:
91122
include:
92123
- os: ubuntu-latest
93124
- os: macos-latest
94-
95125
steps:
96126
- uses: actions/checkout@v2
97127
with:
@@ -116,7 +146,6 @@ jobs:
116146
include:
117147
- os: ubuntu-latest
118148
- os: macos-latest
119-
120149
steps:
121150
- uses: actions/checkout@v2
122151
with:
@@ -126,7 +155,16 @@ jobs:
126155
profile: minimal
127156
toolchain: stable
128157
override: true
158+
- id: check_toml
159+
run: |
160+
if grep -q 'name = "heed3"' heed/Cargo.toml; then
161+
echo "should_skip=true" >> $GITHUB_OUTPUT
162+
else
163+
echo "should_skip=false" >> $GITHUB_OUTPUT
164+
fi
129165
- name: Run the examples
166+
# Skip it if the CI is running with the heed3 Cargo.toml
167+
if: ${{ steps.check_toml.outputs.should_skip == 'false' }}
130168
run: |
131169
cargo clean
132170
# rmp-serde needs a feature activated, so we'll just run it separately.
@@ -142,7 +180,6 @@ jobs:
142180
include:
143181
- os: ubuntu-latest
144182
- os: macos-latest
145-
146183
steps:
147184
- uses: actions/checkout@v2
148185
with:
@@ -158,8 +195,26 @@ jobs:
158195
bash convert-to-heed3.sh
159196
cargo run --example 2>&1 | grep -E '^ '| xargs -n1 cargo run --example
160197
198+
clippy:
199+
name: Ensure clippy is happy on heed and heed3
200+
runs-on: ubuntu-latest
201+
steps:
202+
- uses: actions/checkout@v2
203+
with:
204+
submodules: recursive
205+
- uses: actions-rs/toolchain@v1
206+
with:
207+
profile: minimal
208+
toolchain: stable
209+
override: true
210+
- name: Run the examples
211+
run: |
212+
cargo clippy --all-targets -- --deny warnings
213+
bash convert-to-heed3.sh
214+
cargo clippy --all-targets -- --deny warnings
215+
161216
fmt:
162-
name: Ensure the heed project is formatted
217+
name: Ensure the heed and heed3 project are formatted
163218
runs-on: ubuntu-latest
164219
steps:
165220
- uses: actions/checkout@v2
@@ -170,7 +225,10 @@ jobs:
170225
override: true
171226
components: rustfmt
172227
- name: Run cargo fmt
173-
run: cargo fmt --check
228+
run: |
229+
cargo fmt --check
230+
bash convert-to-heed3.sh
231+
cargo fmt --check
174232
175233
no-heed3-in-heed-folder:
176234
name: Ensure heed3 is not erasing heed

convert-to-heed3.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,13 @@ done
3030
# Make it easier to rollback by doing a commit
3131
git config --local user.email "[email protected]"
3232
git config --local user.name "The CI"
33-
git commit -am 'remove-me: heed3 changes generate by the convert-to-heed3.sh script'
33+
34+
# But only commit if there is something to commit
35+
git diff -q --exit-code || git commit -am 'remove-me: heed3 changes generated by the convert-to-heed3.sh script'
36+
37+
git config --local --unset user.email
38+
git config --local --unset user.name
39+
3440

3541
echo "Heed3 crate setup completed successfully. Configurations for the heed crate have been copied and modified."
3642
echo "A commit (starting with remove-me) has been generated and must be deleted before merging into the main branch."

examples/all-types.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
use std::error::Error;
2-
use std::fs;
3-
use std::path::Path;
42

53
use heed::byteorder::BE;
64
use heed::types::*;
75
use heed::{Database, EnvOpenOptions};
86
use serde::{Deserialize, Serialize};
97

108
fn main() -> Result<(), Box<dyn Error>> {
11-
let path = Path::new("target").join("heed.mdb");
12-
13-
fs::create_dir_all(&path)?;
9+
let path = tempfile::tempdir()?;
1410

1511
let env = unsafe {
1612
EnvOpenOptions::new()

examples/clear-database.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
11
use std::error::Error;
2-
use std::fs;
3-
use std::path::Path;
42

53
use heed::types::*;
64
use heed::{Database, EnvOpenOptions};
75

86
// In this test we are checking that we can clear database entries and
97
// write just after in the same transaction without loosing the writes.
108
fn main() -> Result<(), Box<dyn Error>> {
11-
let env_path = Path::new("target").join("clear-database.mdb");
9+
let env_path = tempfile::tempdir()?;
1210

13-
let _ = fs::remove_dir_all(&env_path);
14-
15-
fs::create_dir_all(&env_path)?;
1611
let env = unsafe {
1712
EnvOpenOptions::new()
1813
.map_size(10 * 1024 * 1024) // 10MB

examples/cursor-append.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
11
use std::error::Error;
2-
use std::fs;
3-
use std::path::Path;
42

53
use heed::types::*;
64
use heed::{Database, EnvOpenOptions, PutFlags};
75

86
// In this test we are checking that we can append ordered entries in one
97
// database even if there is multiple databases which already contain entries.
108
fn main() -> Result<(), Box<dyn Error>> {
11-
let env_path = Path::new("target").join("cursor-append.mdb");
9+
let env_path = tempfile::tempdir()?;
1210

13-
let _ = fs::remove_dir_all(&env_path);
14-
15-
fs::create_dir_all(&env_path)?;
1611
let env = unsafe {
1712
EnvOpenOptions::new()
1813
.map_size(10 * 1024 * 1024) // 10MB

examples/custom-comparator.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use std::cmp::Ordering;
22
use std::error::Error;
3-
use std::path::Path;
4-
use std::{fs, str};
3+
use std::str;
54

65
use heed::EnvOpenOptions;
76
use heed_traits::Comparator;
@@ -21,11 +20,8 @@ impl Comparator for StringAsIntCmp {
2120
}
2221

2322
fn main() -> Result<(), Box<dyn Error>> {
24-
let env_path = Path::new("target").join("custom-key-cmp.mdb");
23+
let env_path = tempfile::tempdir()?;
2524

26-
let _ = fs::remove_dir_all(&env_path);
27-
28-
fs::create_dir_all(&env_path)?;
2925
let env = unsafe {
3026
EnvOpenOptions::new()
3127
.map_size(10 * 1024 * 1024) // 10MB

examples/heed3-all-types.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
use std::error::Error;
2-
use std::fs;
3-
use std::path::Path;
42

53
use heed3::byteorder::BE;
64
use heed3::types::*;
75
use heed3::{Database, EnvOpenOptions};
86
use serde::{Deserialize, Serialize};
97

108
fn main() -> Result<(), Box<dyn Error>> {
11-
let path = Path::new("target").join("heed3.mdb");
12-
13-
fs::create_dir_all(&path)?;
9+
let path = tempfile::tempdir()?;
1410

1511
let env = unsafe {
1612
EnvOpenOptions::new()

examples/heed3-encrypted.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,15 @@
11
use std::error::Error;
2-
use std::fs;
3-
use std::path::Path;
42

53
use argon2::Argon2;
64
use chacha20poly1305::{ChaCha20Poly1305, Key};
75
use heed3::types::*;
86
use heed3::EnvOpenOptions;
97

108
fn main() -> Result<(), Box<dyn Error>> {
11-
let env_path = Path::new("target").join("encrypt.mdb");
9+
let env_path = tempfile::tempdir()?;
1210
let password = "This is the password that will be hashed by the argon2 algorithm";
1311
let salt = "The salt added to the password hashes to add more security when stored";
1412

15-
let _ = fs::remove_dir_all(&env_path);
16-
fs::create_dir_all(&env_path)?;
17-
1813
// We choose to use argon2 as our Key Derivation Function, but you can choose whatever you want.
1914
// <https://github.com/RustCrypto/traits/tree/master/password-hash#supported-crates>
2015
let mut key = Key::default();

examples/multi-env.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
use std::error::Error;
2-
use std::fs;
3-
use std::path::Path;
42

53
use byteorder::BE;
64
use heed::types::*;
@@ -9,18 +7,15 @@ use heed::{Database, EnvOpenOptions};
97
type BEU32 = U32<BE>;
108

119
fn main() -> Result<(), Box<dyn Error>> {
12-
let env1_path = Path::new("target").join("env1.mdb");
13-
let env2_path = Path::new("target").join("env2.mdb");
14-
15-
fs::create_dir_all(&env1_path)?;
10+
let env1_path = tempfile::tempdir()?;
11+
let env2_path = tempfile::tempdir()?;
1612
let env1 = unsafe {
1713
EnvOpenOptions::new()
1814
.map_size(10 * 1024 * 1024) // 10MB
1915
.max_dbs(3000)
2016
.open(env1_path)?
2117
};
2218

23-
fs::create_dir_all(&env2_path)?;
2419
let env2 = unsafe {
2520
EnvOpenOptions::new()
2621
.map_size(10 * 1024 * 1024) // 10MB

examples/nested.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
use std::error::Error;
2-
use std::fs;
3-
use std::path::Path;
42

53
use heed::types::*;
64
use heed::{Database, EnvOpenOptions};
75

86
fn main() -> Result<(), Box<dyn Error>> {
9-
let path = Path::new("target").join("heed.mdb");
10-
11-
fs::create_dir_all(&path)?;
7+
let path = tempfile::tempdir()?;
128

139
let env = unsafe {
1410
EnvOpenOptions::new()

0 commit comments

Comments
 (0)