Skip to content

Commit

Permalink
feat(updater): Introduce a working version comparison to the nightly …
Browse files Browse the repository at this point in the history
…update channel
  • Loading branch information
Hypfer committed Jan 5, 2025
1 parent a96ab06 commit 86c6199
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 5 deletions.
4 changes: 2 additions & 2 deletions backend/lib/updater/Updater.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({});
Expand Down Expand Up @@ -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 = () => {};
Expand Down
2 changes: 1 addition & 1 deletion backend/lib/updater/lib/steps/ValetudoUpdaterCheckStep.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Array<import("./ValetudoRelease")>>}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const Tools = require("../../../utils/Tools");

Check failure on line 1 in backend/lib/updater/lib/update_provider/GithubValetudoUpdateProvider.js

View workflow job for this annotation

GitHub Actions / build (20.x)

'Tools' is assigned a value but never used
const ValetudoRelease = require("./ValetudoRelease");
const ValetudoReleaseBinary = require("./ValetudoReleaseBinary");
const ValetudoUpdateProvider = require("./ValetudoUpdateProvider");
const {get} = require("../UpdaterUtils");

class GithubValetudoUpdateProvider extends ValetudoUpdateProvider {

/**
* @return {Promise<Array<import("./ValetudoRelease")>>}
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Array<import("./ValetudoRelease")>>} These have to be sorted by release date. Element 0 should be the most recent one
Expand Down
20 changes: 19 additions & 1 deletion util/build_release_manifest.js
Original file line number Diff line number Diff line change
@@ -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(),
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 86c6199

Please sign in to comment.