Skip to content
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

Include git hash and crate version #977

Merged
merged 8 commits into from
Feb 6, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions node/forest_libp2p/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ edition = "2018"
[dependencies]
utils = { path = "../utils" }
networks = { path = "../../types/networks" }
fil_types = { path = "../../types" }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry for the nit, but can you avoid bringing this dependency into the libp2p crate? Since the type is as simple as just git_version!(), maybe just have that in place of CURRENT_COMMIT

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @nannick, this PR looks great and I'd like to pull it in. The branch just needs to be updated and that last change (#977 (comment)) made. If you give me privileges to modify your branch I can do this for you, if you'd like :)

Sorry for the late fix on such a small PR

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fil_types = { path = "../../types" }

libp2p = { version = "0.28", default-features = false, features = [
"gossipsub",
"kad",
Expand Down
9 changes: 6 additions & 3 deletions node/forest_libp2p/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use crate::{
discovery::DiscoveryConfig,
hello::{HelloCodec, HelloProtocolName, HelloRequest, HelloResponse},
};
use fil_types::build_version::CURRENT_COMMIT;
use forest_cid::Cid;
use futures::channel::oneshot::{self, Sender as OneShotSender};
use futures::{prelude::*, stream::FuturesUnordered};
Expand Down Expand Up @@ -45,6 +46,10 @@ use std::{collections::HashMap, convert::TryInto};
use std::{task::Context, task::Poll};
use tiny_cid::Cid as Cid2;

lazy_static! {
static ref VERSION: &'static str = env!("CARGO_PKG_VERSION");
}

#[derive(NetworkBehaviour)]
#[behaviour(out_event = "ForestBehaviourEvent", poll_method = "poll")]
pub struct ForestBehaviour {
Expand Down Expand Up @@ -428,9 +433,7 @@ impl ForestBehaviour {
ping: Ping::default(),
identify: Identify::new(
"ipfs/0.1.0".into(),
// TODO update to include actual version
// https://github.com/ChainSafe/forest/issues/934
format!("forest-{}", "0.1.0"),
format!("forest-{}-{}", *VERSION, *CURRENT_COMMIT),
local_key.public(),
),
bitswap,
Expand Down
2 changes: 1 addition & 1 deletion types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ base64 = { version = "0.13", optional = true }
forest_json_utils = { path = "../utils/json_utils", optional = true, version = "0.1" }
lazy_static = "1.4"
async-std = "1.9"

git-version = "0.3.4"

[features]
json = ["base64", "forest_json_utils", "num-bigint/json"]
Expand Down
27 changes: 3 additions & 24 deletions types/src/build_version/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@
// SPDX-License-Identifier: Apache-2.0, MIT

use async_std::sync::RwLock;
use git_version::git_version;
use num_derive::FromPrimitive;
use std::{
fmt::{Display, Formatter, Result as FmtResult},
process::Command,
};
use std::fmt::{Display, Formatter, Result as FmtResult};

use serde::Serialize;
const BUILD_VERSION: &str = "0.10.2";
Expand All @@ -23,26 +21,7 @@ const MINER_API_VERSION: Version = new_version(0, 15, 0);
const WORKER_API_VERSION: Version = new_version(0, 15, 0);

lazy_static! {
static ref CURRENT_COMMIT: String = {
let output = Command::new("git")
.args(&[
"describe",
"--always",
"--match=NeVeRmAtch",
"--dirty",
"2>/dev/null",
])
.output()
.map(|s| s.stdout)
.unwrap_or_else(|_| {
Command::new("git")
.args(&["rev-parse", "--short", "HEAD", "2>/dev/null"])
.output()
.map(|s| s.stdout)
.unwrap_or_default()
});
String::from(std::str::from_utf8(&output).unwrap_or_default())
};
pub static ref CURRENT_COMMIT: String = git_version!().to_string();
pub static ref BUILD_TYPE: RwLock<BuildType> = RwLock::new(BuildType::BuildDefault);
pub static ref RUNNING_NODE_TYPE: RwLock<NodeType> = RwLock::new(NodeType::Full);
}
Expand Down