Skip to content

Commit 6693708

Browse files
add version display based on git describe command to command line, logs and API (#540)
Signed-off-by: Alexey Chernyshov <[email protected]>
1 parent d3cfe70 commit 6693708

19 files changed

+131
-5
lines changed

core/api/full_node/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ target_link_libraries(api
1818
message
1919
miner_types
2020
msg_waiter
21+
node_version
2122
state_tree
2223
mpool
2324
sync

core/api/full_node/make.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "crypto/secp256k1/impl/secp256k1_provider_impl.hpp"
2020
#include "drand/beaconizer.hpp"
2121
#include "markets/retrieval/protocols/retrieval_protocol.hpp"
22+
#include "node/node_version.hpp"
2223
#include "node/pubsub_gate.hpp"
2324
#include "primitives/tipset/chain.hpp"
2425
#include "proofs/impl/proof_engine_impl.hpp"
@@ -65,6 +66,7 @@ namespace fc::api {
6566
using libp2p::peer::PeerId;
6667
using markets::retrieval::DealProposalParams;
6768
using markets::retrieval::QueryResponse;
69+
using node::kNodeVersion;
6870
using primitives::kChainEpochUndefined;
6971
using primitives::block::MsgMeta;
7072
using primitives::sector::getPreferredSealProofTypeFromWindowPoStType;
@@ -1217,7 +1219,7 @@ namespace fc::api {
12171219
};
12181220
api->Version = []() {
12191221
return VersionResult{
1220-
"fuhon", makeApiVersion(2, 1, 0), kEpochDurationSeconds};
1222+
kNodeVersion, makeApiVersion(2, 1, 0), kEpochDurationSeconds};
12211223
};
12221224
api->WalletBalance = [=](auto &address) -> outcome::result<TokenAmount> {
12231225
OUTCOME_TRY(context, tipsetContext({}));

core/api/full_node/node_api_v1_wrapper.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,17 @@
55

66
#include "api/full_node/node_api_v1_wrapper.hpp"
77

8-
#include <functional>
98
#include "const.hpp"
9+
#include "node/node_version.hpp"
1010

1111
namespace fc::api {
12+
using node::kNodeVersion;
1213

1314
std::shared_ptr<FullNodeApiV1Wrapper> makeFullNodeApiV1Wrapper() {
1415
auto api = std::make_shared<FullNodeApiV1Wrapper>();
1516
api->Version = []() {
1617
return VersionResult{
17-
"fuhon", makeApiVersion(1, 4, 0), kEpochDurationSeconds};
18+
kNodeVersion, makeApiVersion(1, 4, 0), kEpochDurationSeconds};
1819
};
1920
return api;
2021
}

core/api/storage_miner/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ target_link_libraries(storage_miner_api
1010
p2p::p2p
1111
remote_worker
1212
jwt
13+
miner_version
1314
)

core/api/storage_miner/storage_api.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
#include "api/storage_miner/storage_api.hpp"
77

88
#include "api/storage_miner/return_api.hpp"
9+
#include "miner/miner_version.hpp"
910
#include "sector_storage/impl/remote_worker.hpp"
1011

1112
namespace fc::api {
13+
using miner::kMinerVersion;
1214
using sector_storage::RemoteWorker;
1315

1416
std::shared_ptr<StorageMinerApi> makeStorageApi(
@@ -143,7 +145,7 @@ namespace fc::api {
143145
};
144146

145147
api->Version = [] {
146-
return api::VersionResult{"fuhon-miner", kMinerApiVersion, 0};
148+
return api::VersionResult{kMinerVersion, kMinerApiVersion, 0};
147149
};
148150

149151
return api;

core/common/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# SPDX-License-Identifier: Apache-2.0
44
#
55

6+
add_subdirectory(git_commit_version)
67
add_subdirectory(libp2p)
78
add_subdirectory(smoothing)
89
add_subdirectory(uri_parser)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#
2+
# Copyright Soramitsu Co., Ltd. All Rights Reserved.
3+
# SPDX-License-Identifier: Apache-2.0
4+
#
5+
6+
add_custom_target(git_commit_version_generated
7+
COMMAND ./git_commit_version.sh
8+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
9+
BYPRODUCTS ${CMAKE_CURRENT_SOURCE_DIR}/git_commit_version.cpp
10+
)
11+
add_library(git_commit_version
12+
git_commit_version.cpp
13+
)
14+
add_dependencies(git_commit_version
15+
git_commit_version_generated
16+
)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* Copyright Soramitsu Co., Ltd. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
#include "common/git_commit_version/git_commit_version.hpp"
7+
8+
namespace fc::common::git_commit_version {
9+
const std::string &getGitPrettyVersion() {
10+
static const std::string version{"@GIT_REPO_PRETTY_VERSION@"};
11+
return version;
12+
}
13+
} // namespace fc::common::git_commit_version
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* Copyright Soramitsu Co., Ltd. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
#pragma once
7+
8+
#include <string>
9+
10+
namespace fc::common::git_commit_version {
11+
12+
/**
13+
* Returns string containing git most recent tag and commit hash.
14+
*/
15+
const std::string &getGitPrettyVersion();
16+
} // namespace fc::common::git_commit_version
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/sh
2+
set -e
3+
4+
GIT_REPO_PRETTY_VERSION=$(git describe --tags --always --dirty) || GIT_REPO_PRETTY_VERSION="git-unknown"
5+
FILE=$(sed -e "s/@GIT_REPO_PRETTY_VERSION@/$GIT_REPO_PRETTY_VERSION/g" git_commit_version.cpp.in)
6+
OLD_FILE=$(cat git_commit_version.cpp) || OLD_FILE=""
7+
HASH=$(echo "$FILE" | shasum)
8+
OLD_HASH=$(echo "$OLD_FILE" | shasum)
9+
10+
if [ "$HASH" != "$OLD_HASH" ]; then
11+
echo "git_commit_version.sh: update"
12+
echo "$FILE" > git_commit_version.cpp
13+
fi

0 commit comments

Comments
 (0)