Skip to content

Commit

Permalink
Merge pull request #2 from r0gue-io/chungquantin/refactor-formatting
Browse files Browse the repository at this point in the history
fix: format with pop-node config
  • Loading branch information
chungquantin authored Sep 24, 2024
2 parents d16f01f + b96ed6a commit 51f5afe
Show file tree
Hide file tree
Showing 43 changed files with 2,067 additions and 1,984 deletions.
32 changes: 32 additions & 0 deletions .github/actions/init/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Initialize
description: This action initializes a runner for use in other actions.
inputs:
cache-key:
description: "The key to be used for the cache"

runs:
using: "composite"
steps:
- name: Setup Ubuntu dependencies
shell: bash
run: sudo apt update && sudo apt install -y protobuf-compiler

- name: Free up space on runner
shell: bash
run: |
sudo rm -rf /opt/ghc
sudo rm -rf /opt/hostedtoolcache/CodeQL
sudo rm -rf /usr/local/.ghcup
sudo rm -rf /usr/local/lib/android
sudo rm -rf /usr/local/share/boost
sudo rm -rf /usr/local/share/powershell
sudo rm -rf /usr/share/dotnet
sudo rm -rf /usr/share/swift
sudo rm -rf "$AGENT_TOOLSDIRECTORY"
- name: Rust Cache
uses: Swatinem/[email protected]
with:
cache-on-failure: true
cache-all-crates: true
key: ${{ inputs.cache-key }}
75 changes: 75 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: ci

on:
push:
branches: [main]
pull_request:
types: [opened, synchronize, reopened, ready_for_review]

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: "./.github/actions/init"

- name: Check formatting
run: |
rustup toolchain install nightly --profile minimal --component rustfmt
cargo +nightly fmt --all -- --check
- name: Check manifests
run: |
cargo install taplo-cli --locked
taplo format --check
- name: Check features
run: |
cargo install zepter --locked
zepter lint propagate-feature --feature try-runtime --left-side-feature-missing=ignore --workspace --feature-enables-dep="try-runtime:frame-try-runtime" --locked
zepter lint propagate-feature --feature runtime-benchmarks --left-side-feature-missing=ignore --workspace --feature-enables-dep="runtime-benchmarks:frame-benchmarking" --locked
zepter lint propagate-feature --feature std --left-side-feature-missing=ignore --workspace --locked
zepter format features
check:
needs: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: "./.github/actions/init"

- name: Check Build
run: |
cargo check --release --locked --features=runtime-benchmarks,try-runtime
clippy:
needs: lint
runs-on: ubuntu-latest
permissions:
checks: write
env:
RUSTFLAGS: "-Wmissing_docs"
SKIP_WASM_BUILD: 1
steps:
- uses: actions/checkout@v4

- uses: "./.github/actions/init"

- name: Annotate with Clippy warnings
uses: actions-rs/clippy-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
args: --release --locked --features=runtime-benchmarks

test:
needs: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: "./.github/actions/init"

- name: Run tests
run: cargo test --release --locked --workspace --features=runtime-benchmarks --exclude integration-tests
20 changes: 20 additions & 0 deletions .github/workflows/lint-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: "Lint PR"

on:
pull_request_target:
types:
- opened
- edited
- synchronize

permissions:
pull-requests: read

jobs:
lint:
name: Validate PR title for conventional commit compliance
runs-on: ubuntu-latest
steps:
- uses: amannn/action-semantic-pull-request@v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
24 changes: 24 additions & 0 deletions .rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Non-default formatting configuration options: use with `cargo +nightly fmt --all`
binop_separator = "Back"
chain_width = 80
combine_control_expr = false
comment_width = 100
condense_wildcard_suffixes = true
edition = "2021"
format_code_in_doc_comments = true
format_strings = true
group_imports = "StdExternalCrate"
hard_tabs = true
imports_granularity = "Crate"
match_arm_blocks = false
match_block_trailing_comma = true
newline_style = "Unix"
normalize_comments = true
reorder_impl_items = true
trailing_semicolon = false
unstable_features = true
use_field_init_shorthand = true
# Uses max_width or its default value (100) if not specified.
use_small_heuristics = "Max"
use_try_shorthand = true
wrap_comments = true
17 changes: 17 additions & 0 deletions .taplo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# all options https://taplo.tamasfe.dev/configuration/formatter-options.html

exclude = [ "networks/**", "target/**" ]

# global rules
[formatting]
array_auto_collapse = false
array_auto_expand = true
compact_arrays = false # zepter compatibility
indent_string = " " # tab
inline_table_expand = false
reorder_arrays = true
reorder_keys = true

[[rule]]
include = [ "Cargo.toml" ]
keys = [ "workspace.dependencies" ]
82 changes: 41 additions & 41 deletions drink-cli/src/app_state/contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,56 +7,56 @@ use ContractIndex::NoContracts;
use crate::app_state::ContractIndex::CurrentContract;

pub struct Contract {
pub name: String,
pub address: AccountId32,
pub base_path: PathBuf,
pub transcoder: Arc<ContractMessageTranscoder>,
pub name: String,
pub address: AccountId32,
pub base_path: PathBuf,
pub transcoder: Arc<ContractMessageTranscoder>,
}

#[derive(Copy, Clone, Eq, PartialEq, Debug, Default)]
pub enum ContractIndex {
#[default]
NoContracts,
CurrentContract(usize),
#[default]
NoContracts,
CurrentContract(usize),
}

#[derive(Default)]
pub struct ContractRegistry {
contracts: Vec<Contract>,
index: ContractIndex,
contracts: Vec<Contract>,
index: ContractIndex,
}

impl ContractRegistry {
pub fn add(&mut self, contract: Contract) {
self.contracts.push(contract);
self.index = CurrentContract(self.contracts.len() - 1);
}

pub fn current_index(&self) -> ContractIndex {
self.index
}

pub fn current_contract(&self) -> Option<&Contract> {
match self.index {
NoContracts => None,
CurrentContract(idx) => Some(&self.contracts[idx]),
}
}

pub fn get_all(&self) -> &[Contract] {
&self.contracts
}

pub fn next(&mut self) -> Option<&Contract> {
let CurrentContract(old_index) = self.index else {
return None;
};

self.index = CurrentContract((old_index + 1) % self.contracts.len());
self.current_contract()
}

pub fn count(&self) -> usize {
self.contracts.len()
}
pub fn add(&mut self, contract: Contract) {
self.contracts.push(contract);
self.index = CurrentContract(self.contracts.len() - 1);
}

pub fn current_index(&self) -> ContractIndex {
self.index
}

pub fn current_contract(&self) -> Option<&Contract> {
match self.index {
NoContracts => None,
CurrentContract(idx) => Some(&self.contracts[idx]),
}
}

pub fn get_all(&self) -> &[Contract] {
&self.contracts
}

pub fn next(&mut self) -> Option<&Contract> {
let CurrentContract(old_index) = self.index else {
return None;
};

self.index = CurrentContract((old_index + 1) % self.contracts.len());
self.current_contract()
}

pub fn count(&self) -> usize {
self.contracts.len()
}
}
Loading

0 comments on commit 51f5afe

Please sign in to comment.