Skip to content

Commit

Permalink
chore: update release workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
slavik-pastushenko committed Nov 8, 2023
1 parent 929ca42 commit 7622ef8
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 69 deletions.
71 changes: 35 additions & 36 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,41 +1,40 @@
name: release

on:
workflow_dispatch:
inputs:
crate:
description: 'Crate to release'
required: true
default: 'blockchain-cli'
workflow_call:
inputs:
crate:
description: 'Crate to release'
required: true
type: string
secrets:
CARGO_REGISTRY_TOKEN:
required: true

name: Release
push:
branches:
- main

jobs:
cargo-publish:
name: Publish and Tag
release:
runs-on: ubuntu-latest
permissions:
contents: write
continue-on-error: true

steps:
- uses: actions/checkout@v2
- uses: jrobsonchase/[email protected]
- name: Publish
uses: actions-rs/cargo@v1
with:
command: publish
args: -p ${{ inputs.crate }} --token ${{secrets.CARGO_REGISTRY_TOKEN}}
- name: Tag
run: |
version="$(extract-crate-version ${{inputs.crate}})"
git config user.name "GitHub Action"
git config user.email [email protected]
git tag -a -m "Version ${version}" ${{inputs.crate}}-v${version}
git push --tags
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Rust
uses: actions/setup-rust@v1
with:
rust-version: stable

- name: Install cargo-release
run: cargo install cargo-release

- name: Bump version and create GitHub release
run: |
# Bump the version and create a GitHub release
cargo release
# Get the version number from Cargo.toml
VERSION=$(grep -oP 'version = "\K[^"]+' Cargo.toml)
# Create a GitHub release using the GitHub CLI
gh release create "v$VERSION" target/package/blockchain-cli-*.crate -t "v$VERSION"
env:
CRATE_NAME: blockchain-cli

- name: Publish to crates.io
run: cargo publish
env:
CRATES_IO_TOKEN: ${{ secrets.CRATES_IO_TOKEN }}
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,7 @@ jobs:
run: cargo build --verbose
- name: Run clippy
run: cargo clippy --all-targets --all-features -- -D warnings
- name: Run lint
run: cargo fmt -- --check
- name: Run tests
run: cargo test --verbose
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ authors = ["Slavik Pastushenko <[email protected]>"]
keywords = ["cli", "crypto", "blockchain"]
exclude = [".prettierrc.toml", ".github/**"]
categories = ["command-line-utilities", "cryptography"]
documentation = "https://docs.rs/blockchain-cli/1.0.0"
documentation = "https://docs.rs/blockchain-cli"
repository = "https://github.com/slavik-pastushenko/blockchain-rust"

[lib]
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ A Rust library provides a command-line interface (CLI) for interacting with bloc
## Reference implementation

[![test](https://github.com/slavik-pastushenko/blockchain-rust/actions/workflows/test.yml/badge.svg)](https://github.com/slavik-pastushenko/blockchain-rust/actions/workflows/test.yml)
[![release](https://github.com/slavik-pastushenko/blockchain-rust/actions/workflows/release.yml/badge.svg)](https://github.com/slavik-pastushenko/blockchain-rust/actions/workflows/release.yml)
[![docs](https://docs.rs/blockchain-cli/badge.svg)](https://docs.rs/blockchain-cli)
[![crate](https://img.shields.io/crates/v/blockchain-cli.svg)](https://crates.io/crates/blockchain-cli)
![Crates.io (recent)](https://img.shields.io/crates/dr/blockchain-cli)
![GitHub](https://img.shields.io/github/license/slavik-pastushenko/blockchain-rust)

![Features](https://github.com/slavik-pastushenko/blockchain-rust/assets/16807375/f9f15dbf-8594-4a1c-9d7a-675567a205da)

Expand Down Expand Up @@ -110,6 +110,12 @@ cargo run
cargo clippy --all-targets --all-features -- -D warnings
```

Run [lint](https://github.com/rust-lang/rustfmt):

```bash
cargo fmt
```

- Generate documentation in HTML format:

```bash
Expand Down
80 changes: 51 additions & 29 deletions src/bin/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,35 @@ use blockchain::Chain;
fn main() -> std::io::Result<()> {
cliclack::clear_screen()?;

let address: String = cliclack
::input("Address")
let address: String = cliclack::input("Address")
.validate(|input: &String| {
if input.is_empty() { Err("Please enter an address") } else { Ok(()) }
if input.is_empty() {
Err("Please enter an address")
} else {
Ok(())
}
})
.interact()?;

let difficulty: u32 = cliclack
::input("Difficulty")
let difficulty: u32 = cliclack::input("Difficulty")
.default_input("2")
.validate(|input: &String| {
if input.is_empty() { Err("Please enter a difficulty") } else { Ok(()) }
if input.is_empty() {
Err("Please enter a difficulty")
} else {
Ok(())
}
})
.interact()?;

let reward: f32 = cliclack
::input("Reward")
let reward: f32 = cliclack::input("Reward")
.default_input("100.0")
.validate(|input: &String| {
if input.is_empty() { Err("Please enter a reward") } else { Ok(()) }
if input.is_empty() {
Err("Please enter a reward")
} else {
Ok(())
}
})
.interact()?;

Expand All @@ -36,8 +45,7 @@ fn main() -> std::io::Result<()> {
spinner.stop("✅ Blockchain was created successfully");

loop {
let action = cliclack
::select("💡 Select an action")
let action = cliclack::select("💡 Select an action")
.initial_value("add_transaction")
.item("add_transaction", "Add a new transaction", "")
.item("get_transaction", "Get a transaction", "")
Expand All @@ -50,24 +58,33 @@ fn main() -> std::io::Result<()> {

match action {
"add_transaction" => {
let sender: String = cliclack
::input("Sender")
let sender: String = cliclack::input("Sender")
.validate(|input: &String| {
if input.is_empty() { Err("Please enter a sender") } else { Ok(()) }
if input.is_empty() {
Err("Please enter a sender")
} else {
Ok(())
}
})
.interact()?;

let receiver: String = cliclack
::input("Receiver")
let receiver: String = cliclack::input("Receiver")
.validate(|input: &String| {
if input.is_empty() { Err("Please enter a receiver") } else { Ok(()) }
if input.is_empty() {
Err("Please enter a receiver")
} else {
Ok(())
}
})
.interact()?;

let amount: f32 = cliclack
::input("Amount")
let amount: f32 = cliclack::input("Amount")
.validate(|input: &String| {
if input.is_empty() { Err("Please enter an amount") } else { Ok(()) }
if input.is_empty() {
Err("Please enter an amount")
} else {
Ok(())
}
})
.interact()?;

Expand All @@ -77,7 +94,7 @@ fn main() -> std::io::Result<()> {
let res = chain.add_transaction(
sender.trim().to_string(),
receiver.trim().to_string(),
amount
amount,
);

match res {
Expand All @@ -87,8 +104,7 @@ fn main() -> std::io::Result<()> {
}
}
"get_transaction" => {
let hash: String = cliclack
::input("Transaction hash")
let hash: String = cliclack::input("Transaction hash")
.validate(|input: &String| {
if input.is_empty() {
Err("Please enter a transaction hash")
Expand Down Expand Up @@ -116,10 +132,13 @@ fn main() -> std::io::Result<()> {
}
}
"change_reward" => {
let new_reward: String = cliclack
::input("New reward")
let new_reward: String = cliclack::input("New reward")
.validate(|input: &String| {
if input.is_empty() { Err("Please enter a new reward") } else { Ok(()) }
if input.is_empty() {
Err("Please enter a new reward")
} else {
Ok(())
}
})
.interact()?;

Expand All @@ -135,10 +154,13 @@ fn main() -> std::io::Result<()> {
}
}
"change_difficulty" => {
let new_difficulty: u32 = cliclack
::input("New difficulty")
let new_difficulty: u32 = cliclack::input("New difficulty")
.validate(|input: &String| {
if input.is_empty() { Err("Please enter a new difficulty") } else { Ok(()) }
if input.is_empty() {
Err("Please enter a new difficulty")
} else {
Ok(())
}
})
.interact()?;

Expand Down
6 changes: 4 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use chrono::Utc;
use serde_derive::Serialize;
use sha2::{ Sha256, Digest };
use sha2::{Digest, Sha256};
use std::fmt::Write;

/// An exchange of assets between two parties
Expand Down Expand Up @@ -115,7 +115,9 @@ impl Chain {
/// # Returns
/// An option containing a reference to the transaction if found, or `None` if not found.
pub fn get_transaction(&self, hash: String) -> Option<&Transaction> {
self.current_transactions.iter().find(|&trx| trx.hash == hash)
self.current_transactions
.iter()
.find(|&trx| trx.hash == hash)
}

/// Add a new transaction to the blockchain.
Expand Down

0 comments on commit 7622ef8

Please sign in to comment.