-
Notifications
You must be signed in to change notification settings - Fork 679
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DRAFT - POC for managing version across binaries #5469
base: master
Are you sure you want to change the base?
Changes from 2 commits
2bdb80e
5059081
929169e
c64d9d6
2e8fad4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,25 @@ | ||
[package] | ||
name = "stacks-common" | ||
version = "0.0.1" | ||
authors = [ "Jude Nelson <[email protected]>", | ||
"Aaron Blankstein <[email protected]>", | ||
"Ludo Galabru <[email protected]>" ] | ||
authors = [ | ||
"Jude Nelson <[email protected]>", | ||
"Aaron Blankstein <[email protected]>", | ||
"Ludo Galabru <[email protected]>", | ||
] | ||
license = "GPLv3" | ||
homepage = "https://github.com/blockstack/stacks-blockchain" | ||
repository = "https://github.com/blockstack/stacks-blockchain" | ||
description = "Common modules for blockstack_lib, libclarity" | ||
keywords = [ "stacks", "stx", "bitcoin", "crypto", "blockstack", "decentralized", "dapps", "blockchain" ] | ||
keywords = [ | ||
"stacks", | ||
"stx", | ||
"bitcoin", | ||
"crypto", | ||
"blockstack", | ||
"decentralized", | ||
"dapps", | ||
"blockchain", | ||
] | ||
readme = "README.md" | ||
resolver = "2" | ||
edition = "2021" | ||
|
@@ -22,23 +33,34 @@ rand = { workspace = true } | |
serde = "1" | ||
serde_derive = "1" | ||
serde_stacker = "0.1" | ||
serde_yaml = "0.9" | ||
sha3 = "0.10.1" | ||
ripemd = "0.1.1" | ||
lazy_static = "1.4.0" | ||
percent-encoding = "2.1.0" | ||
slog = { version = "2.5.2", features = [ "max_level_trace" ] } | ||
slog = { version = "2.5.2", features = ["max_level_trace"] } | ||
slog-term = "2.6.0" | ||
slog-json = { version = "2.3.0", optional = true } | ||
chrono = "0.4.19" | ||
libc = "0.2.82" | ||
hashbrown = { workspace = true } | ||
rusqlite = { workspace = true, optional = true } | ||
|
||
[build-dependencies] | ||
serde = "1" | ||
serde_derive = "1" | ||
serde_yaml = "0.9" | ||
|
||
[target.'cfg(unix)'.dependencies] | ||
nix = "0.23" | ||
|
||
[target.'cfg(windows)'.dependencies] | ||
winapi = { version = "0.3", features = ["consoleapi", "handleapi", "synchapi", "winbase"] } | ||
winapi = { version = "0.3", features = [ | ||
"consoleapi", | ||
"handleapi", | ||
"synchapi", | ||
"winbase", | ||
] } | ||
|
||
[target.'cfg(windows)'.dev-dependencies] | ||
winapi = { version = "0.3", features = ["fileapi", "processenv", "winnt"] } | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
use serde_derive::Serialize; | ||
use serde_derive::Deserialize; | ||
use std::fs::File; | ||
use std::io::Write; | ||
use std::env; | ||
|
||
#[derive(Serialize, Deserialize, Debug)] | ||
struct Versions { | ||
stacks_node: String, | ||
stacks_signer: String, | ||
blockstack_cli: String, | ||
clarity_cli: String, | ||
relay_server: String, | ||
stacks_inspect: String, | ||
} | ||
|
||
// get Versions struct from versions.yaml | ||
fn get_build_versions() -> Versions { | ||
let file = File::open("versions.yaml").expect("Unable to open file"); | ||
let versions: Versions = serde_yaml::from_reader(file).expect("Unable to read file"); | ||
versions | ||
} | ||
|
||
// override build versions with environment variables if they exist otherwise use passed in Versions struct | ||
fn set_build_versions() { | ||
|
||
let mut versions = get_build_versions(); | ||
|
||
if let Ok(val) = env::var("STACKS_NODE_VERSION") { | ||
versions.stacks_node = val; | ||
} | ||
if let Ok(val) = env::var("STACKS_SIGNER_VERSION") { | ||
versions.stacks_signer = val; | ||
} | ||
if let Ok(val) = env::var("BLOCKSTACK_CLI_VERSION") { | ||
versions.blockstack_cli = val; | ||
} | ||
if let Ok(val) = env::var("CLARITY_CLI_VERSION") { | ||
versions.clarity_cli = val; | ||
} | ||
if let Ok(val) = env::var("RELAY_SERVER_VERSION") { | ||
versions.relay_server = val; | ||
} | ||
if let Ok(val) = env::var("STACKS_INSPECT_VERSION") { | ||
versions.stacks_inspect = val; | ||
} | ||
write_build_versions(&versions, "versions.yaml"); | ||
} | ||
|
||
|
||
|
||
fn write_build_versions(versions: &Versions, path: &str) { | ||
let yaml_string = serde_yaml::to_string(&versions).unwrap(); | ||
let mut file = File::create(path).expect("Unable to create file"); | ||
file.write_all(yaml_string.as_bytes()).expect("Unable to write data to path"); | ||
} | ||
|
||
fn main() { | ||
set_build_versions(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
use serde::Serialize; | ||
use serde::Deserialize; | ||
use std::fs::File; | ||
|
||
#[derive(Serialize, Deserialize)] | ||
struct Versions { | ||
stacks_node: String, | ||
stacks_signer: String, | ||
blockstack_cli: String, | ||
clarity_cli: String, | ||
relay_server: String, | ||
stacks_inspect: String, | ||
} | ||
|
||
pub fn get_build_version(binary: &str) -> String { | ||
let versions = get_build_versions(); | ||
match binary { | ||
"stacks-node" => versions.stacks_node, | ||
"stacks-signer" => versions.stacks_signer, | ||
"blockstack-cli" => versions.blockstack_cli, | ||
"clarity-cli" => versions.clarity_cli, | ||
"relay-server" => versions.relay_server, | ||
"stacks-inspect" => versions.stacks_inspect, | ||
_ => panic!("Binary not found"), | ||
} | ||
} | ||
|
||
pub fn get_long_version(binary: &str) -> String { | ||
let build_version = get_build_version(binary); | ||
format!("{} ({}, {}, {})", build_version, get_target_build_type(), get_target_os(), get_target_arch()) | ||
} | ||
Comment on lines
+27
to
+30
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We already have the |
||
|
||
fn get_target_arch() -> String { | ||
let architecture = if cfg!(target_arch = "x86") { | ||
"x86" | ||
} | ||
else if cfg!(target_arch = "x86_64") { | ||
"x86_64" | ||
} | ||
else if cfg!(target_arch = "arm") { | ||
"ARM" | ||
} | ||
else if cfg!(target_arch = "aarch64") { | ||
"AArch64" | ||
} | ||
else { | ||
"unknown" | ||
}; | ||
architecture.to_string() | ||
} | ||
|
||
fn get_target_os() -> String { | ||
let os = if cfg!(target_os = "linux") { | ||
"Linux" | ||
} | ||
else if cfg!(target_os = "macos") { | ||
"macOS" | ||
} | ||
else if cfg!(target_os = "windows") { | ||
"Windows" | ||
} | ||
else { | ||
"unknown" | ||
}; | ||
os.to_string() | ||
} | ||
|
||
fn get_target_build_type() -> String { | ||
let build_type = if cfg!(debug_assertions) { | ||
"Debug" | ||
} | ||
else { | ||
"Release" | ||
}; | ||
build_type.to_string() | ||
} | ||
|
||
fn get_build_versions() -> Versions { | ||
let versions_content = include_str!("../../versions.yaml"); | ||
let versions: Versions = serde_yaml::from_str(versions_content).expect("Unable to read versions.yaml"); | ||
versions | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
stacks_node: 3.0.0.0 | ||
stacks_signer: 3.0.0.0.2 | ||
blockstack_cli: 3.0.0.0.2 | ||
clarity_cli: 3.0.0.0.2 | ||
relay_server: 3.0.0.0.2 | ||
stacks_inspect: 3.0.0.0.2 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -250,6 +250,11 @@ pub struct MonitorSignersArgs { | |
pub max_age: u64, | ||
} | ||
|
||
#[derive(Parser, Debug, Clone)] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FYI this already has a |
||
/// Arguments for the Version command | ||
pub struct VersionArgs { | ||
} | ||
|
||
#[derive(Clone, Debug, PartialEq)] | ||
/// Wrapper around `Pox4SignatureTopic` to implement `ValueEnum` | ||
pub struct StackingSignatureMethod(Pox4SignatureTopic); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need
serde_yaml
outside ofbuild_dependencies