Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ jobs:
run: cargo clippy --all-targets --locked ${{ matrix.features }} ${{ matrix.build }} -- -D warnings
- name: Check with SQLFluff
run: sqlfluff lint
- name: Verify for expression dependencies workspace
run: |
rustup toolchain install nightly
chmod +x ./.scripts/check-expression-deps.rs
./.scripts/check-expression-deps.rs
- name: Run tests
run: cargo test --locked ${{ matrix.features }} ${{ matrix.build }} --verbose

Expand Down
101 changes: 101 additions & 0 deletions .scripts/check-expression-deps.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#!/usr/bin/env -S cargo +nightly -Zscript

---cargo
[package]
edition = "2024"

[dependencies]
toml = { version = "0.8", features = ["parse"] }
---
//! This script checks if the `geo` and `geo-types` versions in the workspace and dependencies workspace match.
//!
//! In more detail, it does the following:
//!
//! 1. Parses the `Cargo.lock` file in the workspace and dependencies workspace.
//! 2. Extracts the versions of the `geo` and `geo-types` packages.
//! 3. Compares the versions by checking if there is an overlap between the versions in the two lockfiles.
//!
//! If any step fails, the script will print an error message and exit with a non-zero status code.

use std::fs;
use std::path::Path;
use toml::Table;

fn main() {
let deps_workspace_lockfile = Path::new("expression/deps-workspace/Cargo.lock");
let workspace_lockfile = Path::new("Cargo.lock");

if !deps_workspace_lockfile.exists() || !deps_workspace_lockfile.is_file() {
eprintln!("`Cargo.lock` in dependencies workspace does not exist at {deps_workspace_lockfile:?}");
std::process::exit(1);
}

if !workspace_lockfile.exists() || !workspace_lockfile.is_file() {
eprintln!("`Cargo.lock` in workspace does not exist at {workspace_lockfile:?}");
std::process::exit(1);
}

let workspace_geo_versions = find_geo_versions(workspace_lockfile);
let deps_workspace_geo_versions = find_geo_versions(deps_workspace_lockfile);

assert!(
workspace_geo_versions.geo_overlaps(&deps_workspace_geo_versions),
"`geo` versions in workspace and dependencies workspace do not match"
);

assert!(
workspace_geo_versions.geo_types_overlaps(&deps_workspace_geo_versions),
"`geo-types` versions in workspace and dependencies workspace do not match"
);

eprintln!("`geo` versions in workspace and dependencies workspace match");
}

fn find_geo_versions(path: &Path) -> GeoVersions {
let lockfile = fs::read_to_string(path).unwrap().parse::<Table>().unwrap();

let packages = lockfile["package"].as_array().unwrap();

let mut versions = GeoVersions {
geo: Vec::new(),
geo_types: Vec::new(),
};

for package in packages {
let version_vec: &mut Vec<String> = match package["name"].as_str().unwrap() {
"geo" => &mut versions.geo,
"geo-types" => &mut versions.geo_types,
_ => continue,
};

version_vec.push(package["version"].as_str().unwrap().to_string());
}

versions
}

#[derive(Debug)]
struct GeoVersions {
pub geo: Vec<String>,
pub geo_types: Vec<String>,
}

impl GeoVersions {
pub fn geo_overlaps(&self, other: &Self) -> bool {
for geo_version in &self.geo {
if other.geo.contains(&geo_version) {
return true;
}
}
return false;
}

pub fn geo_types_overlaps(&self, other: &Self) -> bool {
for geo_version in &self.geo_types {
if other.geo_types.contains(&geo_version) {
return true;
}
}
return false;
}
}
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,14 @@ If you plan on optimizing a feature of Geo Engine, please confirm it this way.
We use the [`expression/deps-workspace`](expression/deps-workspace) crate to manage dependencies for compiling expressions at runtime.
This ensures that it is compatible with Geo Engine when linking against it.

It is important to keep the dependencies in sync with the Geo Engine dependencies.
You can verify this by running the [`check-expression-deps.rs`](.scripts/check-expression-deps.rs) script located in the [`.scripts`](.scripts) directory.

```bash
chmod +x .scripts/check-expression-deps.rs
./.scripts/check-expression-deps.rs
```

To update the expression dependencies, you can use the [`update-expression-deps.rs`](.scripts/update-expression-deps.rs) script located in the [`.scripts`](.scripts) directory.
This script helps to keep the dependencies in sync and up to date.
Run it with:
Expand Down