Skip to content

Commit

Permalink
feat(core): Log and display git commit id
Browse files Browse the repository at this point in the history
  • Loading branch information
Hypfer committed Mar 7, 2021
1 parent 1c8c667 commit 2d94408
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 2 deletions.
8 changes: 8 additions & 0 deletions client/settings-info.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@
???
</div>
</ons-list-item>
<ons-list-item>
<div class="left">
Running commit id:
</div>
<div class="right" id="info_valetudo_commit">
???
</div>
</ons-list-item>
<ons-list-item>
<div class="left">
Newest Valetudo version:
Expand Down
1 change: 1 addition & 0 deletions client/settings-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ async function updateSettingsInfoPage() {
try {
let valetudoVersionRes = await ApiService.getValetudoVersion();
document.getElementById("info_valetudo_version").innerText = valetudoVersionRes.release;
document.getElementById("info_valetudo_commit").innerText = valetudoVersionRes.commit;

let robotRes = await ApiService.getRobot();
document.getElementById("info_device_valetudo_implementation").innerText = robotRes.implementation;
Expand Down
17 changes: 17 additions & 0 deletions lib/Tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,23 @@ class Tools {

return valetudoVersion;
}

static GET_COMMIT_ID() {
let commitId = "unknown";

try {
const rootDirectory = path.resolve(__dirname, "..");
commitId = fs.readFileSync(rootDirectory + "/.git/HEAD", {"encoding": "utf-8"}).trim();

if(commitId.match(/^ref: refs\/heads\/master$/) !== null) {
commitId = fs.readFileSync(rootDirectory + "/.git/refs/heads/master", {"encoding": "utf-8"}).trim();
}
} catch (e) {
//intentional
}

return commitId;
}
}

module.exports = Tools;
1 change: 1 addition & 0 deletions lib/Valetudo.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class Valetudo {
}

Logger.info("Starting Valetudo " + Tools.GET_VALETUDO_VERSION());
Logger.info("Commit ID: " + Tools.GET_COMMIT_ID());
Logger.info("Configuration file: " + this.config.location);
Logger.info("Logfile: " + Logger.LogFile);
Logger.info("Robot: " + this.robot.getManufacturer() + " " + this.robot.getModelName() + " (" + this.robot.constructor.name + ")");
Expand Down
3 changes: 2 additions & 1 deletion lib/webserver/ValetudoRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ class ValetudoRouter {
initRoutes() {
this.router.get("/version", (req, res) => {
res.json({
release: Tools.GET_VALETUDO_VERSION()
release: Tools.GET_VALETUDO_VERSION(),
commit: Tools.GET_COMMIT_ID()
});
});

Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
"license": "Apache-2.0",
"pkg": {
"assets": [
"client/**/*"
"client/**/*",
".git/HEAD",
".git/refs/heads/master"
]
},
"scripts": {
Expand Down

0 comments on commit 2d94408

Please sign in to comment.