Skip to content

Commit

Permalink
Add build version on main.html
Browse files Browse the repository at this point in the history
  • Loading branch information
kunyavskiy committed Dec 7, 2024
1 parent 86c8b25 commit 7fd08c6
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/backend/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,41 @@ application {
}

tasks {
val gitVersionFiles by registering {
val branch = layout.buildDirectory.file("git_branch")
val commit = layout.buildDirectory.file("git_commit")
val description = layout.buildDirectory.file("git_description")
outputs.files(branch, commit, description)
outputs.upToDateWhen { false }
doLast {
branch.get().asFile.outputStream().use { stream ->
exec {
executable = "git"
args = listOf("rev-parse", "--abbrev-ref", "HEAD")
standardOutput = stream
isIgnoreExitValue = true
}
}
commit.get().asFile.outputStream().use { stream ->
exec {
executable = "git"
args = listOf("rev-parse", "HEAD")
standardOutput = stream
isIgnoreExitValue = true
}
}
description.get().asFile.outputStream().use { stream ->
exec {
executable = "git"
args = listOf("describe", "--all", "--always", "--dirty", "--match=origin/*", "--match=v*")
standardOutput = stream
isIgnoreExitValue = true
}
}
}
}


runTask {
this.args = listOfNotNull(
"--no-auth",
Expand Down Expand Up @@ -40,6 +75,9 @@ tasks {
from(project(":frontend").projectDir.resolve("main")) {
into("main")
}
from(gitVersionFiles) {
into("main")
}
}
}
}
Expand Down
24 changes: 24 additions & 0 deletions src/frontend/main/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,34 @@
</head>
<body>
<div class="link-container">
<div id="git-commit">Commit: loading...</div>
<div id="git-branch">Branch: loading...</div>
<div id="git-description">Version: loading...</div>
<a href="/admin" class="link">/admin</a>
<a href="/overlay?noStatus" class="link">/overlay?noStatus</a>
<a href="/api/admin/advancedJsonPreview?fields=all" class="link">/api/admin/advancedJsonPreview?fields=all</a>
<a href="https://github.com/icpc/live-v3" class="link">https://github.com/icpc/live-v3</a>
</div>
<script>
fetch('/git_commit')
.then(response => response.text())
.then(commit => {
document.getElementById('git-commit').innerText = `Commit: ${commit}`
})
.catch(error => console.error('Error fetching git commit:', error));
fetch('/git_branch')
.then(response => response.text())
.then(branch => {
document.getElementById('git-branch').innerText = `Branch: ${branch}`
})
.catch(error => console.error('Error fetching git branch:', error));
fetch('/git_description')
.then(response => response.text())
.then(version => {
document.getElementById('git-description').innerText = `Version: ${version}`
})
.catch(error => console.error('Error fetching git branch:', error));
</script>

</body>
</html>

0 comments on commit 7fd08c6

Please sign in to comment.