From 06c95f36716d4ba75421de8cc83c0934321ebdd1 Mon Sep 17 00:00:00 2001 From: Oleksii Filonenko Date: Mon, 21 Aug 2023 18:28:31 +0300 Subject: [PATCH 01/19] chore(docs): use variables for docs.rs links Now docs.rs links are versioned using `mdbook-variables` preprocessor. --- docs/book.toml | 4 ++++ docs/src/calling-contracts/call-params.md | 2 +- docs/src/connecting/querying.md | 2 +- docs/src/reference.md | 2 +- docs/src/types/address.md | 2 +- docs/src/types/asset-id.md | 2 +- docs/src/types/bytes32.md | 2 +- docs/src/types/contract-id.md | 2 +- 8 files changed, 11 insertions(+), 7 deletions(-) diff --git a/docs/book.toml b/docs/book.toml index 8aee94214b..ecf76a2ec7 100644 --- a/docs/book.toml +++ b/docs/book.toml @@ -10,3 +10,7 @@ git-repository-url = "https://github.com/FuelLabs/fuels-rs" [rust] edition = "2021" + +[preprocessor.variables.variables.versions] +fuels = "0.46.0" +types = "0.35.3" diff --git a/docs/src/calling-contracts/call-params.md b/docs/src/calling-contracts/call-params.md index 75d0198977..27506ca255 100644 --- a/docs/src/calling-contracts/call-params.md +++ b/docs/src/calling-contracts/call-params.md @@ -9,7 +9,7 @@ The parameters for a contract call are: 3. Gas forwarded -You can use these to forward coins to a contract. You can configure these parameters by creating an instance of [`CallParameters`](https://docs.rs/fuels/latest/fuels/programs/contract/struct.CallParameters.html) and passing it to a chain method called `call_params`. +You can use these to forward coins to a contract. You can configure these parameters by creating an instance of [`CallParameters`](https://docs.rs/fuels/{{versions.fuels}}/fuels/programs/contract/struct.CallParameters.html) and passing it to a chain method called `call_params`. For instance, suppose the following contract that uses Sway's `msg_amount()` to return the amount sent in that transaction. diff --git a/docs/src/connecting/querying.md b/docs/src/connecting/querying.md index 7f3dfbe8bc..244d20b693 100644 --- a/docs/src/connecting/querying.md +++ b/docs/src/connecting/querying.md @@ -1,6 +1,6 @@ # Querying the blockchain -Once you set up a provider, you can interact with the Fuel blockchain. Here are a few examples of what you can do with a provider; for a more in-depth overview of the API, check the [official provider API documentation](https://docs.rs/fuels/latest/fuels/accounts/provider/struct.Provider.html). +Once you set up a provider, you can interact with the Fuel blockchain. Here are a few examples of what you can do with a provider; for a more in-depth overview of the API, check the [official provider API documentation](https://docs.rs/fuels/{{versions.fuels}}/fuels/accounts/provider/struct.Provider.html). - [Set up](#set-up) - [Get all coins from an address](#get-all-coins-from-an-address) diff --git a/docs/src/reference.md b/docs/src/reference.md index f031a27969..f9f76c7911 100644 --- a/docs/src/reference.md +++ b/docs/src/reference.md @@ -1,3 +1,3 @@ # API Reference -For a more in-depth look at the APIs provided by the Fuel Rust SDK, head over to the [official documentation](https://docs.rs/fuels/latest/fuels/). In the actual Rust docs, you can see the most up-to-date information about the API, which is synced with the code as it changes. +For a more in-depth look at the APIs provided by the Fuel Rust SDK, head over to the [official documentation](https://docs.rs/fuels/{{versions.fuels}}/fuels/). In the actual Rust docs, you can see the most up-to-date information about the API, which is synced with the code as it changes. diff --git a/docs/src/types/address.md b/docs/src/types/address.md index 2480a72918..35dd960d69 100644 --- a/docs/src/types/address.md +++ b/docs/src/types/address.md @@ -1,6 +1,6 @@ # Address -Like `Bytes32`, `Address` is a wrapper on `[u8; 32]` with similar methods and implements the same traits (see [fuel-types documentation](https://docs.rs/fuel-types/latest/fuel_types/struct.Address.html)). +Like `Bytes32`, `Address` is a wrapper on `[u8; 32]` with similar methods and implements the same traits (see [fuel-types documentation](https://docs.rs/fuel-types/{{versions.types}}/fuel_types/struct.Address.html)). These are the main ways of creating an `Address`: diff --git a/docs/src/types/asset-id.md b/docs/src/types/asset-id.md index ff7affce22..80465a3308 100644 --- a/docs/src/types/asset-id.md +++ b/docs/src/types/asset-id.md @@ -1,6 +1,6 @@ # AssetId -Like `Bytes32`, `AssetId` is a wrapper on `[u8; 32]` with similar methods and implements the same traits (see [fuel-types documentation](https://docs.rs/fuel-types/latest/fuel_types/struct.AssetId.html)). +Like `Bytes32`, `AssetId` is a wrapper on `[u8; 32]` with similar methods and implements the same traits (see [fuel-types documentation](https://docs.rs/fuel-types/{{versions.types}}/fuel_types/struct.AssetId.html)). These are the main ways of creating an `AssetId`: diff --git a/docs/src/types/bytes32.md b/docs/src/types/bytes32.md index 87fc801db1..f130c2234d 100644 --- a/docs/src/types/bytes32.md +++ b/docs/src/types/bytes32.md @@ -14,6 +14,6 @@ These are the main ways of creating a `Bytes32`: {{#include ../../../examples/types/src/lib.rs:bytes32_format}} ``` -For a full list of implemented methods and traits, see the [fuel-types documentation](https://docs.rs/fuel-types/latest/fuel_types/struct.Bytes32.html). +For a full list of implemented methods and traits, see the [fuel-types documentation](https://docs.rs/fuel-types/{{versions.types}}/fuel_types/struct.Bytes32.html). > **Note:** In Fuel, there's a special type called `b256`, which is similar to `Bytes32`; also used to represent hashes, and it holds a 256-bit value. In Rust, through the SDK, this is represented as `Bits256(value)` where `value` is a `[u8; 32]`. If your contract method takes a `b256` as input, all you need to do is pass a `Bits256([u8; 32])` when calling it from the SDK. diff --git a/docs/src/types/contract-id.md b/docs/src/types/contract-id.md index 6a16e38e38..093ba47bcb 100644 --- a/docs/src/types/contract-id.md +++ b/docs/src/types/contract-id.md @@ -1,6 +1,6 @@ # ContractId -Like `Bytes32`, `ContractId` is a wrapper on `[u8; 32]` with similar methods and implements the same traits (see [fuel-types documentation](https://docs.rs/fuel-types/latest/fuel_types/struct.ContractId.html)). +Like `Bytes32`, `ContractId` is a wrapper on `[u8; 32]` with similar methods and implements the same traits (see [fuel-types documentation](https://docs.rs/fuel-types/{{versions.types}}/fuel_types/struct.ContractId.html)). These are the main ways of creating a `ContractId`: From 4d38507dfbe57b6a87e5592e23da1c9b698b753b Mon Sep 17 00:00:00 2001 From: Oleksii Filonenko Date: Mon, 21 Aug 2023 21:11:06 +0300 Subject: [PATCH 02/19] fix(ci): add mdbook-variables to gh-pages workflow --- .github/workflows/gh-pages.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/gh-pages.yml b/.github/workflows/gh-pages.yml index 4218be72ee..304ab4d8c3 100644 --- a/.github/workflows/gh-pages.yml +++ b/.github/workflows/gh-pages.yml @@ -18,6 +18,12 @@ jobs: with: mdbook-version: "0.4.15" + - name: Install mdbook-variables preprocessor + uses: baptiste0928/cargo-install@v2 + with: + crate: mdbook-variables + version: "0.2.2" + - run: mdbook build docs - name: Deploy master From f7702422ed46a433f8864d8ba0a9f4c2eaf43038 Mon Sep 17 00:00:00 2001 From: Oleksii Filonenko Date: Mon, 21 Aug 2023 21:16:24 +0300 Subject: [PATCH 03/19] docs: mention mdbook-variables in README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ec3e982ee6..e2ac96b767 100644 --- a/README.md +++ b/README.md @@ -86,7 +86,7 @@ In order to make the SDK for Fuel feel familiar with those coming from the [ethe Install `mdbook` by running: ```shell -cargo install mdbook +cargo install mdbook mdbook-variables ``` Next, navigate to the `docs` folder and run the command below to start a local server and open a new tab in you browser. From f3845e5459faa2f89bd228de538acf864a1eeda6 Mon Sep 17 00:00:00 2001 From: Oleksii Filonenko Date: Tue, 22 Aug 2023 23:34:26 +0300 Subject: [PATCH 04/19] docs: use fuels_types name (with underscore) --- docs/book.toml | 2 +- docs/src/types/address.md | 2 +- docs/src/types/asset-id.md | 2 +- docs/src/types/bytes32.md | 2 +- docs/src/types/contract-id.md | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/book.toml b/docs/book.toml index ecf76a2ec7..9a3d326013 100644 --- a/docs/book.toml +++ b/docs/book.toml @@ -13,4 +13,4 @@ edition = "2021" [preprocessor.variables.variables.versions] fuels = "0.46.0" -types = "0.35.3" +fuels_types = "0.35.3" diff --git a/docs/src/types/address.md b/docs/src/types/address.md index 35dd960d69..31da7dadab 100644 --- a/docs/src/types/address.md +++ b/docs/src/types/address.md @@ -1,6 +1,6 @@ # Address -Like `Bytes32`, `Address` is a wrapper on `[u8; 32]` with similar methods and implements the same traits (see [fuel-types documentation](https://docs.rs/fuel-types/{{versions.types}}/fuel_types/struct.Address.html)). +Like `Bytes32`, `Address` is a wrapper on `[u8; 32]` with similar methods and implements the same traits (see [fuel-types documentation](https://docs.rs/fuel-types/{{versions.fuels_types}}/fuel_types/struct.Address.html)). These are the main ways of creating an `Address`: diff --git a/docs/src/types/asset-id.md b/docs/src/types/asset-id.md index 80465a3308..387f3dc6dc 100644 --- a/docs/src/types/asset-id.md +++ b/docs/src/types/asset-id.md @@ -1,6 +1,6 @@ # AssetId -Like `Bytes32`, `AssetId` is a wrapper on `[u8; 32]` with similar methods and implements the same traits (see [fuel-types documentation](https://docs.rs/fuel-types/{{versions.types}}/fuel_types/struct.AssetId.html)). +Like `Bytes32`, `AssetId` is a wrapper on `[u8; 32]` with similar methods and implements the same traits (see [fuel-types documentation](https://docs.rs/fuel-types/{{versions.fuels_types}}/fuel_types/struct.AssetId.html)). These are the main ways of creating an `AssetId`: diff --git a/docs/src/types/bytes32.md b/docs/src/types/bytes32.md index f130c2234d..bdd6db05ef 100644 --- a/docs/src/types/bytes32.md +++ b/docs/src/types/bytes32.md @@ -14,6 +14,6 @@ These are the main ways of creating a `Bytes32`: {{#include ../../../examples/types/src/lib.rs:bytes32_format}} ``` -For a full list of implemented methods and traits, see the [fuel-types documentation](https://docs.rs/fuel-types/{{versions.types}}/fuel_types/struct.Bytes32.html). +For a full list of implemented methods and traits, see the [fuel-types documentation](https://docs.rs/fuel-types/{{versions.fuels_types}}/fuel_types/struct.Bytes32.html). > **Note:** In Fuel, there's a special type called `b256`, which is similar to `Bytes32`; also used to represent hashes, and it holds a 256-bit value. In Rust, through the SDK, this is represented as `Bits256(value)` where `value` is a `[u8; 32]`. If your contract method takes a `b256` as input, all you need to do is pass a `Bits256([u8; 32])` when calling it from the SDK. diff --git a/docs/src/types/contract-id.md b/docs/src/types/contract-id.md index 093ba47bcb..84b65e248b 100644 --- a/docs/src/types/contract-id.md +++ b/docs/src/types/contract-id.md @@ -1,6 +1,6 @@ # ContractId -Like `Bytes32`, `ContractId` is a wrapper on `[u8; 32]` with similar methods and implements the same traits (see [fuel-types documentation](https://docs.rs/fuel-types/{{versions.types}}/fuel_types/struct.ContractId.html)). +Like `Bytes32`, `ContractId` is a wrapper on `[u8; 32]` with similar methods and implements the same traits (see [fuel-types documentation](https://docs.rs/fuel-types/{{versions.fuels_types}}/fuel_types/struct.ContractId.html)). These are the main ways of creating a `ContractId`: From 0971a18e0b7160a4cee07713e0a03ff0c6b28436 Mon Sep 17 00:00:00 2001 From: Oleksii Filonenko Date: Tue, 22 Aug 2023 23:36:38 +0300 Subject: [PATCH 05/19] docs: shorten fuels version to just MAJOR.MINOR --- docs/book.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/book.toml b/docs/book.toml index 9a3d326013..525adaae5d 100644 --- a/docs/book.toml +++ b/docs/book.toml @@ -12,5 +12,5 @@ git-repository-url = "https://github.com/FuelLabs/fuels-rs" edition = "2021" [preprocessor.variables.variables.versions] -fuels = "0.46.0" +fuels = "0.46" fuels_types = "0.35.3" From 151a511f98614c489c63bc95e642af588ed54c37 Mon Sep 17 00:00:00 2001 From: Oleksii Filonenko Date: Tue, 22 Aug 2023 23:36:53 +0300 Subject: [PATCH 06/19] docs: replace fuels version in getting-started.md --- docs/src/getting-started.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/src/getting-started.md b/docs/src/getting-started.md index 02529d1e19..d31ca6ccf1 100644 --- a/docs/src/getting-started.md +++ b/docs/src/getting-started.md @@ -91,10 +91,10 @@ cargo test -- --nocapture Add these dependencies on your `Cargo.toml`: ```toml -fuels = "0.46" +fuels = "{{versions.fuels}}" ``` -> **Note** We're using version `0.46` of the SDK, which is the latest version at the time of this writing. +> **Note** We're using version `{{versions.fuels}}` of the SDK, which is the latest version at the time of this writing. And then, in your Rust file that's going to make use of the SDK: From 9518df9fa0e32ea1cf0bc95ee14eacf76dad80fc Mon Sep 17 00:00:00 2001 From: Oleksii Filonenko Date: Thu, 31 Aug 2023 21:41:46 +0300 Subject: [PATCH 07/19] scripts: add version replacer script --- Cargo.toml | 4 ++ docs/src/types/address.md | 2 +- docs/src/types/asset-id.md | 2 +- docs/src/types/bytes32.md | 2 +- docs/src/types/contract-id.md | 2 +- scripts/versions-replacer/Cargo.toml | 21 +++++++++ scripts/versions-replacer/src/lib.rs | 2 + scripts/versions-replacer/src/main.rs | 55 +++++++++++++++++++++++ scripts/versions-replacer/src/metadata.rs | 42 +++++++++++++++++ scripts/versions-replacer/src/replace.rs | 22 +++++++++ 10 files changed, 150 insertions(+), 4 deletions(-) create mode 100644 scripts/versions-replacer/Cargo.toml create mode 100644 scripts/versions-replacer/src/lib.rs create mode 100644 scripts/versions-replacer/src/main.rs create mode 100644 scripts/versions-replacer/src/metadata.rs create mode 100644 scripts/versions-replacer/src/replace.rs diff --git a/Cargo.toml b/Cargo.toml index 9bfd08e275..36273aeb57 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,6 +24,7 @@ members = [ "packages/fuels-test-helpers", "packages/wasm-tests", "scripts/check-docs", + "scripts/versions-replacer", ] [workspace.package] @@ -90,3 +91,6 @@ fuels-core = { version = "0.46.0", path = "./packages/fuels-core", default-featu fuels-macros = { version = "0.46.0", path = "./packages/fuels-macros", default-features = false } fuels-programs = { version = "0.46.0", path = "./packages/fuels-programs", default-features = false } fuels-test-helpers = { version = "0.46.0", path = "./packages/fuels-test-helpers", default-features = false } + +[workspace.metadata.versions-replacer.external-versions] +fuels-types = "0.35.3" diff --git a/docs/src/types/address.md b/docs/src/types/address.md index 31da7dadab..c95fed2014 100644 --- a/docs/src/types/address.md +++ b/docs/src/types/address.md @@ -1,6 +1,6 @@ # Address -Like `Bytes32`, `Address` is a wrapper on `[u8; 32]` with similar methods and implements the same traits (see [fuel-types documentation](https://docs.rs/fuel-types/{{versions.fuels_types}}/fuel_types/struct.Address.html)). +Like `Bytes32`, `Address` is a wrapper on `[u8; 32]` with similar methods and implements the same traits (see [fuel-types documentation](https://docs.rs/fuel-types/{{versions.fuels-types}}/fuel_types/struct.Address.html)). These are the main ways of creating an `Address`: diff --git a/docs/src/types/asset-id.md b/docs/src/types/asset-id.md index 387f3dc6dc..06aaf3ff77 100644 --- a/docs/src/types/asset-id.md +++ b/docs/src/types/asset-id.md @@ -1,6 +1,6 @@ # AssetId -Like `Bytes32`, `AssetId` is a wrapper on `[u8; 32]` with similar methods and implements the same traits (see [fuel-types documentation](https://docs.rs/fuel-types/{{versions.fuels_types}}/fuel_types/struct.AssetId.html)). +Like `Bytes32`, `AssetId` is a wrapper on `[u8; 32]` with similar methods and implements the same traits (see [fuel-types documentation](https://docs.rs/fuel-types/{{versions.fuels-types}}/fuel_types/struct.AssetId.html)). These are the main ways of creating an `AssetId`: diff --git a/docs/src/types/bytes32.md b/docs/src/types/bytes32.md index bdd6db05ef..e31e0d7757 100644 --- a/docs/src/types/bytes32.md +++ b/docs/src/types/bytes32.md @@ -14,6 +14,6 @@ These are the main ways of creating a `Bytes32`: {{#include ../../../examples/types/src/lib.rs:bytes32_format}} ``` -For a full list of implemented methods and traits, see the [fuel-types documentation](https://docs.rs/fuel-types/{{versions.fuels_types}}/fuel_types/struct.Bytes32.html). +For a full list of implemented methods and traits, see the [fuel-types documentation](https://docs.rs/fuel-types/{{versions.fuels-types}}/fuel_types/struct.Bytes32.html). > **Note:** In Fuel, there's a special type called `b256`, which is similar to `Bytes32`; also used to represent hashes, and it holds a 256-bit value. In Rust, through the SDK, this is represented as `Bits256(value)` where `value` is a `[u8; 32]`. If your contract method takes a `b256` as input, all you need to do is pass a `Bits256([u8; 32])` when calling it from the SDK. diff --git a/docs/src/types/contract-id.md b/docs/src/types/contract-id.md index 84b65e248b..76516b0b00 100644 --- a/docs/src/types/contract-id.md +++ b/docs/src/types/contract-id.md @@ -1,6 +1,6 @@ # ContractId -Like `Bytes32`, `ContractId` is a wrapper on `[u8; 32]` with similar methods and implements the same traits (see [fuel-types documentation](https://docs.rs/fuel-types/{{versions.fuels_types}}/fuel_types/struct.ContractId.html)). +Like `Bytes32`, `ContractId` is a wrapper on `[u8; 32]` with similar methods and implements the same traits (see [fuel-types documentation](https://docs.rs/fuel-types/{{versions.fuels-types}}/fuel_types/struct.ContractId.html)). These are the main ways of creating a `ContractId`: diff --git a/scripts/versions-replacer/Cargo.toml b/scripts/versions-replacer/Cargo.toml new file mode 100644 index 0000000000..2bd80128e1 --- /dev/null +++ b/scripts/versions-replacer/Cargo.toml @@ -0,0 +1,21 @@ +[package] +name = "versions-replacer" +publish = false +authors.workspace = true +edition.workspace = true +homepage.workspace = true +readme.workspace = true +license.workspace = true +repository.workspace = true +rust-version.workspace = true +version.workspace = true + +[dependencies] +argh = "0.1.12" +cargo_metadata = "0.17.0" +color-eyre = "0.6.2" +once_cell = "1.18.0" +regex = { workspace = true } +serde = { workspace = true, features = ["derive"] } +serde_json = { workspace = true } +walkdir = "2.3.3" diff --git a/scripts/versions-replacer/src/lib.rs b/scripts/versions-replacer/src/lib.rs new file mode 100644 index 0000000000..b019f47b1c --- /dev/null +++ b/scripts/versions-replacer/src/lib.rs @@ -0,0 +1,2 @@ +pub mod metadata; +pub mod replace; diff --git a/scripts/versions-replacer/src/main.rs b/scripts/versions-replacer/src/main.rs new file mode 100644 index 0000000000..327353d8c2 --- /dev/null +++ b/scripts/versions-replacer/src/main.rs @@ -0,0 +1,55 @@ +use std::path::PathBuf; + +use argh::FromArgs; +use color_eyre::{ + eyre::{eyre, Context}, + Result, +}; +use regex::Regex; +use walkdir::WalkDir; + +use versions_replacer::{ + metadata::collect_versions_from_cargo_toml, replace::replace_versions_in_file, +}; + +#[derive(FromArgs)] +/// Replace variables like '{{{{versions.fuels}}}}' with correct versions from Cargo.toml. +/// Uses versions from '[workspace.members]' and '[workspace.metadata.versions-replacer.external-versions]'. +struct VersionsReplacer { + /// path to directory with files containing variables + #[argh(positional)] + path: PathBuf, + /// path to Cargo.toml with versions + #[argh(option)] + manifest_path: PathBuf, + /// regex to filter filenames (example: "\.md$") + #[argh(option)] + filename_regex: Option, +} + +fn main() -> Result<()> { + let args: VersionsReplacer = argh::from_env(); + let versions = collect_versions_from_cargo_toml(&args.manifest_path)?; + + for entry in WalkDir::new(&args.path) { + let entry = entry.wrap_err("failed to get directory entry")?; + + if entry.path().is_file() { + if let Some(filename_regex) = &args.filename_regex { + let file_name = entry + .path() + .file_name() + .ok_or_else(|| eyre!("{:?} has an invalid file name", entry.path()))? + .to_str() + .ok_or_else(|| eyre!("filename is not valid UTF-8"))?; + if !filename_regex.is_match(file_name) { + continue; + } + } + + replace_versions_in_file(entry.path(), &versions) + .wrap_err_with(|| format!("failed to replace versions in {:?}", entry.path()))?; + } + } + Ok(()) +} diff --git a/scripts/versions-replacer/src/metadata.rs b/scripts/versions-replacer/src/metadata.rs new file mode 100644 index 0000000000..878c3fd941 --- /dev/null +++ b/scripts/versions-replacer/src/metadata.rs @@ -0,0 +1,42 @@ +use std::{collections::HashMap, path::Path}; + +use cargo_metadata::MetadataCommand; +use color_eyre::{eyre::Context, Result}; +use serde::Deserialize; + +#[derive(Deserialize)] +#[serde(rename_all = "kebab-case")] +pub struct WorkspaceMetadata { + pub versions_replacer: VersionsReplacerMetadata, +} + +#[derive(Deserialize)] +#[serde(rename_all = "kebab-case")] +pub struct VersionsReplacerMetadata { + pub external_versions: HashMap, +} + +pub fn collect_versions_from_cargo_toml( + manifest_path: impl AsRef, +) -> Result> { + let metadata = MetadataCommand::new() + .manifest_path(manifest_path.as_ref()) + .exec() + .wrap_err("failed to execute 'cargo metadata'")?; + let version_map = metadata + .workspace_members + .iter() + .map(|package_id| { + let package = &metadata[package_id]; + (package.name.clone(), package.version.to_string()) + }) + .chain( + serde_json::from_value::(metadata.workspace_metadata.clone()) + .wrap_err("failed to parse '[workspace.metadata]'")? + .versions_replacer + .external_versions + .into_iter(), + ) + .collect::>(); + Ok(version_map) +} diff --git a/scripts/versions-replacer/src/replace.rs b/scripts/versions-replacer/src/replace.rs new file mode 100644 index 0000000000..5ae46acca2 --- /dev/null +++ b/scripts/versions-replacer/src/replace.rs @@ -0,0 +1,22 @@ +use std::{collections::HashMap, fs, path::Path}; + +use color_eyre::{eyre::Context, Result}; +use once_cell::sync::Lazy; +use regex::{Captures, Regex}; + +pub static VERSIONS_REGEX: Lazy = + Lazy::new(|| Regex::new(r"\{\{versions\.([\w_-]+)\}\}").unwrap()); + +pub fn replace_versions_in_file( + path: impl AsRef, + versions: &HashMap, +) -> Result<()> { + let path = path.as_ref(); + let contents = + fs::read_to_string(path).wrap_err_with(|| format!("failed to read {:?}", path))?; + let replaced_contents = + VERSIONS_REGEX.replace_all(&contents, |caps: &Captures| &versions[&caps[1]]); + fs::write(path, replaced_contents.as_bytes()) + .wrap_err_with(|| format!("failed to write back to {:?}", path))?; + Ok(()) +} From 91b8e4539338c0574e2ef1b486c8ae434c532975 Mon Sep 17 00:00:00 2001 From: Oleksii Filonenko Date: Thu, 31 Aug 2023 21:57:35 +0300 Subject: [PATCH 08/19] docs: remove mdbook-variables mentions --- .github/workflows/gh-pages.yml | 6 ------ README.md | 2 +- docs/book.toml | 4 ---- 3 files changed, 1 insertion(+), 11 deletions(-) diff --git a/.github/workflows/gh-pages.yml b/.github/workflows/gh-pages.yml index 304ab4d8c3..4218be72ee 100644 --- a/.github/workflows/gh-pages.yml +++ b/.github/workflows/gh-pages.yml @@ -18,12 +18,6 @@ jobs: with: mdbook-version: "0.4.15" - - name: Install mdbook-variables preprocessor - uses: baptiste0928/cargo-install@v2 - with: - crate: mdbook-variables - version: "0.2.2" - - run: mdbook build docs - name: Deploy master diff --git a/README.md b/README.md index e2ac96b767..ec3e982ee6 100644 --- a/README.md +++ b/README.md @@ -86,7 +86,7 @@ In order to make the SDK for Fuel feel familiar with those coming from the [ethe Install `mdbook` by running: ```shell -cargo install mdbook mdbook-variables +cargo install mdbook ``` Next, navigate to the `docs` folder and run the command below to start a local server and open a new tab in you browser. diff --git a/docs/book.toml b/docs/book.toml index 525adaae5d..8aee94214b 100644 --- a/docs/book.toml +++ b/docs/book.toml @@ -10,7 +10,3 @@ git-repository-url = "https://github.com/FuelLabs/fuels-rs" [rust] edition = "2021" - -[preprocessor.variables.variables.versions] -fuels = "0.46" -fuels_types = "0.35.3" From d8d9092e921ffa4d92d857e55b45e1173eb8e269 Mon Sep 17 00:00:00 2001 From: Oleksii Filonenko Date: Thu, 31 Aug 2023 22:55:07 +0300 Subject: [PATCH 09/19] change to test branch of docs action --- .github/workflows/docs.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 9ac97b413b..6f9af02d05 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -10,7 +10,6 @@ on: jobs: test: - uses: FuelLabs/github-actions/.github/workflows/mdbook-docs.yml@master + uses: FuelLabs/github-actions/.github/workflows/mdbook-docs.yml@mdbook-docs-pre-command with: - docs-src-path: 'docs/src' - + docs-src-path: "docs/src" From 7479a7be84dc7386e23f58e5791a59e914dfa0f7 Mon Sep 17 00:00:00 2001 From: Oleksii Filonenko Date: Thu, 31 Aug 2023 23:09:03 +0300 Subject: [PATCH 10/19] ci: add pre-command input to docs.yml --- .github/workflows/docs.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 6f9af02d05..325f9f1428 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -13,3 +13,4 @@ jobs: uses: FuelLabs/github-actions/.github/workflows/mdbook-docs.yml@mdbook-docs-pre-command with: docs-src-path: "docs/src" + pre-command: 'cargo run --package versions-replacer -- ./docs --manifest-path ./Cargo.toml --filename-regex "\.md$"' From 9f6277baf9cb9c27e52744c43d47a73aff99c390 Mon Sep 17 00:00:00 2001 From: Oleksii Filonenko Date: Fri, 1 Sep 2023 11:43:51 +0300 Subject: [PATCH 11/19] count replacements, overwrite files on change only --- scripts/versions-replacer/src/main.rs | 15 +++++++++++++-- scripts/versions-replacer/src/replace.rs | 19 +++++++++++++------ 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/scripts/versions-replacer/src/main.rs b/scripts/versions-replacer/src/main.rs index 327353d8c2..02900e5a5b 100644 --- a/scripts/versions-replacer/src/main.rs +++ b/scripts/versions-replacer/src/main.rs @@ -31,6 +31,8 @@ fn main() -> Result<()> { let args: VersionsReplacer = argh::from_env(); let versions = collect_versions_from_cargo_toml(&args.manifest_path)?; + let mut total_replacements: Vec = Vec::new(); + for entry in WalkDir::new(&args.path) { let entry = entry.wrap_err("failed to get directory entry")?; @@ -47,9 +49,18 @@ fn main() -> Result<()> { } } - replace_versions_in_file(entry.path(), &versions) - .wrap_err_with(|| format!("failed to replace versions in {:?}", entry.path()))?; + if let Some(replacement_count) = replace_versions_in_file(entry.path(), &versions) + .wrap_err_with(|| format!("failed to replace versions in {:?}", entry.path()))? + { + total_replacements.push(replacement_count); + } } } + + println!( + "replaced {} variables across {} files", + total_replacements.iter().sum::(), + total_replacements.len() + ); Ok(()) } diff --git a/scripts/versions-replacer/src/replace.rs b/scripts/versions-replacer/src/replace.rs index 5ae46acca2..baa4e9650d 100644 --- a/scripts/versions-replacer/src/replace.rs +++ b/scripts/versions-replacer/src/replace.rs @@ -10,13 +10,20 @@ pub static VERSIONS_REGEX: Lazy = pub fn replace_versions_in_file( path: impl AsRef, versions: &HashMap, -) -> Result<()> { +) -> Result> { let path = path.as_ref(); let contents = fs::read_to_string(path).wrap_err_with(|| format!("failed to read {:?}", path))?; - let replaced_contents = - VERSIONS_REGEX.replace_all(&contents, |caps: &Captures| &versions[&caps[1]]); - fs::write(path, replaced_contents.as_bytes()) - .wrap_err_with(|| format!("failed to write back to {:?}", path))?; - Ok(()) + let mut replacement_count = 0; + let replaced_contents = VERSIONS_REGEX.replace_all(&contents, |caps: &Captures| { + replacement_count += 1; + &versions[&caps[1]] + }); + if replaced_contents != contents { + fs::write(path, replaced_contents.as_bytes()) + .wrap_err_with(|| format!("failed to write back to {:?}", path))?; + Ok(Some(replacement_count)) + } else { + Ok(None) + } } From 5ccdbeefeb21a52641d8cf9626a75b0518025ec9 Mon Sep 17 00:00:00 2001 From: Oleksii Filonenko Date: Fri, 1 Sep 2023 12:09:56 +0300 Subject: [PATCH 12/19] add unit tests --- scripts/versions-replacer/src/replace.rs | 79 +++++++++++++++++++++--- 1 file changed, 69 insertions(+), 10 deletions(-) diff --git a/scripts/versions-replacer/src/replace.rs b/scripts/versions-replacer/src/replace.rs index baa4e9650d..97cc3d2d70 100644 --- a/scripts/versions-replacer/src/replace.rs +++ b/scripts/versions-replacer/src/replace.rs @@ -1,4 +1,4 @@ -use std::{collections::HashMap, fs, path::Path}; +use std::{borrow::Cow, collections::HashMap, fs, path::Path}; use color_eyre::{eyre::Context, Result}; use once_cell::sync::Lazy; @@ -14,16 +14,75 @@ pub fn replace_versions_in_file( let path = path.as_ref(); let contents = fs::read_to_string(path).wrap_err_with(|| format!("failed to read {:?}", path))?; - let mut replacement_count = 0; - let replaced_contents = VERSIONS_REGEX.replace_all(&contents, |caps: &Captures| { - replacement_count += 1; - &versions[&caps[1]] - }); - if replaced_contents != contents { + let (replaced_contents, replacement_count) = replace_versions_in_string(&contents, versions); + if replacement_count.is_some() { fs::write(path, replaced_contents.as_bytes()) .wrap_err_with(|| format!("failed to write back to {:?}", path))?; - Ok(Some(replacement_count)) - } else { - Ok(None) + } + Ok(replacement_count) +} + +pub fn replace_versions_in_string<'a>( + s: &'a str, + versions: &HashMap, +) -> (Cow<'a, str>, Option) { + let mut replacement_count = 0; + let replaced_s = VERSIONS_REGEX.replace_all(s, |caps: &Captures| { + if let Some(version) = versions.get(&caps[1]) { + replacement_count += 1; + version.clone() + } else { + // leave unchanged + caps[0].to_string() + } + }); + let replacement_count = (replaced_s != s).then_some(replacement_count); + (replaced_s, replacement_count) +} + +#[cfg(test)] +mod tests { + use super::*; + + fn test_versions() -> HashMap { + [("fuels", "0.47.0"), ("fuels-types", "0.35.3")] + .into_iter() + .map(|(name, version)| (name.to_string(), version.to_string())) + .collect() + } + + #[test] + fn test_valid_replacements() { + let s = "docs.rs/fuels/{{versions.fuels}}/fuels\ndocs.rs/fuels-types/{{versions.fuels-types}}/fuels-types"; + let versions = test_versions(); + let (replaced, count) = replace_versions_in_string(s, &versions); + assert_eq!( + replaced, + format!( + "docs.rs/fuels/{}/fuels\ndocs.rs/fuels-types/{}/fuels-types", + versions["fuels"], versions["fuels-types"] + ) + ); + assert_eq!(count, Some(2)); + } + + #[test] + fn test_invalid_replacement() { + let s = "```rust,ignore +{{#include ../../../examples/contracts/src/lib.rs:deployed_contracts}} +```"; + let versions = test_versions(); + let (replaced, count) = replace_versions_in_string(s, &versions); + assert_eq!(replaced, s); + assert!(count.is_none()); + } + + #[test] + fn test_invalid_package_name() { + let s = "docs.rs/fuels-wrong-name/{{versions.fuels-wrong-name}}/fuels-wrong-name"; + let versions = test_versions(); + let (replaced, count) = replace_versions_in_string(s, &versions); + assert_eq!(replaced, s); + assert_eq!(count, None); } } From 40b16b0cb3f933c7e5ab4ed363bddbd0e2930266 Mon Sep 17 00:00:00 2001 From: Oleksii Filonenko Date: Fri, 1 Sep 2023 12:12:36 +0300 Subject: [PATCH 13/19] normalize test code --- scripts/versions-replacer/src/replace.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/versions-replacer/src/replace.rs b/scripts/versions-replacer/src/replace.rs index 97cc3d2d70..95f12971ba 100644 --- a/scripts/versions-replacer/src/replace.rs +++ b/scripts/versions-replacer/src/replace.rs @@ -83,6 +83,6 @@ mod tests { let versions = test_versions(); let (replaced, count) = replace_versions_in_string(s, &versions); assert_eq!(replaced, s); - assert_eq!(count, None); + assert!(count.is_none()); } } From df719e54f0eea73d4774534983729e5787f71d9f Mon Sep 17 00:00:00 2001 From: Oleksii Filonenko Date: Fri, 1 Sep 2023 20:20:50 +0300 Subject: [PATCH 14/19] Use master branch of docs workflow --- .github/workflows/docs.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 325f9f1428..f086e8586e 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -10,7 +10,7 @@ on: jobs: test: - uses: FuelLabs/github-actions/.github/workflows/mdbook-docs.yml@mdbook-docs-pre-command + uses: FuelLabs/github-actions/.github/workflows/mdbook-docs.yml@master with: docs-src-path: "docs/src" pre-command: 'cargo run --package versions-replacer -- ./docs --manifest-path ./Cargo.toml --filename-regex "\.md$"' From 664422bcb4805b692878b2a3384f6b5d948638c1 Mon Sep 17 00:00:00 2001 From: Oleksii Filonenko Date: Thu, 7 Sep 2023 14:01:53 +0300 Subject: [PATCH 15/19] Apply suggestions from code review Co-authored-by: Ahmed Sagdati <37515857+segfault-magnet@users.noreply.github.com> --- scripts/versions-replacer/src/metadata.rs | 1 - scripts/versions-replacer/src/replace.rs | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/scripts/versions-replacer/src/metadata.rs b/scripts/versions-replacer/src/metadata.rs index 878c3fd941..415835106e 100644 --- a/scripts/versions-replacer/src/metadata.rs +++ b/scripts/versions-replacer/src/metadata.rs @@ -35,7 +35,6 @@ pub fn collect_versions_from_cargo_toml( .wrap_err("failed to parse '[workspace.metadata]'")? .versions_replacer .external_versions - .into_iter(), ) .collect::>(); Ok(version_map) diff --git a/scripts/versions-replacer/src/replace.rs b/scripts/versions-replacer/src/replace.rs index 95f12971ba..244bfa475c 100644 --- a/scripts/versions-replacer/src/replace.rs +++ b/scripts/versions-replacer/src/replace.rs @@ -46,9 +46,8 @@ mod tests { fn test_versions() -> HashMap { [("fuels", "0.47.0"), ("fuels-types", "0.35.3")] - .into_iter() .map(|(name, version)| (name.to_string(), version.to_string())) - .collect() + .into() } #[test] From 9a306f3168c22e1d56461e01fa2cc0d47e6c581e Mon Sep 17 00:00:00 2001 From: Oleksii Filonenko Date: Thu, 7 Sep 2023 14:17:17 +0300 Subject: [PATCH 16/19] use 0 instead of None for "no replacements" --- scripts/versions-replacer/src/main.rs | 6 +++--- scripts/versions-replacer/src/replace.rs | 13 ++++++------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/scripts/versions-replacer/src/main.rs b/scripts/versions-replacer/src/main.rs index 02900e5a5b..a5d420e1b1 100644 --- a/scripts/versions-replacer/src/main.rs +++ b/scripts/versions-replacer/src/main.rs @@ -49,9 +49,9 @@ fn main() -> Result<()> { } } - if let Some(replacement_count) = replace_versions_in_file(entry.path(), &versions) - .wrap_err_with(|| format!("failed to replace versions in {:?}", entry.path()))? - { + let replacement_count = replace_versions_in_file(entry.path(), &versions) + .wrap_err_with(|| format!("failed to replace versions in {:?}", entry.path()))?; + if replacement_count > 0 { total_replacements.push(replacement_count); } } diff --git a/scripts/versions-replacer/src/replace.rs b/scripts/versions-replacer/src/replace.rs index 244bfa475c..5090bd08cf 100644 --- a/scripts/versions-replacer/src/replace.rs +++ b/scripts/versions-replacer/src/replace.rs @@ -10,12 +10,12 @@ pub static VERSIONS_REGEX: Lazy = pub fn replace_versions_in_file( path: impl AsRef, versions: &HashMap, -) -> Result> { +) -> Result { let path = path.as_ref(); let contents = fs::read_to_string(path).wrap_err_with(|| format!("failed to read {:?}", path))?; let (replaced_contents, replacement_count) = replace_versions_in_string(&contents, versions); - if replacement_count.is_some() { + if replacement_count > 0 { fs::write(path, replaced_contents.as_bytes()) .wrap_err_with(|| format!("failed to write back to {:?}", path))?; } @@ -25,7 +25,7 @@ pub fn replace_versions_in_file( pub fn replace_versions_in_string<'a>( s: &'a str, versions: &HashMap, -) -> (Cow<'a, str>, Option) { +) -> (Cow<'a, str>, usize) { let mut replacement_count = 0; let replaced_s = VERSIONS_REGEX.replace_all(s, |caps: &Captures| { if let Some(version) = versions.get(&caps[1]) { @@ -36,7 +36,6 @@ pub fn replace_versions_in_string<'a>( caps[0].to_string() } }); - let replacement_count = (replaced_s != s).then_some(replacement_count); (replaced_s, replacement_count) } @@ -62,7 +61,7 @@ mod tests { versions["fuels"], versions["fuels-types"] ) ); - assert_eq!(count, Some(2)); + assert_eq!(count, 2); } #[test] @@ -73,7 +72,7 @@ mod tests { let versions = test_versions(); let (replaced, count) = replace_versions_in_string(s, &versions); assert_eq!(replaced, s); - assert!(count.is_none()); + assert_eq!(count, 0); } #[test] @@ -82,6 +81,6 @@ mod tests { let versions = test_versions(); let (replaced, count) = replace_versions_in_string(s, &versions); assert_eq!(replaced, s); - assert!(count.is_none()); + assert_eq!(count, 0); } } From 4c7f6066e8b9ae527363b611ac6ad6695f518799 Mon Sep 17 00:00:00 2001 From: Oleksii Filonenko Date: Thu, 7 Sep 2023 14:18:52 +0300 Subject: [PATCH 17/19] cargo fmt --- scripts/versions-replacer/src/metadata.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/versions-replacer/src/metadata.rs b/scripts/versions-replacer/src/metadata.rs index 415835106e..9a2adc10b0 100644 --- a/scripts/versions-replacer/src/metadata.rs +++ b/scripts/versions-replacer/src/metadata.rs @@ -34,7 +34,7 @@ pub fn collect_versions_from_cargo_toml( serde_json::from_value::(metadata.workspace_metadata.clone()) .wrap_err("failed to parse '[workspace.metadata]'")? .versions_replacer - .external_versions + .external_versions, ) .collect::>(); Ok(version_map) From 53ebf5c864d8c2419a0bba2cd8972cc5cb3759c0 Mon Sep 17 00:00:00 2001 From: Oleksii Filonenko Date: Thu, 7 Sep 2023 22:18:01 +0300 Subject: [PATCH 18/19] Remove `external-versions` metadata table --- Cargo.toml | 3 --- docs/src/types/address.md | 2 +- docs/src/types/asset-id.md | 2 +- docs/src/types/bytes32.md | 2 +- docs/src/types/contract-id.md | 2 +- scripts/versions-replacer/src/metadata.rs | 13 ++----------- scripts/versions-replacer/src/replace.rs | 8 ++++---- 7 files changed, 10 insertions(+), 22 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f10d1b7570..79b319bee5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -91,6 +91,3 @@ fuels-core = { version = "0.47.0", path = "./packages/fuels-core", default-featu fuels-macros = { version = "0.47.0", path = "./packages/fuels-macros", default-features = false } fuels-programs = { version = "0.47.0", path = "./packages/fuels-programs", default-features = false } fuels-test-helpers = { version = "0.47.0", path = "./packages/fuels-test-helpers", default-features = false } - -[workspace.metadata.versions-replacer.external-versions] -fuels-types = "0.35.3" diff --git a/docs/src/types/address.md b/docs/src/types/address.md index c95fed2014..3aac7381f5 100644 --- a/docs/src/types/address.md +++ b/docs/src/types/address.md @@ -1,6 +1,6 @@ # Address -Like `Bytes32`, `Address` is a wrapper on `[u8; 32]` with similar methods and implements the same traits (see [fuel-types documentation](https://docs.rs/fuel-types/{{versions.fuels-types}}/fuel_types/struct.Address.html)). +Like `Bytes32`, `Address` is a wrapper on `[u8; 32]` with similar methods and implements the same traits (see [fuel-types documentation](https://docs.rs/fuel-types/{{versions.fuel-types}}/fuel_types/struct.Address.html)). These are the main ways of creating an `Address`: diff --git a/docs/src/types/asset-id.md b/docs/src/types/asset-id.md index 06aaf3ff77..71f43348aa 100644 --- a/docs/src/types/asset-id.md +++ b/docs/src/types/asset-id.md @@ -1,6 +1,6 @@ # AssetId -Like `Bytes32`, `AssetId` is a wrapper on `[u8; 32]` with similar methods and implements the same traits (see [fuel-types documentation](https://docs.rs/fuel-types/{{versions.fuels-types}}/fuel_types/struct.AssetId.html)). +Like `Bytes32`, `AssetId` is a wrapper on `[u8; 32]` with similar methods and implements the same traits (see [fuel-types documentation](https://docs.rs/fuel-types/{{versions.fuel-types}}/fuel_types/struct.AssetId.html)). These are the main ways of creating an `AssetId`: diff --git a/docs/src/types/bytes32.md b/docs/src/types/bytes32.md index e31e0d7757..041fc2d46e 100644 --- a/docs/src/types/bytes32.md +++ b/docs/src/types/bytes32.md @@ -14,6 +14,6 @@ These are the main ways of creating a `Bytes32`: {{#include ../../../examples/types/src/lib.rs:bytes32_format}} ``` -For a full list of implemented methods and traits, see the [fuel-types documentation](https://docs.rs/fuel-types/{{versions.fuels-types}}/fuel_types/struct.Bytes32.html). +For a full list of implemented methods and traits, see the [fuel-types documentation](https://docs.rs/fuel-types/{{versions.fuel-types}}/fuel_types/struct.Bytes32.html). > **Note:** In Fuel, there's a special type called `b256`, which is similar to `Bytes32`; also used to represent hashes, and it holds a 256-bit value. In Rust, through the SDK, this is represented as `Bits256(value)` where `value` is a `[u8; 32]`. If your contract method takes a `b256` as input, all you need to do is pass a `Bits256([u8; 32])` when calling it from the SDK. diff --git a/docs/src/types/contract-id.md b/docs/src/types/contract-id.md index 76516b0b00..a14dd877ce 100644 --- a/docs/src/types/contract-id.md +++ b/docs/src/types/contract-id.md @@ -1,6 +1,6 @@ # ContractId -Like `Bytes32`, `ContractId` is a wrapper on `[u8; 32]` with similar methods and implements the same traits (see [fuel-types documentation](https://docs.rs/fuel-types/{{versions.fuels-types}}/fuel_types/struct.ContractId.html)). +Like `Bytes32`, `ContractId` is a wrapper on `[u8; 32]` with similar methods and implements the same traits (see [fuel-types documentation](https://docs.rs/fuel-types/{{versions.fuel-types}}/fuel_types/struct.ContractId.html)). These are the main ways of creating a `ContractId`: diff --git a/scripts/versions-replacer/src/metadata.rs b/scripts/versions-replacer/src/metadata.rs index 9a2adc10b0..3858d6a4d2 100644 --- a/scripts/versions-replacer/src/metadata.rs +++ b/scripts/versions-replacer/src/metadata.rs @@ -24,18 +24,9 @@ pub fn collect_versions_from_cargo_toml( .exec() .wrap_err("failed to execute 'cargo metadata'")?; let version_map = metadata - .workspace_members + .packages .iter() - .map(|package_id| { - let package = &metadata[package_id]; - (package.name.clone(), package.version.to_string()) - }) - .chain( - serde_json::from_value::(metadata.workspace_metadata.clone()) - .wrap_err("failed to parse '[workspace.metadata]'")? - .versions_replacer - .external_versions, - ) + .map(|package| (package.name.clone(), package.version.to_string())) .collect::>(); Ok(version_map) } diff --git a/scripts/versions-replacer/src/replace.rs b/scripts/versions-replacer/src/replace.rs index 5090bd08cf..7bc1893c1f 100644 --- a/scripts/versions-replacer/src/replace.rs +++ b/scripts/versions-replacer/src/replace.rs @@ -44,21 +44,21 @@ mod tests { use super::*; fn test_versions() -> HashMap { - [("fuels", "0.47.0"), ("fuels-types", "0.35.3")] + [("fuels", "0.47.0"), ("fuel-types", "0.35.3")] .map(|(name, version)| (name.to_string(), version.to_string())) .into() } #[test] fn test_valid_replacements() { - let s = "docs.rs/fuels/{{versions.fuels}}/fuels\ndocs.rs/fuels-types/{{versions.fuels-types}}/fuels-types"; + let s = "docs.rs/fuels/{{versions.fuels}}/fuels\ndocs.rs/fuel-types/{{versions.fuel-types}}/fuel-types"; let versions = test_versions(); let (replaced, count) = replace_versions_in_string(s, &versions); assert_eq!( replaced, format!( - "docs.rs/fuels/{}/fuels\ndocs.rs/fuels-types/{}/fuels-types", - versions["fuels"], versions["fuels-types"] + "docs.rs/fuels/{}/fuels\ndocs.rs/fuel-types/{}/fuel-types", + versions["fuels"], versions["fuel-types"] ) ); assert_eq!(count, 2); From 44f760301f29bc805d263782c15e92419e956c5f Mon Sep 17 00:00:00 2001 From: Oleksii Filonenko Date: Wed, 27 Sep 2023 13:19:33 +0300 Subject: [PATCH 19/19] remove unused serde_json dependency --- scripts/versions-replacer/Cargo.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/versions-replacer/Cargo.toml b/scripts/versions-replacer/Cargo.toml index 2bd80128e1..8dda125775 100644 --- a/scripts/versions-replacer/Cargo.toml +++ b/scripts/versions-replacer/Cargo.toml @@ -17,5 +17,4 @@ color-eyre = "0.6.2" once_cell = "1.18.0" regex = { workspace = true } serde = { workspace = true, features = ["derive"] } -serde_json = { workspace = true } walkdir = "2.3.3"