mirror of
https://github.com/Hypfer/Valetudo.git
synced 2025-10-26 11:27:27 +00:00
feat(updater): Introduce a working version comparison to the nightly update channel
This commit is contained in:
parent
a96ab06546
commit
2cb8efc3f4
@ -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 {
|
||||
@ -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();
|
||||
@ -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({});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -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 = () => {};
|
||||
|
||||
@ -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(
|
||||
|
||||
@ -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")>>}
|
||||
@ -22,6 +26,7 @@ class GithubValetudoNightlyUpdateProvider extends ValetudoUpdateProvider {
|
||||
}
|
||||
|
||||
let changelog = rawBranchResponse.data.commit.commit.message;
|
||||
let version = rawBranchResponse.data.commit.sha;
|
||||
let manifest;
|
||||
|
||||
try {
|
||||
@ -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,
|
||||
})
|
||||
|
||||
@ -4,7 +4,6 @@ const ValetudoUpdateProvider = require("./ValetudoUpdateProvider");
|
||||
const {get} = require("../UpdaterUtils");
|
||||
|
||||
class GithubValetudoUpdateProvider extends ValetudoUpdateProvider {
|
||||
|
||||
/**
|
||||
* @return {Promise<Array<import("./ValetudoRelease")>>}
|
||||
*/
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user