Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

feat: add git commit hash of the build and display it as the tooltip when hovering on the version (#1553)

tianzhoubd91b81279a5
diff --git a/api/actuator.go b/api/actuator.go
index 041d4dac49..6edec76732 100644
--- a/api/actuator.go
+++ b/api/actuator.go
@@ -4,6 +4,7 @@ package api
// Actuator concept is similar to the Spring Boot Actuator
type ServerInfo struct {
Version string `json:"version"`
+ GitCommit string `json:"gitCommit"`
Readonly bool `json:"readonly"`
Demo bool `json:"demo"`
Host string `json:"host"`
diff --git a/bin/server/cmd/profile_dev.go b/bin/server/cmd/profile_dev.go
index b24b0d0a61..d3ed447fd8 100644
--- a/bin/server/cmd/profile_dev.go
+++ b/bin/server/cmd/profile_dev.go
@@ -29,6 +29,7 @@ func activeProfile(dataDir string) server.Profile {
DemoDataDir: fmt.Sprintf("demo/%s", common.ReleaseModeDev),
BackupRunnerInterval: 10 * time.Second,
Version: version,
+ GitCommit: gitcommit,
PgURL: flags.pgURL,
MetricConnectionKey: "3zcZLeX3ahvlueEJqNyJysGfVAErsjjT",
}
diff --git a/bin/server/cmd/profile_release.go b/bin/server/cmd/profile_release.go
index e8e6c20070..3331c802cc 100644
--- a/bin/server/cmd/profile_release.go
+++ b/bin/server/cmd/profile_release.go
@@ -33,6 +33,7 @@ func activeProfile(dataDir string) server.Profile {
DemoDataDir: demoDataDir,
BackupRunnerInterval: 10 * time.Minute,
Version: version,
+ GitCommit: gitcommit,
PgURL: flags.pgURL,
MetricConnectionKey: "so9lLwj5zLjH09sxNabsyVNYSsAHn68F",
}
diff --git a/frontend/src/layouts/BodyLayout.vue b/frontend/src/layouts/BodyLayout.vue
index 2cd8ffde4a..b4cf9ae4ca 100644
--- a/frontend/src/layouts/BodyLayout.vue
+++ b/frontend/src/layouts/BodyLayout.vue
@@ -44,7 +44,10 @@
<heroicons-solid:sparkles class="w-5 h-5" />
{{ $t(currentPlan) }}
</router-link>
- <div class="text-sm ml-auto text-control-light">{{ version }}</div>
+ <div class="text-sm ml-auto text-control-light tooltip-wrapper">
+ {{ version }}
+ <span v-if="gitCommit" class="tooltip">{{ gitCommit }}</span>
+ </div>
</div>
</div>
<div class="flex-shrink-0 w-14" aria-hidden="true">
@@ -83,8 +86,9 @@
<heroicons-outline:sparkles class="w-5 h-5" />
{{ $t(currentPlan) }}
</router-link>
- <div class="text-sm ml-auto text-control-light">
+ <div class="text-sm ml-auto text-control-light tooltip-wrapper">
{{ version }}
+ <span v-if="gitCommit" class="tooltip">{{ gitCommit }}</span>
</div>
</div>
</div>
@@ -245,6 +249,10 @@ export default defineComponent({
return v;
});
+ const gitCommit = computed(() => {
+ return `Git hash ${actuatorStore.gitCommit.substring(0, 7)}`;
+ });
+
const currentPlan = computed((): string => {
const plan = subscriptionStore.currentPlan;
switch (plan) {
@@ -269,6 +277,7 @@ export default defineComponent({
showIntro,
showQuickstart,
version,
+ gitCommit,
currentPlan,
isFreePlan,
};
diff --git a/frontend/src/store/modules/actuator.ts b/frontend/src/store/modules/actuator.ts
index 58f90c99c7..efae87bfd5 100644
--- a/frontend/src/store/modules/actuator.ts
+++ b/frontend/src/store/modules/actuator.ts
@@ -13,6 +13,9 @@ export const useActuatorStore = defineStore("actuator", {
version: (state) => {
return state.serverInfo?.version || "";
},
+ gitCommit: (state) => {
+ return state.serverInfo?.gitCommit || "";
+ },
isDemo: (state) => {
return state.serverInfo?.demo || false;
},
diff --git a/frontend/src/types/actuator.ts b/frontend/src/types/actuator.ts
index 33411a5593..90f64a7655 100644
--- a/frontend/src/types/actuator.ts
+++ b/frontend/src/types/actuator.ts
@@ -1,5 +1,6 @@
export type ServerInfo = {
version: string;
+ gitCommit: string;
readonly: boolean;
demo: boolean;
host: string;
diff --git a/scripts/.air.toml b/scripts/.air.toml
index 7c29b3a3b2..88dd0f9b4f 100644
--- a/scripts/.air.toml
+++ b/scripts/.air.toml
@@ -3,7 +3,16 @@ tmp_dir = ".air"
[build]
bin = "./.air/bytebase --port 8080 --frontend-port 3000 --data ."
- cmd = "go build -gcflags=all=\"-N -l\" -o ./.air/bytebase ./bin/server/main.go"
+ cmd = """
+ go build -gcflags=all=\"-N -l\" \
+ -ldflags " \
+ -X 'github.com/bytebase/bytebase/bin/server/cmd.version=development' \
+ -X 'github.com/bytebase/bytebase/bin/server/cmd.goversion=$(go version)' \
+ -X 'github.com/bytebase/bytebase/bin/server/cmd.gitcommit=$(git rev-parse HEAD)' \
+ -X 'github.com/bytebase/bytebase/bin/server/cmd.buildtime=$(date -u +"%Y-%m-%dT%H:%M:%SZ")' \
+ -X 'github.com/bytebase/bytebase/bin/server/cmd.builduser=$(id -u -n)' \
+ " \
+ -o ./.air/bytebase ./bin/server/main.go"""
delay = 1000
exclude_dir = [".air", "vendor", "frontend", "docs"]
exclude_file = []
diff --git a/scripts/.air_bb.toml b/scripts/.air_bb.toml
index 6c38b78817..0b97184250 100644
--- a/scripts/.air_bb.toml
+++ b/scripts/.air_bb.toml
@@ -3,7 +3,16 @@ tmp_dir = ".air"
[build]
bin = "./.air/bb version"
- cmd = "go build -o ./.air/bb ./bin/bb/main.go"
+ cmd = """
+ go build \
+ -ldflags " \
+ -X 'github.com/bytebase/bytebase/bin/bb/cmd.version=development' \
+ -X 'github.com/bytebase/bytebase/bin/bb/cmd.goversion=$(go version)' \
+ -X 'github.com/bytebase/bytebase/bin/bb/cmd.gitcommit=$(git rev-parse HEAD)' \
+ -X 'github.com/bytebase/bytebase/bin/bb/cmd.buildtime=$(date -u +"%Y-%m-%dT%H:%M:%SZ")' \
+ -X 'github.com/bytebase/bytebase/bin/bb/cmd.builduser=$(id -u -n)' \
+ " \
+ -o ./.air/bb ./bin/bb/main.go"""
delay = 1000
exclude_dir = [".air", "vendor", "frontend", "docs"]
exclude_file = []
diff --git a/server/actuator.go b/server/actuator.go
index 9d2deaf0c7..f7be3baeea 100644
--- a/server/actuator.go
+++ b/server/actuator.go
@@ -12,11 +12,12 @@ func (s *Server) registerActuatorRoutes(g *echo.Group) {
g.GET("/actuator/info", func(c echo.Context) error {
ctx := c.Request().Context()
serverInfo := api.ServerInfo{
- Version: s.profile.Version,
- Readonly: s.profile.Readonly,
- Demo: s.profile.Demo,
- Host: s.profile.BackendHost,
- Port: strconv.Itoa(s.profile.BackendPort),
+ Version: s.profile.Version,
+ GitCommit: s.profile.GitCommit,
+ Readonly: s.profile.Readonly,
+ Demo: s.profile.Demo,
+ Host: s.profile.BackendHost,
+ Port: strconv.Itoa(s.profile.BackendPort),
}
findRole := api.Owner
diff --git a/server/config.go b/server/config.go
index ea6e7779b5..7fde1f74c3 100644
--- a/server/config.go
+++ b/server/config.go
@@ -53,6 +53,8 @@ type Profile struct {
BackupRunnerInterval time.Duration
// Version is the bytebase's version
Version string
+ // Git commit hash of the build
+ GitCommit string
// PgURL is the optional external PostgreSQL instance connection url
PgURL string
// MetricConnectionKey is the connection key for metric.