-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
433 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { createSubPubChannel } from "@homarr/redis"; | ||
|
||
import { createTRPCRouter, protectedProcedure } from "../trpc"; | ||
|
||
export const updateCheckerRouter = createTRPCRouter({ | ||
getAvailableUpdates: protectedProcedure.query(async () => { | ||
const channel = createSubPubChannel<{ | ||
availableUpdates: { name: string | null; contentHtml?: string; url: string; tag_name: string }[]; | ||
}>("homarr:update", { | ||
persist: true, | ||
}); | ||
|
||
const data = await channel.getLastDataAsync(); | ||
|
||
return data?.availableUpdates; | ||
}), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { Octokit } from "octokit"; | ||
import { compareSemVer, isValidSemVer } from "semver-parser"; | ||
|
||
import { EVERY_HOUR } from "@homarr/cron-jobs-core/expressions"; | ||
import { logger } from "@homarr/log"; | ||
import { createSubPubChannel } from "@homarr/redis"; | ||
|
||
import packageJson from "../../../../package.json"; | ||
import { createCronJob } from "../lib"; | ||
|
||
export const updateCheckerJob = createCronJob("updateChecker", EVERY_HOUR, { | ||
runOnStart: true, | ||
}).withCallback(async () => { | ||
const octokit = new Octokit(); | ||
const releases = await octokit.rest.repos.listReleases({ | ||
owner: "homarr-labs", | ||
repo: "homarr", | ||
}); | ||
|
||
const currentVersion = (packageJson as { version: string }).version; | ||
const availableReleases = []; | ||
|
||
for (const release of releases.data) { | ||
if (!isValidSemVer(release.tag_name)) { | ||
logger.warn(`Unable to parse semantic tag '${release.tag_name}'. Update check might not work.`); | ||
continue; | ||
} | ||
|
||
availableReleases.push(release); | ||
} | ||
|
||
const availableNewerReleases = availableReleases | ||
.filter((release) => compareSemVer(release.tag_name, currentVersion) > 0) | ||
.sort((releaseA, releaseB) => compareSemVer(releaseB.tag_name, releaseA.tag_name)); | ||
if (availableReleases.length > 0) { | ||
logger.info( | ||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
`Update checker found a new available version: ${availableReleases[0]!.tag_name}. Current version is ${currentVersion}`, | ||
); | ||
} else { | ||
logger.debug(`Update checker did not find any available updates. Current version is ${currentVersion}`); | ||
} | ||
|
||
const channel = createSubPubChannel<{ | ||
availableUpdates: { name: string | null; contentHtml?: string; url: string; tag_name: string }[]; | ||
}>("homarr:update", { | ||
persist: true, | ||
}); | ||
|
||
await channel.publishAsync({ | ||
availableUpdates: availableNewerReleases.map((release) => ({ | ||
name: release.name, | ||
contentHtml: release.body_html, | ||
url: release.html_url, | ||
tag_name: release.tag_name, | ||
})), | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.