-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use dynamic supported fuel-core version (#1190)
Close #1189. ~~Waiting on a new `fuel-core` release incorporating FuelLabs/fuel-core#1473 ### Checklist - [x] I have linked to any relevant issues. - [ ] I have updated the documentation. - [ ] I have added tests that prove my fix is effective or that my feature works. - [x] I have added necessary labels. - [x] I have done my best to ensure that my PR adheres to [the Fuel Labs Code Review Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md). - [x] I have requested a review from the relevant team or maintainers. --------- Co-authored-by: Ahmed Sagdati <[email protected]>
- Loading branch information
1 parent
7f43e07
commit b706076
Showing
6 changed files
with
112 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[package] | ||
name = "fuel-core-version" | ||
version = { workspace = true } | ||
authors = { workspace = true } | ||
edition = { workspace = true } | ||
homepage = { workspace = true } | ||
license = { workspace = true } | ||
publish = false | ||
repository = { workspace = true } | ||
rust-version = { workspace = true } | ||
|
||
[dependencies] | ||
clap = { version = "4.5.3", features = ["derive"] } | ||
color-eyre = "0.6.2" | ||
semver = { workspace = true } | ||
versions-replacer = { workspace = true } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
use std::{ | ||
fs, | ||
path::{Path, PathBuf}, | ||
}; | ||
|
||
use clap::{Parser, Subcommand}; | ||
use color_eyre::{ | ||
eyre::{bail, ContextCompat}, | ||
Result, | ||
}; | ||
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 { | ||
major, | ||
minor, | ||
patch, | ||
.. | ||
} = version; | ||
let text = format!("Version::new({major}, {minor}, {patch})"); | ||
fs::write(version_file_path, text.as_bytes())?; | ||
Ok(()) | ||
} | ||
|
||
fn get_version_file_path( | ||
manifest_path: impl AsRef<Path>, | ||
) -> Result<PathBuf, color_eyre::eyre::Error> { | ||
Ok(manifest_path | ||
.as_ref() | ||
.parent() | ||
.wrap_err("Invalid manifest path")? | ||
.join("scripts/fuel-core-version/version.rs")) | ||
} | ||
|
||
fn verify_version_from_file(version: Version) -> Result<()> { | ||
let version_from_file: Version = include!("../version.rs"); | ||
if version != version_from_file { | ||
bail!( | ||
"fuel_core version in version.rs ({}) doesn't match one in Cargo.toml ({})", | ||
version_from_file, | ||
version | ||
); | ||
} | ||
println!( | ||
"fuel_core versions in versions.rs and Cargo.toml match ({})", | ||
version | ||
); | ||
Ok(()) | ||
} | ||
|
||
#[derive(Debug, Parser)] | ||
struct App { | ||
#[clap(subcommand)] | ||
command: Command, | ||
#[clap(long)] | ||
manifest_path: PathBuf, | ||
} | ||
|
||
#[derive(Debug, Subcommand)] | ||
enum Command { | ||
Write, | ||
Verify, | ||
} | ||
|
||
fn main() -> Result<()> { | ||
let App { | ||
command, | ||
manifest_path, | ||
} = App::parse(); | ||
let version = get_version_from_toml(&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(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Version::new(0, 26, 0) |