Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: read cargo toml instead of running cargo metadata #1552

Merged
merged 1 commit into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
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,
}
}
Loading