Skip to content
This repository was archived by the owner on Sep 3, 2025. It is now read-only.

Commit 9c4b980

Browse files
nathanmyeeNathan Yee
andauthored
Add git commit hash and date to development (#6162)
* Add git commit hash and date to development * Update link to href instead * Format with linter --------- Co-authored-by: Nathan Yee <nyee@netflix.com>
1 parent 7ad2041 commit 9c4b980

4 files changed

Lines changed: 59 additions & 12 deletions

File tree

docker/Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ ENV VITE_DISPATCH_COMMIT_HASH="Unknown"
5252
ARG VITE_DISPATCH_COMMIT_MESSAGE
5353
ENV VITE_DISPATCH_COMMIT_MESSAGE="Unknown"
5454

55+
ARG VITE_DISPATCH_COMMIT_DATE
56+
ENV VITE_DISPATCH_COMMIT_DATE="Unknown"
57+
5558
COPY . /usr/src/dispatch/
5659
RUN YARN_CACHE_FOLDER="$(mktemp -d)" \
5760
&& export YARN_CACHE_FOLDER \

src/dispatch/cli.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -820,11 +820,40 @@ def run_server(log_level):
820820
os.environ["LOG_LEVEL"] = log_level.upper()
821821
if not os.path.isdir(config.STATIC_DIR):
822822
import atexit
823+
import subprocess
823824
from subprocess import Popen
824825

825826
# take our frontend vars and export them for the frontend to consume
826827
envvars = os.environ.copy()
827828
envvars.update({x: getattr(config, x) for x in dir(config) if x.startswith("VITE_")})
829+
830+
# Add git commit information for development
831+
try:
832+
commit_hash = subprocess.check_output(
833+
["git", "rev-parse", "HEAD"], cwd=".", stderr=subprocess.DEVNULL
834+
).decode("utf-8").strip()
835+
envvars["VITE_DISPATCH_COMMIT_HASH"] = commit_hash
836+
except (subprocess.CalledProcessError, FileNotFoundError):
837+
# If git is not available or not in a git repo, use a default value
838+
envvars["VITE_DISPATCH_COMMIT_HASH"] = "dev-local"
839+
840+
try:
841+
commit_message = subprocess.check_output(
842+
["git", "log", "-1", "--pretty=%B"], cwd=".", stderr=subprocess.DEVNULL
843+
).decode("utf-8").strip()
844+
envvars["VITE_DISPATCH_COMMIT_MESSAGE"] = commit_message
845+
except (subprocess.CalledProcessError, FileNotFoundError):
846+
# If git is not available or not in a git repo, use a default value
847+
envvars["VITE_DISPATCH_COMMIT_MESSAGE"] = "Development build"
848+
849+
try:
850+
commit_date = subprocess.check_output(
851+
["git", "log", "-1", "--pretty=%cd", "--date=short"], cwd=".", stderr=subprocess.DEVNULL
852+
).decode("utf-8").strip()
853+
envvars["VITE_DISPATCH_COMMIT_DATE"] = commit_date
854+
except (subprocess.CalledProcessError, FileNotFoundError):
855+
# If git is not available or not in a git repo, use a default value
856+
envvars["VITE_DISPATCH_COMMIT_DATE"] = "Unknown"
828857
is_windows = os.name == "nt"
829858
windows_cmds = ["cmd", "/c"]
830859
default_cmds = ["npm", "run", "serve"]

src/dispatch/static/dispatch/src/app/store.js

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const getDefaultRefreshState = () => {
1010

1111
const latestCommitHash = import.meta.env.VITE_DISPATCH_COMMIT_HASH
1212
const latestCommitMessage = import.meta.env.VITE_DISPATCH_COMMIT_MESSAGE
13+
const latestCommitDate = import.meta.env.VITE_DISPATCH_COMMIT_DATE
1314

1415
const state = {
1516
toggleDrawer: true,
@@ -18,6 +19,7 @@ const state = {
1819
},
1920
loading: false,
2021
currentVersion: latestCommitHash,
22+
currentVersionDate: latestCommitDate,
2123
}
2224

2325
const getters = {
@@ -36,14 +38,21 @@ const actions = {
3638
commit("SET_LOADING", value)
3739
},
3840
showCommitMessage({ commit }) {
39-
commit(
40-
"notification_backend/addBeNotification",
41-
{
42-
text: `Hash: ${latestCommitHash} | Message: ${latestCommitMessage}`,
43-
type: "success",
44-
},
45-
{ root: true }
46-
)
41+
if (latestCommitHash && latestCommitHash !== "Unknown" && latestCommitHash !== "dev-local") {
42+
// Open GitHub commit URL in a new tab
43+
const githubUrl = `https://github.com/Netflix/dispatch/commit/${latestCommitHash}`
44+
window.open(githubUrl, "_blank")
45+
} else {
46+
// Fallback to showing notification for local development or unknown commits
47+
commit(
48+
"notification_backend/addBeNotification",
49+
{
50+
text: `Hash: ${latestCommitHash} | Message: ${latestCommitMessage}`,
51+
type: "success",
52+
},
53+
{ root: true }
54+
)
55+
}
4756
},
4857
}
4958

src/dispatch/static/dispatch/src/components/AppToolbar.vue

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,17 @@
4747
/>
4848
<v-list-item
4949
v-if="currentVersion()"
50-
@click="showCommitMessage"
51-
append-icon="mdi-page-next-outline"
50+
:href="`https://github.com/Netflix/dispatch/commit/${currentVersion()}`"
51+
target="_blank"
52+
append-icon="mdi-open-in-new"
5253
>
5354
<v-list-item-title>
54-
Current version: {{ formatHash(currentVersion()) }}
55+
Current version: {{ formatHash(currentVersion())
56+
}}{{
57+
currentVersionDate() && currentVersionDate() !== "Unknown"
58+
? ` (${currentVersionDate()})`
59+
: ""
60+
}}
5561
</v-list-item-title>
5662
</v-list-item>
5763
</v-list>
@@ -230,7 +236,7 @@ export default {
230236
})
231237
},
232238
...mapState("auth", ["currentUser"]),
233-
...mapState("app", ["currentVersion"]),
239+
...mapState("app", ["currentVersion", "currentVersionDate"]),
234240
...mapActions("auth", ["logout", "getExperimentalFeatures"]),
235241
...mapActions("search", ["setQuery"]),
236242
...mapActions("organization", ["showCreateEditDialog"]),

0 commit comments

Comments
 (0)