Skip to content

Commit

Permalink
Track builder in version info
Browse files Browse the repository at this point in the history
Summary:
To prepare for more potential places that pixie artifacts might be
built, add some builder info to versions via xdefs.

Test Plan: Built the CLI and ran px version

Reviewers: zasgar, michelle

Reviewed By: michelle

Signed-off-by: Vihang Mehta <[email protected]>

Differential Revision: https://phab.corp.pixielabs.ai/D11697

GitOrigin-RevId: a3f63b6
  • Loading branch information
vihangm authored and copybaranaut committed Jun 29, 2022
1 parent 4e66e86 commit 2df268c
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 2 deletions.
2 changes: 2 additions & 0 deletions bazel/get_workspace_status.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ then
echo "STABLE_BUILD_TAG $(cat VERSION)"
echo "STABLE_BUILD_NUMBER ${BUILD_NUMBER}"
echo "STABLE_BUILD_SCM_STATUS Distribution"
echo "STABLE_BUILT_BY jenkins"

# Build buddy tags.
echo "COMMIT_SHA $(cat GIT_COMMIT)"
Expand Down Expand Up @@ -68,6 +69,7 @@ echo "STABLE_BUILD_SCM_REVISION ${git_rev}"
echo "STABLE_BUILD_TAG 0.0.0-dev"
echo "STABLE_BUILD_NUMBER 0"
echo "STABLE_BUILD_SCM_STATUS ${tree_status}"
echo "STABLE_BUILT_BY ${USER}"

# Build buddy variables.
echo "COMMIT_SHA ${git_rev}"
Expand Down
2 changes: 2 additions & 0 deletions src/shared/goversion/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ stamped_xdefs = {
"buildSCMStatus": "{STABLE_BUILD_SCM_STATUS}",
"buildSemver": "{STABLE_BUILD_TAG}",
"buildTimeStamp": "{BUILD_TIMESTAMP}",
"builtBy": "{STABLE_BUILT_BY}",
}

unstamped_xdefs = {
Expand All @@ -32,6 +33,7 @@ unstamped_xdefs = {
"buildSCMStatus": "Modified",
"buildSemver": "0.0.0-dev",
"buildTimeStamp": "0",
"builtBy": "Unknown",
}

go_library(
Expand Down
9 changes: 9 additions & 0 deletions src/shared/goversion/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ var (
buildSemver = "0.0.0-dev"
buildTimeStamp = "0"
buildNumber = "0"
builtBy = "Unknown"
)

var versionInstance *Version
Expand All @@ -43,6 +44,7 @@ type Version struct {
buildSCMStatus string
buildSemver semver.Version
buildTimeStamp time.Time
builtBy string
}

func init() {
Expand All @@ -66,6 +68,7 @@ func init() {
buildSCMRevisionShort,
t.Format("20060102150405"),
buildNumber,
builtBy,
}
v.Build = buildMetadata

Expand All @@ -74,6 +77,7 @@ func init() {
buildSCMStatus: buildSCMStatus,
buildSemver: v,
buildTimeStamp: t,
builtBy: builtBy,
}
}

Expand All @@ -92,6 +96,11 @@ func (v *Version) BuildTimestamp() string {
return v.buildTimeStamp.UTC().String()
}

// Builder returns the built by.
func (v *Version) Builder() string {
return v.builtBy
}

// ToString returns the semver string.
func (v *Version) ToString() string {
return v.buildSemver.String()
Expand Down
4 changes: 4 additions & 0 deletions src/shared/version/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ genrule(
STABLE_BUILD_NUMBER=$$(
grep STABLE_BUILD_NUMBER bazel-out/stable-status.txt \\
| sed 's/^STABLE_BUILD_NUMBER //')
STABLE_BUILT_BY=$$(
grep STABLE_BUILT_BY bazel-out/stable-status.txt \\
| sed 's/^STABLE_BUILT_BY //')
BUILD_TIMESTAMP=$$(
Expand All @@ -47,6 +50,7 @@ genrule(
echo "#define BUILD_SCM_STATUS \\"$$STABLE_BUILD_SCM_STATUS\\"" >> $@
echo "#define BUILD_TAG \\"$$STABLE_BUILD_TAG\\"" >> $@
echo "#define BUILD_NUMBER \\"$$STABLE_BUILD_NUMBER\\"" >> $@
echo "#define BUILT_BY \\"$$STABLE_BUILT_BY\\"" >> $@
echo "#define BUILD_TIMESTAMP $$BUILD_TIMESTAMP" >> $@
cat $(location :version_linkstamp.cc) >> $@
Expand Down
2 changes: 2 additions & 0 deletions src/shared/version/placeholder_version_linkstamp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ extern const char* kBuildSCMRevision;
extern const int64_t kBuildTimeStamp;
extern const char* kBuildSemver;
extern const char* kBuildNumber;
extern const char* kBuiltBy;

const char* kBuildSCMStatus = "Modified";
const char* kBuildSCMRevision = "0000000";
const int64_t kBuildTimeStamp = 0; // UNIX TIMESTAMP seconds.
const char* kBuildSemver = "0.0.0-dev"; // Semver string.
const char* kBuildNumber = "0"; // Build number..
const char* kBuiltBy = "Unknown";
7 changes: 5 additions & 2 deletions src/shared/version/version.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,16 @@ extern const char* kBuildSCMRevision;
extern const int64_t kBuildTimeStamp;
extern const char* kBuildSemver;
extern const char* kBuildNumber;
extern const char* kBuiltBy;

namespace px {

std::string VersionInfo::Revision() { return kBuildSCMRevision; }

std::string VersionInfo::RevisionStatus() { return kBuildSCMStatus; }

std::string VersionInfo::Builder() { return kBuiltBy; }

int VersionInfo::BuildNumber() {
int build_number = 0;
bool ok = absl::SimpleAtoi(kBuildNumber, &build_number);
Expand All @@ -50,8 +53,8 @@ std::string VersionInfo::VersionString() {
std::string short_rev = Revision().substr(0, 7);
auto t = absl::FromUnixSeconds(kBuildTimeStamp);
auto build_time = absl::FormatTime("%Y%m%d%H%M", t, absl::LocalTimeZone());
return absl::Substitute("v$0+$1.$2.$3.$4.$5", kBuildSemver, RevisionStatus(), short_rev,
build_time, BuildNumber(), build_type);
return absl::Substitute("v$0+$1.$2.$3.$4.$5.$6", kBuildSemver, RevisionStatus(), short_rev,
build_time, BuildNumber(), build_type, Builder());
}

} // namespace px
6 changes: 6 additions & 0 deletions src/shared/version/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ class VersionInfo {
*/
static std::string RevisionStatus();

/**
* Get the built by.
* @return string
*/
static std::string Builder();

/**
* Returns a version string with git info, release status.
* @return string
Expand Down
2 changes: 2 additions & 0 deletions src/shared/version/version_linkstamp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ extern const char* kBuildSCMRevision;
extern const int64_t kBuildTimeStamp;
extern const char* kBuildSemver;
extern const char* kBuildNumber;
extern const char* kBuiltBy;

const char* kBuildSCMStatus = BUILD_SCM_STATUS;
const char* kBuildSCMRevision = BUILD_SCM_REVISION;
const int64_t kBuildTimeStamp = BUILD_TIMESTAMP; // UNIX TIMESTAMP seconds.
const char* kBuildSemver = BUILD_TAG; // Semver string.
const char* kBuildNumber = BUILD_NUMBER; // Build number..
const char* kBuiltBy = BUILT_BY;

0 comments on commit 2df268c

Please sign in to comment.