Skip to content

Commit

Permalink
style: format in ci.yml (#287)
Browse files Browse the repository at this point in the history
* Refactor of ci.yml

* Updating all files to be formated with nightly
  • Loading branch information
tsenovilla authored Sep 4, 2024
1 parent 1d41cd4 commit f9ebdd3
Show file tree
Hide file tree
Showing 16 changed files with 66 additions and 65 deletions.
10 changes: 9 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,16 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Install Rust nightly
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
profile: minimal
components: rustfmt
override: true

- name: Check formatting
run: cargo fmt --all -- --check
run: cargo +nightly fmt --all -- --check

build:
needs: lint
Expand Down
22 changes: 10 additions & 12 deletions crates/pop-cli/src/commands/build/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,13 +370,13 @@ async fn guide_user_to_generate_spec(args: BuildSpecCommand) -> anyhow::Result<B
}
// Prompt relays chains based on the chain type
match chain_type {
ChainType::Live => {
ChainType::Live =>
for relay in RelayChain::VARIANTS {
if !matches!(
relay,
RelayChain::Westend
| RelayChain::Paseo | RelayChain::Kusama
| RelayChain::Polkadot
RelayChain::Westend |
RelayChain::Paseo | RelayChain::Kusama |
RelayChain::Polkadot
) {
continue;
} else {
Expand All @@ -386,15 +386,14 @@ async fn guide_user_to_generate_spec(args: BuildSpecCommand) -> anyhow::Result<B
relay.get_detailed_message().unwrap_or_default(),
);
}
}
},
_ => {
},
_ =>
for relay in RelayChain::VARIANTS {
if matches!(
relay,
RelayChain::Westend
| RelayChain::Paseo | RelayChain::Kusama
| RelayChain::Polkadot
RelayChain::Westend |
RelayChain::Paseo | RelayChain::Kusama |
RelayChain::Polkadot
) {
continue;
} else {
Expand All @@ -404,8 +403,7 @@ async fn guide_user_to_generate_spec(args: BuildSpecCommand) -> anyhow::Result<B
relay.get_detailed_message().unwrap_or_default(),
);
}
}
},
},
}

let relay_chain = prompt.interact()?.clone();
Expand Down
5 changes: 2 additions & 3 deletions crates/pop-cli/src/commands/install/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,12 +299,11 @@ async fn install_rustup() -> anyhow::Result<()> {
async fn install_homebrew() -> anyhow::Result<()> {
match cmd("which", vec!["brew"]).read() {
Ok(output) => log::info(format!("ℹ️ Homebrew installed already at {}.", output))?,
Err(_) => {
Err(_) =>
run_external_script(
"https://raw.githubusercontent.com/Homebrew/install/master/install.sh",
)
.await?
},
.await?,
}
Ok(())
}
Expand Down
10 changes: 5 additions & 5 deletions crates/pop-cli/src/commands/new/pallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ impl NewPalletCommand {
let mut pallet_custom_origin = false;

if let Some(Mode::Advanced(advanced_mode_args)) = &self.mode {
if advanced_mode_args.config_common_types.is_empty()
&& advanced_mode_args.storage.is_empty()
&& !(advanced_mode_args.genesis_config
|| advanced_mode_args.default_config
|| advanced_mode_args.custom_origin)
if advanced_mode_args.config_common_types.is_empty() &&
advanced_mode_args.storage.is_empty() &&
!(advanced_mode_args.genesis_config ||
advanced_mode_args.default_config ||
advanced_mode_args.custom_origin)
{
Cli.info("Generate the pallet's config trait.")?;

Expand Down
4 changes: 2 additions & 2 deletions crates/pop-cli/src/commands/new/parachain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,8 @@ fn get_customization_value(
decimals: Option<u8>,
initial_endowment: Option<String>,
) -> Result<Config> {
if !matches!(template, Parachain::Standard)
&& (symbol.is_some() || decimals.is_some() || initial_endowment.is_some())
if !matches!(template, Parachain::Standard) &&
(symbol.is_some() || decimals.is_some() || initial_endowment.is_some())
{
log::warning("Customization options are not available for this template")?;
sleep(Duration::from_secs(3))
Expand Down
4 changes: 2 additions & 2 deletions crates/pop-cli/src/commands/up/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,8 @@ pub fn has_contract_been_built(path: Option<&Path>) -> bool {
Err(_) => return false,
};
let contract_name = manifest.package().name();
project_path.join("target/ink").exists()
&& project_path.join(format!("target/ink/{}.contract", contract_name)).exists()
project_path.join("target/ink").exists() &&
project_path.join(format!("target/ink/{}.contract", contract_name)).exists()
}

#[cfg(test)]
Expand Down
5 changes: 2 additions & 3 deletions crates/pop-cli/src/commands/up/parachain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl ZombienetCommand {
.await
{
Ok(n) => n,
Err(e) => {
Err(e) =>
return match e {
Error::Config(message) => {
outro_cancel(format!("🚫 A configuration error occurred: `{message}`"))?;
Expand All @@ -82,8 +82,7 @@ impl ZombienetCommand {
Ok(())
},
_ => Err(e.into()),
}
},
},
};

// Source any missing/stale binaries
Expand Down
3 changes: 2 additions & 1 deletion crates/pop-common/src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ impl Git {
Self::parse_latest_tag(tags.iter().flatten().collect::<Vec<_>>())
}

/// Parses a list of tags to identify the latest one, prioritizing tags in the stable format first.
/// Parses a list of tags to identify the latest one, prioritizing tags in the stable format
/// first.
fn parse_latest_tag(tags: Vec<&str>) -> Option<String> {
match Self::parse_stable_format(tags.clone()) {
Some(last_stable_tag) => Some(last_stable_tag),
Expand Down
10 changes: 4 additions & 6 deletions crates/pop-common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,16 @@ pub fn target() -> Result<&'static str, Error> {
}

match ARCH {
"aarch64" => {
"aarch64" =>
return match OS {
"macos" => Ok("aarch64-apple-darwin"),
_ => Ok("aarch64-unknown-linux-gnu"),
}
},
"x86_64" | "x86" => {
},
"x86_64" | "x86" =>
return match OS {
"macos" => Ok("x86_64-apple-darwin"),
_ => Ok("x86_64-unknown-linux-gnu"),
}
},
},
&_ => {},
}
Err(Error::UnsupportedPlatform { arch: ARCH, os: OS })
Expand Down
11 changes: 8 additions & 3 deletions crates/pop-common/src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,17 @@ pub fn from_path(path: Option<&Path>) -> Result<Manifest, Error> {
Ok(Manifest::from_path(path.canonicalize()?)?)
}

/// This function is used to determine if a Path is contained inside a workspace, and returns a PathBuf to the workspace Cargo.toml if found.
/// This function is used to determine if a Path is contained inside a workspace, and returns a
/// PathBuf to the workspace Cargo.toml if found.
///
/// # Arguments
/// * `target_dir` - A directory that may be contained inside a workspace
pub fn find_workspace_toml(target_dir: &Path) -> Option<PathBuf> {
let mut dir = target_dir;
while let Some(parent) = dir.parent() {
// This condition is necessary to avoid that calling the function from a workspace using a path which isn't contained in a workspace returns `Some(Cargo.toml)` refering the workspace from where the function has been called instead of the expected `None`.
// This condition is necessary to avoid that calling the function from a workspace using a
// path which isn't contained in a workspace returns `Some(Cargo.toml)` refering the
// workspace from where the function has been called instead of the expected `None`.
if parent.to_str() == Some("") {
return None;
}
Expand Down Expand Up @@ -249,7 +252,9 @@ mod tests {
if let Some(Item::Value(Value::Array(array))) = workspace_table.get("members") {
assert!(array.iter().any(|item| {
if let Value::String(item) = item {
// item is only the relative path from the Cargo.toml manifest, while test_buildder.insider_workspace_dir is the absolute path, so we can only test with contains
// item is only the relative path from the Cargo.toml manifest, while
// test_buildder.insider_workspace_dir is the absolute path, so we can only
// test with contains
test_builder
.inside_workspace_dir
.as_ref()
Expand Down
20 changes: 8 additions & 12 deletions crates/pop-common/src/sourcing/binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,12 @@ impl Binary {
pub fn latest(&self) -> Option<&str> {
match self {
Self::Local { .. } => None,
Self::Source { source, .. } => {
Self::Source { source, .. } =>
if let GitHub(ReleaseArchive { latest, .. }) = source {
latest.as_deref()
} else {
None
}
},
},
}
}

Expand Down Expand Up @@ -135,18 +134,15 @@ impl Binary {
) -> Result<(), Error> {
match self {
Self::Local { name, path, manifest, .. } => match manifest {
None => {
None =>
return Err(Error::MissingBinary(format!(
"The {path:?} binary cannot be sourced automatically."
)))
},
Some(manifest) => {
from_local_package(manifest, name, release, status, verbose).await
},
},
Self::Source { source, cache, .. } => {
source.source(cache, release, status, verbose).await
))),
Some(manifest) =>
from_local_package(manifest, name, release, status, verbose).await,
},
Self::Source { source, cache, .. } =>
source.source(cache, release, status, verbose).await,
}
}

Expand Down
10 changes: 4 additions & 6 deletions crates/pop-common/src/sourcing/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,8 @@ impl GitHub {
let artifacts: Vec<_> = artifacts
.iter()
.map(|name| match reference {
Some(reference) => {
(name.as_str(), cache.join(&format!("{name}-{reference}")))
},
Some(reference) =>
(name.as_str(), cache.join(&format!("{name}-{reference}"))),
None => (name.as_str(), cache.join(&name)),
})
.collect();
Expand Down Expand Up @@ -379,11 +378,10 @@ async fn from_github_archive(
// Prepare archive contents for build
let entries: Vec<_> = read_dir(&working_dir)?.take(2).filter_map(|x| x.ok()).collect();
match entries.len() {
0 => {
0 =>
return Err(Error::ArchiveError(
"The downloaded archive does not contain any entries.".into(),
))
},
)),
1 => working_dir = entries[0].path(), // Automatically switch to top level directory
_ => {}, /* Assume that downloaded archive does not have a
* top level directory */
Expand Down
4 changes: 2 additions & 2 deletions crates/pop-common/src/templates/extractor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ fn copy_dir_all(
for entry in fs::read_dir(src)? {
let entry = entry?;
let ty = entry.file_type()?;
if ty.is_dir()
&& ignore_directories.contains(&entry.file_name().to_string_lossy().to_string())
if ty.is_dir() &&
ignore_directories.contains(&entry.file_name().to_string_lossy().to_string())
{
continue;
} else if ty.is_dir() {
Expand Down
4 changes: 2 additions & 2 deletions crates/pop-parachains/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ pub fn is_supported(path: Option<&Path>) -> Result<bool, Error> {
const DEPENDENCIES: [&str; 4] =
["cumulus-client-collator", "cumulus-primitives-core", "parachains-common", "polkadot-sdk"];
Ok(DEPENDENCIES.into_iter().any(|d| {
manifest.dependencies.contains_key(d)
|| manifest.workspace.as_ref().map_or(false, |w| w.dependencies.contains_key(d))
manifest.dependencies.contains_key(d) ||
manifest.workspace.as_ref().map_or(false, |w| w.dependencies.contains_key(d))
}))
}

Expand Down
5 changes: 2 additions & 3 deletions crates/pop-parachains/src/up/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,13 +252,12 @@ impl Zombienet {
if let Some(command) = NetworkConfiguration::command(node).and_then(|c| c.as_str())
{
match &relay {
Some(relay) => {
Some(relay) =>
if command.to_lowercase() != relay.binary.name() {
return Err(Error::UnsupportedCommand(format!(
"the relay chain command is unsupported: {command}",
)));
}
},
},
None => {
relay = Some(
relay::from(command, version, runtime_version, chain, cache)
Expand Down
4 changes: 2 additions & 2 deletions crates/pop-parachains/src/utils/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ pub(crate) fn sanitize(target: &Path) -> Result<(), Error> {
///
/// * `initial_endowment` - initial endowment amount to be checked for validity.
pub fn is_initial_endowment_valid(initial_endowment: &str) -> bool {
initial_endowment.parse::<u128>().is_ok()
|| is_valid_bitwise_left_shift(initial_endowment).is_ok()
initial_endowment.parse::<u128>().is_ok() ||
is_valid_bitwise_left_shift(initial_endowment).is_ok()
}
// Auxiliar method to check if the endowment input with a shift left (1u64 << 60) format is valid.
// Parse the self << rhs format and check the shift left operation is valid.
Expand Down

0 comments on commit f9ebdd3

Please sign in to comment.