Skip to content

Commit

Permalink
restructure build action + clippy + fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
arrudagates committed Nov 9, 2023
1 parent d9c11f7 commit c638384
Show file tree
Hide file tree
Showing 7 changed files with 211 additions and 205 deletions.
103 changes: 56 additions & 47 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ env:
CARGO_TERM_COLOR: always

jobs:
build:
get_changed_files:
runs-on: ubuntu-latest
name: Build
steps:
Expand All @@ -28,6 +28,19 @@ jobs:
dir_names: true
dir_names_max_depth: 1

build_tinkernet:
runs-on: ubuntu-latest
name: Build Tinkernet

needs: get_changed_files
if:
contains(needs.get_changed_files.outputs.all_modified_files, 'tinkernet')

defaults:
run:
working-directory: ./tinkernet

steps:
- name: Free disk space
run: |
sudo rm -rf /usr/share/dotnet
Expand All @@ -37,66 +50,62 @@ jobs:
df -h
- name: Setup for checks
if:
contains(steps.changed-files.outputs.all_modified_files, 'tinkernet') || contains(steps.changed-files.outputs.all_modified_files, 'invarch')
run: sudo apt install -y git clang curl libssl-dev llvm libudev-dev protobuf-compiler

- name: Build [tinkernet]
if:
contains(steps.changed-files.outputs.all_modified_files, 'tinkernet')
working-directory: ./tinkernet
- name: Install & display rust toolchain
run: rustup show

- uses: Swatinem/rust-cache@v2

- name: Build
run: cargo build --verbose

- name: Run tests [tinkernet]
if:
contains(steps.changed-files.outputs.all_modified_files, 'tinkernet')
working-directory: ./tinkernet
- name: Run tests
run: cargo test --verbose

- name: Run clippy [tinkernet]
if:
contains(steps.changed-files.outputs.all_modified_files, 'tinkernet')
working-directory: ./tinkernet
- name: Run clippy
run: cargo clippy -- -D warnings

- name: Run cargofmt [tinkernet]
if:
contains(steps.changed-files.outputs.all_modified_files, 'tinkernet')
working-directory: ./tinkernet
run: cargo +stable fmt --all -- --check
- name: Run cargofmt
run: cargo fmt --all -- --check

- name: Cleanup [tinkernet]
if:
contains(steps.changed-files.outputs.all_modified_files, 'tinkernet')
working-directory: ./tinkernet
run: cargo clean
build_invarch:
runs-on: ubuntu-latest
name: Build InvArch

- name: Build [invarch]
if:
contains(steps.changed-files.outputs.all_modified_files, 'invarch')
needs: get_changed_files
if:
contains(needs.get_changed_files.outputs.all_modified_files, 'invarch')

defaults:
run:
working-directory: ./invarch

steps:
- name: Free disk space
run: |
sudo rm -rf /usr/share/dotnet
sudo rm -rf /opt/ghc
sudo rm -rf "/usr/local/share/boost"
sudo rm -rf "$AGENT_TOOLSDIRECTORY"
df -h
- name: Setup for checks
run: sudo apt install -y git clang curl libssl-dev llvm libudev-dev protobuf-compiler

- name: Install & display rust toolchain
run: rustup show

- uses: Swatinem/rust-cache@v2

- name: Build
run: cargo build --verbose

- name: Run tests [invarch]
if:
contains(steps.changed-files.outputs.all_modified_files, 'invarch')
working-directory: ./invarch
- name: Run tests
run: cargo test --verbose

- name: Run clippy [invarch]
if:
contains(steps.changed-files.outputs.all_modified_files, 'invarch')
working-directory: ./invarch
- name: Run clippy
run: cargo clippy -- -D warnings

- name: Run cargofmt [invarch]
if:
contains(steps.changed-files.outputs.all_modified_files, 'invarch')
working-directory: ./invarch
run: cargo +stable fmt --all -- --check

- name: Cleanup [invarch]
if:
contains(steps.changed-files.outputs.all_modified_files, 'invarch')
working-directory: ./invarch
run: cargo clean
- name: Run cargofmt
run: cargo fmt --all -- --check
19 changes: 8 additions & 11 deletions invarch/node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ pub fn run() -> Result<()> {
&polkadot_cli,
config.tokio_handle.clone(),
)
.map_err(|err| format!("Relay chain argument error: {}", err))?;
.map_err(|err| format!("Relay chain argument error: {err}"))?;

cmd.run(config, polkadot_config)
})
Expand Down Expand Up @@ -265,14 +265,11 @@ pub fn run() -> Result<()> {
}
}
#[cfg(not(feature = "runtime-benchmarks"))]
BenchmarkCmd::Storage(_) => {
return Err(sc_cli::Error::Input(
"Compile with --features=runtime-benchmarks \
BenchmarkCmd::Storage(_) => Err(sc_cli::Error::Input(
"Compile with --features=runtime-benchmarks \
to enable storage benchmarks."
.into(),
)
.into())
}
.into(),
)),
#[cfg(feature = "runtime-benchmarks")]
BenchmarkCmd::Storage(cmd) => runner.sync_run(|config| {
let partials =
Expand Down Expand Up @@ -335,7 +332,7 @@ pub fn run() -> Result<()> {
runner.run_node_until_exit(|config| async move {
let hwbench = if !cli.no_hardware_benchmarks {
config.database.path().map(|database_path| {
let _ = std::fs::create_dir_all(&database_path);
let _ = std::fs::create_dir_all(database_path);
sc_sysinfo::gather_hwbench(Some(database_path))
})
} else {
Expand Down Expand Up @@ -368,13 +365,13 @@ pub fn run() -> Result<()> {
let state_version =
RelayChainCli::native_runtime_version(&config.chain_spec).state_version();
let block: Block = generate_genesis_block(&*config.chain_spec, state_version)
.map_err(|e| format!("{:?}", e))?;
.map_err(|e| format!("{e:?}"))?;
let genesis_state = format!("0x{:?}", HexDisplay::from(&block.header().encode()));

let tokio_handle = config.tokio_handle.clone();
let polkadot_config =
SubstrateCli::create_configuration(&polkadot_cli, &polkadot_cli, tokio_handle)
.map_err(|err| format!("Relay chain argument error: {}", err))?;
.map_err(|err| format!("Relay chain argument error: {err}"))?;

info!("Parachain id: {:?}", id);
info!("Parachain Account: {}", parachain_account);
Expand Down
10 changes: 5 additions & 5 deletions invarch/runtime/build.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use substrate_wasm_builder::WasmBuilder;

fn main() {
WasmBuilder::new()
.with_current_project()
.export_heap_base()
.import_memory()
.build()
WasmBuilder::new()
.with_current_project()
.export_heap_base()
.import_memory()
.build()
}
60 changes: 30 additions & 30 deletions invarch/runtime/src/weights/block_weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,38 +16,38 @@
// limitations under the License.

pub mod constants {
use frame_support::{
parameter_types,
weights::{constants, Weight},
};
use frame_support::{
parameter_types,
weights::{constants, Weight},
};

parameter_types! {
/// Importing a block with 0 Extrinsics.
pub const BlockExecutionWeight: Weight =
Weight::from_ref_time(constants::WEIGHT_REF_TIME_PER_NANOS.saturating_mul(5_000_000));
}
parameter_types! {
/// Importing a block with 0 Extrinsics.
pub const BlockExecutionWeight: Weight =
Weight::from_ref_time(constants::WEIGHT_REF_TIME_PER_NANOS.saturating_mul(5_000_000));
}

#[cfg(test)]
mod test_weights {
use frame_support::weights::constants;
#[cfg(test)]
mod test_weights {
use frame_support::weights::constants;

/// Checks that the weight exists and is sane.
// NOTE: If this test fails but you are sure that the generated values are fine,
// you can delete it.
#[test]
fn sane() {
let w = super::constants::BlockExecutionWeight::get();
/// Checks that the weight exists and is sane.
// NOTE: If this test fails but you are sure that the generated values are fine,
// you can delete it.
#[test]
fn sane() {
let w = super::constants::BlockExecutionWeight::get();

// At least 100 µs.
assert!(
w.ref_time() >= 100u64 * constants::WEIGHT_REF_TIME_PER_MICROS,
"Weight should be at least 100 µs."
);
// At most 50 ms.
assert!(
w.ref_time() <= 50u64 * constants::WEIGHT_REF_TIME_PER_MILLIS,
"Weight should be at most 50 ms."
);
}
}
// At least 100 µs.
assert!(
w.ref_time() >= 100u64 * constants::WEIGHT_REF_TIME_PER_MICROS,
"Weight should be at least 100 µs."
);
// At most 50 ms.
assert!(
w.ref_time() <= 50u64 * constants::WEIGHT_REF_TIME_PER_MILLIS,
"Weight should be at most 50 ms."
);
}
}
}
60 changes: 30 additions & 30 deletions invarch/runtime/src/weights/extrinsic_weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,38 +16,38 @@
// limitations under the License.

pub mod constants {
use frame_support::{
parameter_types,
weights::{constants, Weight},
};
use frame_support::{
parameter_types,
weights::{constants, Weight},
};

parameter_types! {
/// Executing a NO-OP `System::remarks` Extrinsic.
pub const ExtrinsicBaseWeight: Weight =
Weight::from_ref_time(constants::WEIGHT_REF_TIME_PER_NANOS.saturating_mul(125_000));
}
parameter_types! {
/// Executing a NO-OP `System::remarks` Extrinsic.
pub const ExtrinsicBaseWeight: Weight =
Weight::from_ref_time(constants::WEIGHT_REF_TIME_PER_NANOS.saturating_mul(125_000));
}

#[cfg(test)]
mod test_weights {
use frame_support::weights::constants;
#[cfg(test)]
mod test_weights {
use frame_support::weights::constants;

/// Checks that the weight exists and is sane.
// NOTE: If this test fails but you are sure that the generated values are fine,
// you can delete it.
#[test]
fn sane() {
let w = super::constants::ExtrinsicBaseWeight::get();
/// Checks that the weight exists and is sane.
// NOTE: If this test fails but you are sure that the generated values are fine,
// you can delete it.
#[test]
fn sane() {
let w = super::constants::ExtrinsicBaseWeight::get();

// At least 10 µs.
assert!(
w.ref_time() >= 10u64 * constants::WEIGHT_REF_TIME_PER_MICROS,
"Weight should be at least 10 µs."
);
// At most 1 ms.
assert!(
w.ref_time() <= constants::WEIGHT_REF_TIME_PER_MILLIS,
"Weight should be at most 1 ms."
);
}
}
// At least 10 µs.
assert!(
w.ref_time() >= 10u64 * constants::WEIGHT_REF_TIME_PER_MICROS,
"Weight should be at least 10 µs."
);
// At most 1 ms.
assert!(
w.ref_time() <= constants::WEIGHT_REF_TIME_PER_MILLIS,
"Weight should be at most 1 ms."
);
}
}
}
Loading

0 comments on commit c638384

Please sign in to comment.