Skip to content

Commit

Permalink
bug: read cargo toml instead of running cargo metadata (#1552)
Browse files Browse the repository at this point in the history
- Closes: #1551 

# Summary

Now we read from the `Cargo.toml` and use that for the CI check. More
details in the issue.

# Checklist

- [x] All **changes** are **covered** by **tests** (or not applicable)
- [x] All **changes** are **documented** (or not applicable)
- [x] I **reviewed** the **entire PR** myself (preferably, on GH UI)
- [x] I **described** all **Breaking Changes** (or there's none)
  • Loading branch information
segfault-magnet authored Dec 5, 2024
1 parent 1d06f47 commit 08771d9
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ which = { version = "6.0.0", default-features = false }
zeroize = "1.7.0"
octocrab = { version = "0.39", default-features = false }
dotenv = { version = "0.15", default-features = false }
toml = { version = "0.8", default-features = false }

# Dependencies from the `fuel-core` repository:
fuel-core = { version = "0.40.0", default-features = false, features = [
Expand Down
2 changes: 1 addition & 1 deletion scripts/fuel-core-version/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ clap = { version = "4.5.3", features = ["derive"] }
color-eyre = "0.6.2"
fuels-accounts = { workspace = true, features = ["std"] }
semver = { workspace = true }
versions-replacer = { workspace = true }
toml = { workspace = true, features = ["parse"] }
35 changes: 27 additions & 8 deletions scripts/fuel-core-version/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use color_eyre::eyre::OptionExt;
use std::{
fs,
path::{Path, PathBuf},
};
use toml::Value;

use clap::{Parser, Subcommand};
use color_eyre::{
Expand All @@ -10,13 +12,6 @@ use color_eyre::{
};
use fuels_accounts::provider::SUPPORTED_FUEL_CORE_VERSION;
use semver::Version;
use versions_replacer::metadata::collect_versions_from_cargo_toml;

fn get_version_from_toml(manifest_path: impl AsRef<Path>) -> Result<Version> {
let versions = collect_versions_from_cargo_toml(manifest_path)?;
let version = versions["fuel-core-types"].parse::<Version>()?;
Ok(version)
}

fn write_version_to_file(version: Version, version_file_path: impl AsRef<Path>) -> Result<()> {
let Version {
Expand Down Expand Up @@ -74,11 +69,35 @@ fn main() -> Result<()> {
command,
manifest_path,
} = App::parse();
let version = get_version_from_toml(&manifest_path)?;
let version = read_fuel_core_version(&manifest_path)?;
let version_file_path = get_version_file_path(&manifest_path)?;
match command {
Command::Write => write_version_to_file(version, version_file_path)?,
Command::Verify => verify_version_from_file(version)?,
}
Ok(())
}

pub fn read_fuel_core_version(path: impl AsRef<Path>) -> color_eyre::Result<Version> {
let cargo_toml: Value = fs::read_to_string(path.as_ref())?.parse::<Value>()?;

let str_version =
find_dependency_version(&cargo_toml).ok_or_eyre("could not find fuel-core version")?;

Ok(str_version.parse()?)
}

fn find_dependency_version(toml: &Value) -> Option<String> {
match toml
.get("workspace")?
.get("dependencies")?
.get("fuel-core")?
{
Value::String(version) => Some(version.clone()),
Value::Table(table) => table
.get("version")
.and_then(|v| v.as_str())
.map(String::from),
_ => None,
}
}

0 comments on commit 08771d9

Please sign in to comment.