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 2cb8efc
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 16 deletions.
21 changes: 9 additions & 12 deletions backend/lib/updater/Updater.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ const GithubValetudoUpdateProvider = require("./lib/update_provider/GithubValetu
const Logger = require("../Logger");
const States = require("../entities/core/updater");
const Steps = require("./lib/steps");
const Tools = require("../utils/Tools");



class Updater {
Expand Down Expand Up @@ -44,15 +42,6 @@ class Updater {
clearTimeout(this.pendingCleanupTimeout);
this.cleanupHandler();

if (updaterConfig.enabled === true) {
this.state = new States.ValetudoUpdaterIdleState({
currentVersion: Tools.GET_VALETUDO_VERSION()
});
} else {
this.state = new States.ValetudoUpdaterDisabledState({});
}


switch (updaterConfig.updateProvider.type) {
case GithubValetudoUpdateProvider.TYPE:
this.updateProvider = new GithubValetudoUpdateProvider();
Expand All @@ -63,6 +52,14 @@ class Updater {
default:
throw new Error(`Invalid UpdateProvider ${updaterConfig.updateProvider.type}`);
}

if (updaterConfig.enabled === true) {
this.state = new States.ValetudoUpdaterIdleState({
currentVersion: this.updateProvider.getCurrentVersion()
});
} else {
this.state = new States.ValetudoUpdaterDisabledState({});
}
}

/**
Expand Down Expand Up @@ -143,7 +140,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 All @@ -22,6 +26,7 @@ class GithubValetudoNightlyUpdateProvider extends ValetudoUpdateProvider {
}

let changelog = rawBranchResponse.data.commit.commit.message;
let version = rawBranchResponse.data.commit.sha;
let manifest;

try {
Expand All @@ -30,13 +35,16 @@ class GithubValetudoNightlyUpdateProvider extends ValetudoUpdateProvider {
if (typeof manifest?.changelog === "string") {
changelog = manifest.changelog;
}
if (typeof manifest?.version === "string") {
version = manifest.version;
}
} catch (e) {
// intentional
}

return [
new ValetudoRelease({
version: rawBranchResponse.data.commit.sha,
version: version,
releaseTimestamp: new Date(rawBranchResponse.data.commit.commit.committer.date),
changelog: changelog,
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ 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 2cb8efc

Please sign in to comment.