mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Improve git commit hash lookup (#5225)
- Also get the branch name. - Use rev-parse instead of describe to get a clean hash. - Return the git hash and branch name in server_info for admin connections. - Include git hash and branch name on separate lines in --version.
This commit is contained in:
@@ -86,21 +86,42 @@ admin = 127.0.0.1
|
||||
|
||||
{
|
||||
Env env(*this);
|
||||
auto const result = env.rpc("server_info");
|
||||
BEAST_EXPECT(!result[jss::result].isMember(jss::error));
|
||||
BEAST_EXPECT(result[jss::result][jss::status] == "success");
|
||||
BEAST_EXPECT(result[jss::result].isMember(jss::info));
|
||||
auto const serverinfo = env.rpc("server_info");
|
||||
BEAST_EXPECT(serverinfo.isMember(jss::result));
|
||||
auto const& result = serverinfo[jss::result];
|
||||
BEAST_EXPECT(!result.isMember(jss::error));
|
||||
BEAST_EXPECT(result[jss::status] == "success");
|
||||
BEAST_EXPECT(result.isMember(jss::info));
|
||||
auto const& info = result[jss::info];
|
||||
BEAST_EXPECT(info.isMember(jss::build_version));
|
||||
// Git info is not guaranteed to be present
|
||||
if (info.isMember(jss::git))
|
||||
{
|
||||
auto const& git = info[jss::git];
|
||||
BEAST_EXPECT(
|
||||
git.isMember(jss::hash) || git.isMember(jss::branch));
|
||||
BEAST_EXPECT(
|
||||
!git.isMember(jss::hash) ||
|
||||
(git[jss::hash].isString() &&
|
||||
git[jss::hash].asString().size() == 40));
|
||||
BEAST_EXPECT(
|
||||
!git.isMember(jss::branch) ||
|
||||
(git[jss::branch].isString() &&
|
||||
git[jss::branch].asString().size() != 0));
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
Env env(*this);
|
||||
|
||||
// Call NetworkOPs directly and set the admin flag to false.
|
||||
// Expect that the admin ports are not included in the result.
|
||||
auto const result =
|
||||
env.app().getOPs().getServerInfo(true, false, 0);
|
||||
// Expect that the admin ports are not included in the result.
|
||||
auto const& ports = result[jss::ports];
|
||||
BEAST_EXPECT(ports.isArray() && ports.size() == 0);
|
||||
// Expect that git info is absent
|
||||
BEAST_EXPECT(!result.isMember(jss::git));
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
@@ -521,6 +521,12 @@ run(int argc, char** argv)
|
||||
{
|
||||
std::cout << "rippled version " << BuildInfo::getVersionString()
|
||||
<< std::endl;
|
||||
#ifdef GIT_COMMIT_HASH
|
||||
std::cout << "Git commit hash: " << GIT_COMMIT_HASH << std::endl;
|
||||
#endif
|
||||
#ifdef GIT_BRANCH
|
||||
std::cout << "Git build branch: " << GIT_BRANCH << std::endl;
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -2493,6 +2493,18 @@ NetworkOPsImp::getServerInfo(bool human, bool admin, bool counters)
|
||||
x[jss::expiration] = "unknown";
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(GIT_COMMIT_HASH) || defined(GIT_BRANCH)
|
||||
{
|
||||
auto& x = (info[jss::git] = Json::objectValue);
|
||||
#ifdef GIT_COMMIT_HASH
|
||||
x[jss::hash] = GIT_COMMIT_HASH;
|
||||
#endif
|
||||
#ifdef GIT_BRANCH
|
||||
x[jss::branch] = GIT_BRANCH;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
}
|
||||
info[jss::io_latency_ms] =
|
||||
static_cast<Json::UInt>(app_.getIOLatency().count());
|
||||
|
||||
Reference in New Issue
Block a user