From bc9d395e7723d2ec4d1c32546b3f27058fc3b0c8 Mon Sep 17 00:00:00 2001 From: grey Date: Mon, 10 Jul 2023 15:51:52 +0200 Subject: [PATCH] improved /version route to include git info --- src/frontend/manage/startpage.eta.html | 15 +++++++++++++-- src/index.ts | 7 +++++++ src/routes/api/v1/version.ts | 7 ++++++- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/frontend/manage/startpage.eta.html b/src/frontend/manage/startpage.eta.html index d6da456..2237ee6 100644 --- a/src/frontend/manage/startpage.eta.html +++ b/src/frontend/manage/startpage.eta.html @@ -1,7 +1,7 @@ <%~ E.includeFile("../partials/head.eta.html", {"title": "Settings"}) %> <%~ E.includeFile("../partials/controls.eta.html", {"active": "SETT"}) %>

Manage your AssetFlow instance

- +
- + <%~ E.includeFile("../partials/controlsFoot.eta.html") %> <%~ E.includeFile("../partials/foot.eta.html") %> diff --git a/src/index.ts b/src/index.ts index b86bf37..ba664cd 100644 --- a/src/index.ts +++ b/src/index.ts @@ -67,9 +67,16 @@ Sentry.init({ environment: config.global.debug ? 'development' : 'production' }); +app.locals.versionRevLong = require('child_process') +.execSync('git rev-parse HEAD') +.toString().trim() app.locals.versionRev = require('child_process') .execSync('git rev-parse --short HEAD') .toString().trim() +app.locals.versionRevLatest = require('child_process') +.execSync('git ls-remote --refs -q') +.toString().trim().split("\t")[0] +log.core.info(`Running revision ${app.locals.versionRevLong} (${app.locals.versionRevLatest} latest)`); // RequestHandler creates a separate execution context using domains, so that every // transaction/span/breadcrumb is attached to its own Hub instance diff --git a/src/routes/api/v1/version.ts b/src/routes/api/v1/version.ts index 52b285b..49c938e 100644 --- a/src/routes/api/v1/version.ts +++ b/src/routes/api/v1/version.ts @@ -2,7 +2,12 @@ import express, { Request, Response } from 'express'; function get(req: Request, res: Response) { const revision = req.app.locals.versionRev; - res.status(200).send({ version: '1.0.0', commit: revision }); + let updateAvailable = false; + if(req.app.locals.versionRevLong !== req.app.locals.versionRevLatest) { + updateAvailable = true; + } + + res.status(200).send({ version: '1.0.0', commit: revision, updateAvailable: updateAvailable }); }; export default { get };