Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(electron-updater): fix backward compatibility for GitHub provider without channels #6998

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fair-gifts-explain.md
@@ -0,0 +1,5 @@
---
"electron-updater": patch
---

fix(electron-updater): fix backward compatibility for GitHub provider without channels
56 changes: 31 additions & 25 deletions packages/electron-updater/src/providers/GitHubProvider.ts
Expand Up @@ -58,32 +58,38 @@ export class GitHubProvider extends BaseGitHubProvider<GithubUpdateInfo> {
try {
if (this.updater.allowPrerelease) {
const currentChannel = this.updater?.channel || (semver.prerelease(this.updater.currentVersion)?.[0] as string) || null
for (const element of feed.getElements("entry")) {

if (currentChannel === null) {
// noinspection TypeScriptValidateJSTypes
const hrefElement = hrefRegExp.exec(element.element("link").attribute("href"))!

// If this is null then something is wrong and skip this release
if (hrefElement === null) continue

// This Release's Tag
const hrefTag = hrefElement[1]
//Get Channel from this release's tag
const hrefChannel = (semver.prerelease(hrefTag)?.[0] as string) || null

const shouldFetchVersion = !currentChannel || ["alpha", "beta"].includes(currentChannel)
const isCustomChannel = !["alpha", "beta"].includes(String(hrefChannel))
// Allow moving from alpha to beta but not down
const channelMismatch = currentChannel === "beta" && hrefChannel === "alpha"

if (shouldFetchVersion && !isCustomChannel && !channelMismatch) {
tag = hrefTag
break
}

const isNextPreRelease = hrefChannel && hrefChannel === currentChannel
if (isNextPreRelease) {
tag = hrefTag
break
tag = hrefRegExp.exec(latestRelease.element("link").attribute("href"))![1]
} else {
for (const element of feed.getElements("entry")) {
// noinspection TypeScriptValidateJSTypes
const hrefElement = hrefRegExp.exec(element.element("link").attribute("href"))!

// If this is null then something is wrong and skip this release
if (hrefElement === null) continue

// This Release's Tag
const hrefTag = hrefElement[1]
//Get Channel from this release's tag
const hrefChannel = (semver.prerelease(hrefTag)?.[0] as string) || null

const shouldFetchVersion = !currentChannel || ["alpha", "beta"].includes(currentChannel)
const isCustomChannel = !["alpha", "beta"].includes(String(hrefChannel))
// Allow moving from alpha to beta but not down
const channelMismatch = currentChannel === "beta" && hrefChannel === "alpha"

if (shouldFetchVersion && !isCustomChannel && !channelMismatch) {
tag = hrefTag
break
}

const isNextPreRelease = hrefChannel && hrefChannel === currentChannel
if (isNextPreRelease) {
tag = hrefTag
break
}
}
}
} else {
Expand Down