Skip to content

Commit

Permalink
chore: standardise versioning for binaries
Browse files Browse the repository at this point in the history
The RFC for the release process stipulated there should be four versioning arguments:
* --version
* --crate-version
* --package-version
* --network-version

Here, `--crate-version` is the semantic version of the crate, `--package-version` is the release
cycle version, e.g., `2024.09.1.1`, and `--network-version` prints the compatible network protocol.
The `--version` argument will then print all of this information. The `--package-version` argument
does not apply to the nightly release.

The `sn_build_info` crate is utilised to avoid repeating the setup.

Since we are going to introduce a nightly build, this commit also introduces a nightly feature,
which will control what versioning information is used. For the nightly, the binaries will be
versioned with the date on which they are built. The `--package-version` argument does not apply to
the nightly release; it is not necessary if all the binaries have the same version, which is the
date.
  • Loading branch information
jacderida committed Sep 19, 2024
1 parent bda1bc4 commit 5b0ecc6
Show file tree
Hide file tree
Showing 23 changed files with 431 additions and 57 deletions.
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions nat-detection/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ version = "0.2.4"
name = "nat-detection"
path = "src/main.rs"

[features]
nightly = []

[dependencies]
clap = { version = "4.5.4", features = ["derive"] }
clap-verbosity-flag = "2.2.0"
Expand All @@ -28,7 +31,9 @@ libp2p = { version = "0.54.1", features = [
"macros",
"upnp",
] }
sn_build_info = { path = "../sn_build_info", version = "0.1.12" }
sn_networking = { path = "../sn_networking", version = "0.18.1" }
sn_protocol = { path = "../sn_protocol", version = "0.17.8" }
tokio = { version = "1.32.0", features = ["full"] }
tracing = { version = "~0.1.26" }
tracing-log = "0.2.0"
Expand Down
33 changes: 31 additions & 2 deletions nat-detection/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use libp2p::autonat::NatStatus;
use libp2p::core::{multiaddr::Protocol, Multiaddr};
use libp2p::swarm::SwarmEvent;
use libp2p::{noise, tcp, yamux};
use sn_protocol::version::IDENTIFY_PROTOCOL_STR;
use std::collections::HashSet;
use std::net::Ipv4Addr;
use std::time::Duration;
Expand All @@ -35,7 +36,7 @@ const RETRY_INTERVAL: Duration = Duration::from_secs(10);
/// - 11: Public under UPnP
/// - 12: Private or Unknown NAT
#[derive(Debug, Parser)]
#[clap(version, author, verbatim_doc_comment)]
#[clap(version = sn_build_info::version_string(env!("CARGO_PKG_VERSION"), &IDENTIFY_PROTOCOL_STR), author, verbatim_doc_comment)]
struct Opt {
/// Port to listen on.
///
Expand All @@ -60,15 +61,43 @@ struct Opt {

#[command(flatten)]
verbose: clap_verbosity_flag::Verbosity,

/// Print the crate version
#[clap(long)]
crate_version: bool,

/// Print the protocol version
#[clap(long)]
protocol_version: bool,

/// Print the package version
#[clap(long)]
#[cfg(not(feature = "nightly"))]
package_version: bool,
}

#[tokio::main]
async fn main() -> Result<()> {
color_eyre::install()?;

// Process command line arguments.
let opt = Opt::parse();

if opt.crate_version {
println!("Crate version: {}", env!("CARGO_PKG_VERSION"));
return Ok(());
}

if opt.protocol_version {
println!("Network version: {}", IDENTIFY_PROTOCOL_STR.to_string());
return Ok(());
}

#[cfg(not(feature = "nightly"))]
if opt.package_version {
println!("Package version: {}", sn_build_info::package_version());
return Ok(());
}

let registry = tracing_subscriber::registry().with(tracing_subscriber::fmt::layer());
// Use `RUST_LOG` if set, else use the verbosity flag (where `-vvvv` is trace level).
let _ = if std::env::var_os("RUST_LOG").is_some() {
Expand Down
5 changes: 5 additions & 0 deletions node-launchpad/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ build = "build.rs"
name = "node-launchpad"
path = "src/bin/tui/main.rs"

[features]
nightly = []

[dependencies]
atty = "0.2.14"
better-panic = "0.3.0"
Expand Down Expand Up @@ -48,8 +51,10 @@ reqwest = { version = "0.12.2", default-features = false, features = [
serde = { version = "1.0.188", features = ["derive"] }
serde_json = "1.0.107"
signal-hook = "0.3.17"
sn_build_info = { path = "../sn_build_info", version = "0.1.12" }
sn-node-manager = { version = "0.10.3", path = "../sn_node_manager" }
sn_peers_acquisition = { version = "0.5.0", path = "../sn_peers_acquisition" }
sn_protocol = { path = "../sn_protocol", version = "0.17.8" }
sn-releases = "~0.2.6"
sn_service_management = { version = "0.3.11", path = "../sn_service_management" }
strip-ansi-escapes = "0.2.0"
Expand Down
32 changes: 31 additions & 1 deletion node-launchpad/src/bin/tui/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ use node_launchpad::{
#[cfg(target_os = "windows")]
use sn_node_manager::config::is_running_as_root;
use sn_peers_acquisition::PeersArgs;
use sn_protocol::version::IDENTIFY_PROTOCOL_STR;
use std::{env, path::PathBuf};
use tokio::task::LocalSet;

#[derive(Parser, Debug)]
#[command(author, version = version(), about)]
#[command(author, version = version(), about, name = "Autonomi Node Launchpad")]
pub struct Cli {
#[arg(
short,
Expand Down Expand Up @@ -53,12 +54,41 @@ pub struct Cli {

#[command(flatten)]
pub(crate) peers: PeersArgs,

/// Print the crate version.
#[clap(long)]
crate_version: bool,

/// Print the network protocol version.
#[clap(long)]
protocol_version: bool,

/// Print the package version.
#[clap(long)]
#[cfg(not(feature = "nightly"))]
package_version: bool,
}

async fn tokio_main() -> Result<()> {
initialize_panic_handler()?;
let args = Cli::parse();

if args.crate_version {
println!("{}", env!("CARGO_PKG_VERSION"));
return Ok(());
}

if args.protocol_version {
println!("{}", IDENTIFY_PROTOCOL_STR.to_string());
return Ok(());
}

#[cfg(not(feature = "nightly"))]
if args.package_version {
println!("{}", sn_build_info::package_version());
return Ok(());
}

info!("Starting app with args: {args:?}");
let mut app = App::new(
args.tick_rate,
Expand Down
16 changes: 4 additions & 12 deletions node-launchpad/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,13 @@

use crate::config::get_launchpad_data_dir_path;
use color_eyre::eyre::{Context, Result};
use sn_protocol::version::IDENTIFY_PROTOCOL_STR;
use tracing::error;
use tracing_error::ErrorLayer;
use tracing_subscriber::{
self, prelude::__tracing_subscriber_SubscriberExt, util::SubscriberInitExt, Layer,
};

const VERSION_MESSAGE: &str = concat!(
env!("CARGO_PKG_VERSION"),
"-",
env!("VERGEN_GIT_DESCRIBE"),
" (",
env!("VERGEN_BUILD_DATE"),
")"
);

pub fn initialize_panic_handler() -> Result<()> {
let (panic_hook, eyre_hook) = color_eyre::config::HookBuilder::default()
.panic_section(format!(
Expand Down Expand Up @@ -135,12 +127,12 @@ macro_rules! trace_dbg {

pub fn version() -> String {
let author = clap::crate_authors!();

let version_message =
sn_build_info::version_string(env!("CARGO_PKG_VERSION"), &IDENTIFY_PROTOCOL_STR);
let data_dir_path = get_launchpad_data_dir_path().unwrap().display().to_string();

format!(
"\
{VERSION_MESSAGE}
{version_message}
Authors: {author}
Expand Down
3 changes: 3 additions & 0 deletions sn_auditor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ local-discovery = [
"sn_peers_acquisition/local-discovery",
]
network-contacts = ["sn_peers_acquisition/network-contacts"]
nightly = []
open-metrics = ["sn_client/open-metrics"]
websockets = ["sn_client/websockets"]
svg-dag = ["graphviz-rust", "dag-collection"]
Expand All @@ -31,9 +32,11 @@ graphviz-rust = { version = "0.9.0", optional = true }
lazy_static = "1.4.0"
serde = { version = "1.0.133", features = ["derive", "rc"] }
serde_json = "1.0.108"
sn_build_info = { path = "../sn_build_info", version = "0.1.12" }
sn_client = { path = "../sn_client", version = "0.110.0" }
sn_logging = { path = "../sn_logging", version = "0.2.33" }
sn_peers_acquisition = { path = "../sn_peers_acquisition", version = "0.5.0" }
sn_protocol = { path = "../sn_protocol", version = "0.17.8" }
tiny_http = { version = "0.12", features = ["ssl-rustls"] }
tracing = { version = "~0.1.26" }
tokio = { version = "1.32.0", features = [
Expand Down
32 changes: 31 additions & 1 deletion sn_auditor/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use dag_db::SpendDagDb;
use sn_client::Client;
use sn_logging::{Level, LogBuilder, LogFormat, LogOutputDest};
use sn_peers_acquisition::PeersArgs;
use sn_protocol::version::IDENTIFY_PROTOCOL_STR;
use std::collections::BTreeSet;
use std::path::PathBuf;
use tiny_http::{Response, Server};
Expand All @@ -27,7 +28,7 @@ use tiny_http::{Response, Server};
const BETA_REWARDS_BACKUP_INTERVAL_SECS: u64 = 20 * 60;

#[derive(Parser)]
#[command(author, version, about, long_about = None)]
#[command(author, version = sn_build_info::version_string(env!("CARGO_PKG_VERSION"), &IDENTIFY_PROTOCOL_STR), about, long_about = None, name = "Autonomi Auditor")]
struct Opt {
#[command(flatten)]
peers: PeersArgs,
Expand Down Expand Up @@ -70,6 +71,19 @@ struct Opt {
/// discord usernames of the beta participants
#[clap(short = 'k', long, value_name = "hex_secret_key")]
beta_encryption_key: Option<String>,

/// Print the crate version.
#[clap(long)]
pub crate_version: bool,

/// Print the network protocol version.
#[clap(long)]
pub protocol_version: bool,

/// Print the package version.
#[cfg(not(feature = "nightly"))]
#[clap(long)]
pub package_version: bool,
}

#[tokio::main]
Expand All @@ -78,6 +92,22 @@ async fn main() -> Result<()> {
let log_builder = logging_init(opt.log_output_dest, opt.log_format)?;
let _log_handles = log_builder.initialize()?;

if opt.crate_version {
println!("{}", sn_build_info::version_string(env!("CARGO_PKG_VERSION"), &IDENTIFY_PROTOCOL_STR));
return Ok(());
}

#[cfg(not(feature = "nightly"))]
if opt.package_version {
println!("{}", sn_build_info::package_version());
return Ok(());
}

if opt.protocol_version {
println!("{}", IDENTIFY_PROTOCOL_STR.to_string());
return Ok(());
}

let beta_participants = load_and_update_beta_participants(opt.beta_participants)?;

let maybe_sk = if let Some(sk_str) = opt.beta_encryption_key {
Expand Down
8 changes: 8 additions & 0 deletions sn_build_info/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,17 @@ name = "sn_build_info"
readme = "README.md"
repository = "https://github.com/maidsafe/safe_network"
version = "0.1.12"
build = "build.rs"

[build-dependencies]
vergen = { version = "8.0.0", features = ["build", "git", "gitcl"] }

[features]
nightly = []

[lints]
workspace = true

[dependencies]
chrono = "0.4"
tracing = { version = "~0.1.26" }
28 changes: 28 additions & 0 deletions sn_build_info/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
// under the GPL Licence is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. Please review the Licences for the specific language governing
// permissions and limitations relating to use of the SAFE Network Software.
use std::fs;
use std::path::Path;
use vergen::EmitBuilder;

fn main() -> Result<(), Box<dyn std::error::Error>> {
Expand All @@ -18,5 +20,31 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
.git_describe(true, false, None)
.emit()?;

let release_info_path = Path::new("../release-cycle-info");
let contents =
fs::read_to_string(release_info_path).expect("Failed to read release-cycle-info");

let mut year = String::new();
let mut month = String::new();
let mut cycle = String::new();
let mut counter = String::new();

for line in contents.lines() {
if line.starts_with("release-year:") {
year = line.split(':').nth(1).unwrap().trim().to_string();
} else if line.starts_with("release-month:") {
month = line.split(':').nth(1).unwrap().trim().to_string();
} else if line.starts_with("release-cycle:") {
cycle = line.split(':').nth(1).unwrap().trim().to_string();
} else if line.starts_with("release-cycle-counter:") {
counter = line.split(':').nth(1).unwrap().trim().to_string();
}
}

println!("cargo:rustc-env=RELEASE_YEAR={}", year);
println!("cargo:rustc-env=RELEASE_MONTH={}", month);
println!("cargo:rustc-env=RELEASE_CYCLE={}", cycle);
println!("cargo:rustc-env=RELEASE_CYCLE_COUNTER={}", counter);

Ok(())
}
Loading

0 comments on commit 5b0ecc6

Please sign in to comment.