diff --git a/backend/lib/updater/Updater.js b/backend/lib/updater/Updater.js index a9cfaef85f2..fb54c428df8 100644 --- a/backend/lib/updater/Updater.js +++ b/backend/lib/updater/Updater.js @@ -46,7 +46,7 @@ class Updater { if (updaterConfig.enabled === true) { this.state = new States.ValetudoUpdaterIdleState({ - currentVersion: Tools.GET_VALETUDO_VERSION() + currentVersion: this.updateProvider.getCurrentVersion() }); } else { this.state = new States.ValetudoUpdaterDisabledState({}); @@ -143,7 +143,7 @@ class Updater { fs.unlinkSync(downloadPath); this.state = new States.ValetudoUpdaterIdleState({ - currentVersion: Tools.GET_VALETUDO_VERSION() + currentVersion: this.updateProvider.getCurrentVersion() }); this.cleanupHandler = () => {}; diff --git a/backend/lib/updater/lib/steps/ValetudoUpdaterCheckStep.js b/backend/lib/updater/lib/steps/ValetudoUpdaterCheckStep.js index f115bfec4f1..d45da18658d 100644 --- a/backend/lib/updater/lib/steps/ValetudoUpdaterCheckStep.js +++ b/backend/lib/updater/lib/steps/ValetudoUpdaterCheckStep.js @@ -31,7 +31,7 @@ class ValetudoUpdaterCheckStep extends ValetudoUpdaterStep { async execute() { const requiresLowmem = Tools.IS_LOWMEM_HOST(); const arch = this.architectures[process.arch]; - const currentVersion = Tools.GET_VALETUDO_VERSION(); + const currentVersion = this.updateProvider.getCurrentVersion(); if (this.embedded !== true) { throw new ValetudoUpdaterError( diff --git a/backend/lib/updater/lib/update_provider/GithubValetudoNightlyUpdateProvider.js b/backend/lib/updater/lib/update_provider/GithubValetudoNightlyUpdateProvider.js index e30afe1dd30..b7b42020ded 100644 --- a/backend/lib/updater/lib/update_provider/GithubValetudoNightlyUpdateProvider.js +++ b/backend/lib/updater/lib/update_provider/GithubValetudoNightlyUpdateProvider.js @@ -1,9 +1,13 @@ +const Tools = require("../../../utils/Tools"); const ValetudoRelease = require("./ValetudoRelease"); const ValetudoReleaseBinary = require("./ValetudoReleaseBinary"); const ValetudoUpdateProvider = require("./ValetudoUpdateProvider"); const {get} = require("../UpdaterUtils"); class GithubValetudoNightlyUpdateProvider extends ValetudoUpdateProvider { + getCurrentVersion() { + return Tools.GET_COMMIT_ID(); + } /** * @return {Promise>} diff --git a/backend/lib/updater/lib/update_provider/GithubValetudoUpdateProvider.js b/backend/lib/updater/lib/update_provider/GithubValetudoUpdateProvider.js index c545f729f03..9f5257a9b73 100644 --- a/backend/lib/updater/lib/update_provider/GithubValetudoUpdateProvider.js +++ b/backend/lib/updater/lib/update_provider/GithubValetudoUpdateProvider.js @@ -1,10 +1,10 @@ +const Tools = require("../../../utils/Tools"); const ValetudoRelease = require("./ValetudoRelease"); const ValetudoReleaseBinary = require("./ValetudoReleaseBinary"); const ValetudoUpdateProvider = require("./ValetudoUpdateProvider"); const {get} = require("../UpdaterUtils"); class GithubValetudoUpdateProvider extends ValetudoUpdateProvider { - /** * @return {Promise>} */ diff --git a/backend/lib/updater/lib/update_provider/ValetudoUpdateProvider.js b/backend/lib/updater/lib/update_provider/ValetudoUpdateProvider.js index 23a94569467..023390cfb4a 100644 --- a/backend/lib/updater/lib/update_provider/ValetudoUpdateProvider.js +++ b/backend/lib/updater/lib/update_provider/ValetudoUpdateProvider.js @@ -1,10 +1,19 @@ const NotImplementedError = require("../../../core/NotImplementedError"); +const Tools = require("../../../utils/Tools"); class ValetudoUpdateProvider { constructor() { //intentional } + /** + * This allows checking for updates based on either the valetudo version, the commit id or something else entirely + * @return {string} + */ + getCurrentVersion() { + return Tools.GET_VALETUDO_VERSION(); + } + /** * @abstract * @return {Promise>} These have to be sorted by release date. Element 0 should be the most recent one diff --git a/util/build_release_manifest.js b/util/build_release_manifest.js index 09a3f1fe84b..f243763ec83 100644 --- a/util/build_release_manifest.js +++ b/util/build_release_manifest.js @@ -1,6 +1,24 @@ const crypto = require("crypto"); const fs = require("fs"); const packageJson = require("../package.json"); +const path = require("path"); + +function GET_COMMIT_ID() { + let commitId = "nightly"; + + 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; +} const manifest = { timestamp: new Date().toISOString(), @@ -41,7 +59,7 @@ Object.values(binaries).forEach((path, i) => { }) if (process.argv.length > 2 && process.argv[2] === "nightly") { - manifest.version = "nightly"; + manifest.version = GET_COMMIT_ID(); try { manifest.changelog = fs.readFileSync("./build/changelog_nightly.md").toString();