Skip to content

Commit

Permalink
Use dynamic supported fuel-core version (#1190)
Browse files Browse the repository at this point in the history
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
Br1ght0ne and segfault-magnet authored May 22, 2024
1 parent 7f43e07 commit b706076
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 5 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ jobs:
args: --skip-target-dir
- command: test_wasm
args:
- command: check_fuel_core_version
args:
- command: check_doc_anchors_valid
args:
- command: check_doc_unresolved_links
Expand Down Expand Up @@ -236,6 +238,10 @@ jobs:
cd wasm-tests
wasm-pack test --node
- name: Check that fuel_core version.rs file is up to date
if: ${{ matrix.command == 'check_fuel_core_version' }}
run: cargo run --bin fuel-core-version -- --manifest-path ./Cargo.toml verify

- name: Check for invalid documentation anchors
if: ${{ matrix.command == 'check_doc_anchors_valid' }}
run: cargo run --bin check-docs
Expand Down
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ members = [
"packages/fuels-programs",
"packages/fuels-test-helpers",
"scripts/check-docs",
"scripts/fuel-core-version",
"scripts/versions-replacer",
"wasm-tests",
]
Expand Down Expand Up @@ -100,3 +101,4 @@ fuels-core = { version = "0.62.0", path = "./packages/fuels-core", default-featu
fuels-macros = { version = "0.62.0", path = "./packages/fuels-macros", default-features = false }
fuels-programs = { version = "0.62.0", path = "./packages/fuels-programs", default-features = false }
fuels-test-helpers = { version = "0.62.0", path = "./packages/fuels-test-helpers", default-features = false }
versions-replacer = { version = "0.62.0", path = "./scripts/versions-replacer", default-features = false }
8 changes: 3 additions & 5 deletions packages/fuels-accounts/src/provider/supported_versions.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use semver::Version;

fn get_supported_fuel_core_version() -> Version {
"0.26.0".parse().expect("is valid version")
}
pub const SUPPORTED_FUEL_CORE_VERSION: Version =
include!("../../../../scripts/fuel-core-version/version.rs");

#[derive(Debug, PartialEq, Eq)]
pub(crate) struct VersionCompatibility {
Expand All @@ -13,8 +12,7 @@ pub(crate) struct VersionCompatibility {
}

pub(crate) fn compare_node_compatibility(network_version: Version) -> VersionCompatibility {
let supported_version = get_supported_fuel_core_version();
check_version_compatibility(network_version, supported_version)
check_version_compatibility(network_version, SUPPORTED_FUEL_CORE_VERSION)
}

fn check_version_compatibility(
Expand Down
16 changes: 16 additions & 0 deletions scripts/fuel-core-version/Cargo.toml
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 }
84 changes: 84 additions & 0 deletions scripts/fuel-core-version/src/main.rs
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(())
}
1 change: 1 addition & 0 deletions scripts/fuel-core-version/version.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Version::new(0, 26, 0)

0 comments on commit b706076

Please sign in to comment.