fix(electron): make sure updater receive correct installer files (#8798)

fix AF-1680
This commit is contained in:
forehalo
2024-11-13 07:48:37 +00:00
parent 01d1631fe8
commit b3b1ea2f33
13 changed files with 356 additions and 122 deletions

View File

@@ -3,17 +3,25 @@ import fs from 'node:fs';
import path from 'node:path';
const filenamesMapping = {
windows: 'latest.yml',
all: 'latest.yml',
macos: 'latest-mac.yml',
linux: 'latest-linux.yml',
};
const releaseFiles = ['zip', 'exe', 'dmg', 'appimage', 'deb', 'flatpak'];
const generateYml = platform => {
const yml = {
version: process.env.RELEASE_VERSION ?? '0.0.0',
files: [],
};
const regex = new RegExp(`^affine-.*-${platform}-.*.(exe|zip|dmg|appimage)$`);
const regex =
// we involves all distribution files in one release file to enforce we handle auto updater correctly
platform === 'all'
? new RegExp(`.(${releaseFiles.join('|')})$`)
: new RegExp(`.+-${platform}-.+.(${releaseFiles.join('|')})$`);
const files = fs.readdirSync(process.cwd()).filter(file => regex.test(file));
const outputFileName = filenamesMapping[platform];
@@ -34,11 +42,14 @@ const generateYml = platform => {
});
} catch {}
});
// path & sha512 are deprecated
yml.path = yml.files[0].url;
yml.sha512 = yml.files[0].sha512;
yml.releaseDate = new Date().toISOString();
// NOTE(@forehalo): make sure old windows x64 won't fetch windows arm64 by default
// maybe we need to separate arm64 builds to separated yml file `latest-arm64.yml`, `latest-linux-arm64.yml`
// check https://github.com/electron-userland/electron-builder/blob/master/packages/electron-updater/src/providers/Provider.ts#L30
// and packages/frontend/apps/electron/src/main/updater/affine-update-provider.ts#L100
yml.files.sort(a => (a.url.includes('windows-arm64') ? 1 : -1));
const ymlStr =
`version: ${yml.version}\n` +
`files:\n` +
@@ -51,13 +62,11 @@ const generateYml = platform => {
);
})
.join('') +
`path: ${yml.path}\n` +
`sha512: ${yml.sha512}\n` +
`releaseDate: ${yml.releaseDate}\n`;
fs.writeFileSync(outputFileName, ymlStr);
};
generateYml('windows');
generateYml('macos');
generateYml('linux');
generateYml('all');

View File

@@ -5,7 +5,6 @@ import { newError } from 'builder-util-runtime';
import type {
AppUpdater,
ResolvedUpdateFileInfo,
UpdateFileInfo,
UpdateInfo,
} from 'electron-updater';
import { CancellationToken, Provider } from 'electron-updater';
@@ -23,12 +22,18 @@ interface GithubUpdateInfo extends UpdateInfo {
}
interface GithubRelease {
url: string;
name: string;
tag_name: string;
body: string;
draft: boolean;
prerelease: boolean;
created_at: string;
published_at: string;
assets: Array<{
name: string;
url: string;
size: number;
}>;
}
@@ -92,11 +97,15 @@ export class AFFiNEUpdateProvider extends Provider<GithubUpdateInfo> {
const latestRelease = releases[0] as GithubRelease;
const tag = latestRelease.tag_name;
const channelFileName = getChannelFilename(this.getDefaultChannelName());
const channelFileAsset = latestRelease.assets.find(({ url }) =>
url.endsWith(channelFileName)
const channelFileName = 'latest.yml';
const channelFileAsset = latestRelease.assets.find(
({ name }) => name === channelFileName
);
// TODO(@forehalo):
// we need a way to let UI thread prompt user to manually install the latest version,
// if we introduce breaking changes on auto updater in the future.
// for example we rename the release file from `latest.yml` to `release.yml`
if (!channelFileAsset) {
throw newError(
`Cannot find ${channelFileName} in the latest release artifacts.`,
@@ -113,32 +122,30 @@ export class AFFiNEUpdateProvider extends Provider<GithubUpdateInfo> {
channelFileUrl
);
const files: UpdateFileInfo[] = [];
result.files.forEach(file => {
const asset = latestRelease.assets.find(({ name }) => name === file.url);
if (asset) {
file.url = asset.url;
}
// for windows, we need to determine its installer type (nsis or squirrel)
if (process.platform === 'win32') {
const isSquirrel = isSquirrelBuild();
if (isSquirrel && file.url.endsWith('.nsis.exe')) {
return;
result.files
.filter(({ url }) =>
availableForMyPlatformAndInstaller(
url,
process.platform,
process.arch,
isSquirrelBuild()
)
)
.forEach(file => {
const asset = latestRelease.assets.find(
({ name }) => name === file.url
);
if (asset) {
file.url = asset.url;
}
}
files.push(file);
});
});
if (result.releaseName == null) {
result.releaseName = latestRelease.name;
}
if (result.releaseNotes == null) {
// TODO(@forehalo): add release notes
result.releaseNotes = '';
result.releaseNotes = latestRelease.body;
}
return {
@@ -150,13 +157,130 @@ export class AFFiNEUpdateProvider extends Provider<GithubUpdateInfo> {
resolveFiles(updateInfo: GithubUpdateInfo): Array<ResolvedUpdateFileInfo> {
const files = getFileList(updateInfo);
return files.map(file => ({
url: new URL(file.url),
info: file,
}));
return files
.filter(({ url }) =>
availableForMyPlatformAndInstaller(
url,
process.platform,
process.arch,
isSquirrelBuild()
)
)
.map(file => ({
url: new URL(file.url),
info: file,
}));
}
}
function getChannelFilename(channel: string): string {
return `${channel}.yml`;
type VersionDistribution = 'canary' | 'beta' | 'stable';
type VersionPlatform = 'windows' | 'macos' | 'linux';
type VersionArch = 'x64' | 'arm64';
type FileParts =
| ['affine', string, VersionDistribution, VersionPlatform, VersionArch]
| [
'affine',
string,
`${'canary' | 'beta'}.${number}`,
VersionDistribution,
VersionPlatform,
VersionArch,
];
export function availableForMyPlatformAndInstaller(
file: string,
platform: NodeJS.Platform,
arch: NodeJS.Architecture,
// moved to parameter to make test coverage easier
imWindowsSquirrelPkg: boolean
): boolean {
const imArm64 = arch === 'arm64';
const imX64 = arch === 'x64';
const imMacos = platform === 'darwin';
const imWindows = platform === 'win32';
const imLinux = platform === 'linux';
// in form of:
// affine-${build}-${buildSuffix}-${distribution}-${platform}-${arch}.${installer}
// ^ 1.0.0 ^canary.1 ^ canary ^windows ^ x64 ^.nsis.exe
const filename = file.split('/').pop();
if (!filename) {
return false;
}
const parts = filename.split('-') as FileParts;
// fix -${arch}.${installer}
const archDotInstaller = parts[parts.length - 1];
const installerIdx = archDotInstaller.indexOf('.');
if (installerIdx === -1) {
return false;
}
const installer = archDotInstaller.substring(installerIdx + 1);
parts[parts.length - 1] = archDotInstaller.substring(0, installerIdx);
let version: {
build: string;
suffix?: string;
distribution: VersionDistribution;
platform: VersionPlatform;
arch: VersionArch;
installer: string;
};
if (parts.length === 5) {
version = {
build: parts[1],
distribution: parts[2],
platform: parts[3],
arch: parts[4],
installer,
};
} else if (parts.length === 6) {
version = {
build: parts[1],
suffix: parts[2],
distribution: parts[3],
platform: parts[4],
arch: parts[5],
installer,
};
} else {
return false;
}
function matchPlatform(platform: VersionPlatform) {
return (
(platform === 'windows' && imWindows) ||
(platform === 'macos' && imMacos) ||
(platform === 'linux' && imLinux)
);
}
function matchArch(arch: VersionArch) {
return (
// off course we can install x64 on x64
(imX64 && arch === 'x64') ||
// arm64 macos can install arm64 or x64 in rosetta2
(imArm64 && (arch === 'arm64' || imMacos))
);
}
function matchInstaller(installer: string) {
// do not allow squirrel or nsis installer to cross download each other on windows
if (!imWindows) {
return true;
}
return imWindowsSquirrelPkg
? installer === 'exe'
: installer === 'nsis.exe';
}
return (
matchPlatform(version.platform) &&
matchArch(version.arch) &&
matchInstaller(version.installer)
);
}

View File

@@ -0,0 +1,50 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`testing for client update > filter valid installer files > filter for platform [darwin] arch [arm64] 1`] = `
[
"affine-0.18.0-stable-macos-arm64.dmg",
"affine-0.18.0-stable-macos-arm64.zip",
"affine-0.18.0-stable-macos-x64.dmg",
"affine-0.18.0-stable-macos-x64.zip",
]
`;
exports[`testing for client update > filter valid installer files > filter for platform [darwin] arch [x64] 1`] = `
[
"affine-0.18.0-stable-macos-x64.dmg",
"affine-0.18.0-stable-macos-x64.zip",
]
`;
exports[`testing for client update > filter valid installer files > filter for platform [linux] arch [x64] 1`] = `
[
"affine-0.18.0-stable-linux-x64.appimage",
"affine-0.18.0-stable-linux-x64.deb",
"affine-0.18.0-stable-linux-x64.flatpak",
"affine-0.18.0-stable-linux-x64.zip",
]
`;
exports[`testing for client update > filter valid installer files > filter for platform [win32] arch [arm64] 1`] = `
[
"affine-0.18.0-stable-windows-arm64.nsis.exe",
]
`;
exports[`testing for client update > filter valid installer files > filter for platform [win32] arch [arm64] and is squirrel installer 1`] = `
[
"affine-0.18.0-stable-windows-arm64.exe",
]
`;
exports[`testing for client update > filter valid installer files > filter for platform [win32] arch [x64] 1`] = `
[
"affine-0.18.0-stable-windows-x64.nsis.exe",
]
`;
exports[`testing for client update > filter valid installer files > filter for platform [win32] arch [x64] and is squirrel installer 1`] = `
[
"affine-0.18.0-stable-windows-x64.exe",
]
`;

View File

@@ -45,6 +45,16 @@
"url": "https://github.com/toeverything/AFFiNE/releases/download/v0.17.0-canary.7/affine-0.17.0-canary.7-canary-windows-x64.nsis.exe",
"size": 133493672
},
{
"name": "affine-0.17.0-canary.7-canary-windows-arm64.exe",
"url": "https://github.com/toeverything/AFFiNE/releases/download/v0.17.0-canary.7/affine-0.17.0-canary.7-canary-windows-arm64.exe",
"size": 182557416
},
{
"name": "affine-0.17.0-canary.7-canary-windows-arm64.nsis.exe",
"url": "https://github.com/toeverything/AFFiNE/releases/download/v0.17.0-canary.7/affine-0.17.0-canary.7-canary-windows-arm64.nsis.exe",
"size": 133493672
},
{
"name": "codecov.yml",
"url": "https://github.com/toeverything/AFFiNE/releases/download/v0.17.0-canary.7/codecov.yml",

View File

@@ -1,73 +1,73 @@
[
{
"url": "https://github.com/toeverything/AFFiNE/releases/tag/v0.16.3",
"name": "0.16.3",
"tag_name": "v0.16.3",
"published_at": "2024-08-14T07:43:22Z",
"url": "https://github.com/toeverything/AFFiNE/releases/tag/v0.18.0",
"name": "0.18.0",
"tag_name": "v0.18.0",
"published_at": "2024-11-13T07:43:22Z",
"assets": [
{
"name": "affine-0.16.3-stable-linux-x64.appimage",
"url": "https://github.com/toeverything/AFFiNE/releases/download/v0.16.3/affine-0.16.3-stable-linux-x64.appimage",
"name": "affine-0.18.0-stable-linux-x64.appimage",
"url": "https://github.com/toeverything/AFFiNE/releases/download/v0.18.0/affine-0.18.0-stable-linux-x64.appimage",
"size": 178308288
},
{
"name": "affine-0.16.3-stable-linux-x64.zip",
"url": "https://github.com/toeverything/AFFiNE/releases/download/v0.16.3/affine-0.16.3-stable-linux-x64.zip",
"name": "affine-0.18.0-stable-linux-x64.zip",
"url": "https://github.com/toeverything/AFFiNE/releases/download/v0.18.0/affine-0.18.0-stable-linux-x64.zip",
"size": 176405078
},
{
"name": "affine-0.16.3-stable-macos-arm64.dmg",
"url": "https://github.com/toeverything/AFFiNE/releases/download/v0.16.3/affine-0.16.3-stable-macos-arm64.dmg",
"name": "affine-0.18.0-stable-macos-arm64.dmg",
"url": "https://github.com/toeverything/AFFiNE/releases/download/v0.18.0/affine-0.18.0-stable-macos-arm64.dmg",
"size": 168093091
},
{
"name": "affine-0.16.3-stable-macos-arm64.zip",
"url": "https://github.com/toeverything/AFFiNE/releases/download/v0.16.3/affine-0.16.3-stable-macos-arm64.zip",
"name": "affine-0.18.0-stable-macos-arm64.zip",
"url": "https://github.com/toeverything/AFFiNE/releases/download/v0.18.0/affine-0.18.0-stable-macos-arm64.zip",
"size": 167540517
},
{
"name": "affine-0.16.3-stable-macos-x64.dmg",
"url": "https://github.com/toeverything/AFFiNE/releases/download/v0.16.3/affine-0.16.3-stable-macos-x64.dmg",
"name": "affine-0.18.0-stable-macos-x64.dmg",
"url": "https://github.com/toeverything/AFFiNE/releases/download/v0.18.0/affine-0.18.0-stable-macos-x64.dmg",
"size": 175029125
},
{
"name": "affine-0.16.3-stable-macos-x64.zip",
"url": "https://github.com/toeverything/AFFiNE/releases/download/v0.16.3/affine-0.16.3-stable-macos-x64.zip",
"name": "affine-0.18.0-stable-macos-x64.zip",
"url": "https://github.com/toeverything/AFFiNE/releases/download/v0.18.0/affine-0.18.0-stable-macos-x64.zip",
"size": 174752343
},
{
"name": "affine-0.16.3-stable-windows-x64.exe",
"url": "https://github.com/toeverything/AFFiNE/releases/download/v0.16.3/affine-0.16.3-stable-windows-x64.exe",
"name": "affine-0.18.0-stable-windows-x64.exe",
"url": "https://github.com/toeverything/AFFiNE/releases/download/v0.18.0/affine-0.18.0-stable-windows-x64.exe",
"size": 177757416
},
{
"name": "affine-0.16.3-stable-windows-x64.nsis.exe",
"url": "https://github.com/toeverything/AFFiNE/releases/download/v0.16.3/affine-0.16.3-stable-windows-x64.nsis.exe",
"name": "affine-0.18.0-stable-windows-x64.nsis.exe",
"url": "https://github.com/toeverything/AFFiNE/releases/download/v0.18.0/affine-0.18.0-stable-windows-x64.nsis.exe",
"size": 130302976
},
{
"name": "codecov.yml",
"url": "https://github.com/toeverything/AFFiNE/releases/download/v0.16.3/codecov.yml",
"url": "https://github.com/toeverything/AFFiNE/releases/download/v0.18.0/codecov.yml",
"size": 91
},
{
"name": "latest-linux.yml",
"url": "https://github.com/toeverything/AFFiNE/releases/download/v0.16.3/latest-linux.yml",
"url": "https://github.com/toeverything/AFFiNE/releases/download/v0.18.0/latest-linux.yml",
"size": 539
},
{
"name": "latest-mac.yml",
"url": "https://github.com/toeverything/AFFiNE/releases/download/v0.16.3/latest-mac.yml",
"url": "https://github.com/toeverything/AFFiNE/releases/download/v0.18.0/latest-mac.yml",
"size": 865
},
{
"name": "latest.yml",
"url": "https://github.com/toeverything/AFFiNE/releases/download/v0.16.3/latest.yml",
"url": "https://github.com/toeverything/AFFiNE/releases/download/v0.18.0/latest.yml",
"size": 540
},
{
"name": "web-static.zip",
"url": "https://github.com/toeverything/AFFiNE/releases/download/v0.16.3/web-static.zip",
"url": "https://github.com/toeverything/AFFiNE/releases/download/v0.18.0/web-static.zip",
"size": 61989498
}
]

View File

@@ -1,11 +0,0 @@
version: 0.16.3
files:
- url: affine-0.16.3-stable-linux-x64.appimage
sha512: nmID71T7jq9yKCdujVUeL71TLXmwIdaaWZB0ouDX13Np1vahS1+1A5uJbHUzTH0N/sN0W+LKUg9L29wNgi42gw==
size: 178308288
- url: affine-0.16.3-stable-linux-x64.zip
sha512: fsHTT0fUeU/uLGdlRiuddzSuJWIOcaUTgUj7DB5XSQJ4qA5blAcpij8zOil0ww3Ea7Kwe7qcIe4SSCtNFu31sQ==
size: 176405078
path: affine-0.16.3-stable-linux-x64.appimage
sha512: nmID71T7jq9yKCdujVUeL71TLXmwIdaaWZB0ouDX13Np1vahS1+1A5uJbHUzTH0N/sN0W+LKUg9L29wNgi42gw==
releaseDate: 2024-08-14T07:11:42.171Z

View File

@@ -1,17 +0,0 @@
version: 0.16.3
files:
- url: affine-0.16.3-stable-macos-arm64.dmg
sha512: fmJWpi45gVYYUavb0Cd6Y9DR2nxBc3wMagHOiMF1PPg+4tEyHGmVIhRIwY/QaJ5TAR+3tRAENZwen2gvja0UtQ==
size: 168093091
- url: affine-0.16.3-stable-macos-arm64.zip
sha512: u1ud8pJ613A5Oqh3fbcnUUOA4hNoURWBdtAMJoeZ6EIAUvZzV0tsDcAqLiEP89LKbitaH0IdrW3D8EFSsZ9kRw==
size: 167540517
- url: affine-0.16.3-stable-macos-x64.dmg
sha512: Ou1W6/xHyM+ZN9BLYvc+8qCB8wR9F3jLQP5m3oG0uIDDw7wwoR+ny3gcWbDzalfxoOR84CvM74LIfc7BQf69Uw==
size: 175029125
- url: affine-0.16.3-stable-macos-x64.zip
sha512: oot098M9qqdRbw+znnuLjVedZ1U59p4m+gzSxRtpCuYdfvumvu5/RN1jvY2cHssqstJj/Ybh4eBTlREZMgKyyg==
size: 174752343
path: affine-0.16.3-stable-macos-arm64.dmg
sha512: fmJWpi45gVYYUavb0Cd6Y9DR2nxBc3wMagHOiMF1PPg+4tEyHGmVIhRIwY/QaJ5TAR+3tRAENZwen2gvja0UtQ==
releaseDate: 2024-08-14T07:11:41.503Z

View File

@@ -1,11 +0,0 @@
version: 0.16.3
files:
- url: affine-0.16.3-stable-windows-x64.exe
sha512: 47zaLkAhSxPuWsKq01dSEt8GusXqK1rmSaiOTBLe32lmUiXPhUqYO5JhzbrjJKx7/TFcic4UDJ/Zir3wf9fKRA==
size: 177757416
- url: affine-0.16.3-stable-windows-x64.nsis.exe
sha512: G3Rxa3onqlJTGQIcz7Rz6ZQ/6rAwjzjYnW/HB5yzXkjN6e5yfW2JBk765+AyiPFV5Mn4Rloj7V6GM6m4q7WfWg==
size: 130302976
path: affine-0.16.3-stable-windows-x64.exe
sha512: 47zaLkAhSxPuWsKq01dSEt8GusXqK1rmSaiOTBLe32lmUiXPhUqYO5JhzbrjJKx7/TFcic4UDJ/Zir3wf9fKRA==
releaseDate: 2024-08-14T07:11:40.285Z

View File

@@ -3,9 +3,13 @@ files:
- url: affine-0.17.0-canary.7-canary-linux-x64.appimage
sha512: qspZkDlItrHu02vSItbjc3I+t4FcOiHOzGt0Ap6IeZEFKal+hoOh4WIcUN16dlS/OoFm+is8yPBHqN/70xhWKA==
size: 181990592
- url: affine-0.17.0-canary.7-canary-linux-x64.deb
sha512: fom2iuMiPUlnHAGJhQdAnWJwMggK4rloNkiWqH8ZHF1Q09oturgSMGgkUEWZWXsZPpORt545eYNv5Zg9aff8yQ==
size: 180105256
- url: affine-0.17.0-canary.7-canary-linux-x64.flatpak
sha512: fom2iuMiPUlnHAGJhQdAnWJwMggK4rloNkiWqH8ZHF1Q09oturgSMGgkUEWZWXsZPpORt545eYNv5Zg9aff8yQ==
size: 180105256
- url: affine-0.17.0-canary.7-canary-linux-x64.zip
sha512: fom2iuMiPUlnHAGJhQdAnWJwMggK4rloNkiWqH8ZHF1Q09oturgSMGgkUEWZWXsZPpORt545eYNv5Zg9aff8yQ==
size: 180105256
path: affine-0.17.0-canary.7-canary-linux-x64.appimage
sha512: qspZkDlItrHu02vSItbjc3I+t4FcOiHOzGt0Ap6IeZEFKal+hoOh4WIcUN16dlS/OoFm+is8yPBHqN/70xhWKA==
releaseDate: 2024-08-29T08:20:53.453Z

View File

@@ -12,6 +12,4 @@ files:
- url: affine-0.17.0-canary.7-canary-macos-x64.zip
sha512: PL24krtjeiQY53F7OuS+hh8EZP3YpbLle0JboXiddSrulypxzBRquOCCinNW88Kg8ZJbOrfTkxaNOHpOAVfeaQ==
size: 176948223
path: affine-0.17.0-canary.7-canary-macos-arm64.dmg
sha512: Tdy7dgrCHP95PjsZBt1evxUk7DUkn+JpseBQj1Gz60MmcsFx+0NtJvofZbUcsLFiS0IC32JM/szHlHiNGEznrQ==
releaseDate: 2024-08-29T08:20:52.810Z

View File

@@ -6,6 +6,10 @@ files:
- url: affine-0.17.0-canary.7-canary-windows-x64.nsis.exe
sha512: ztugqKwPpxDDSK1OpzUPkGvL8wLXwg9rh985bs9ZvxydY037yKBAZOk96PPtow2qqRb5/9Xn8MuGrWgchqXkVg==
size: 133493672
path: affine-0.17.0-canary.7-canary-windows-x64.exe
sha512: cF47Wcu69PXyMVswSzrdNktNO2lqkjsyJ/HQr2qWjFPuIJfcad9QDTfOyCVsMCV6KGUSSeFiTHyObWgKd6z2DQ==
- url: affine-0.17.0-canary.7-canary-windows-arm64.exe
sha512: cF47Wcu69PXyMVswSzrdNktNO2lqkjsyJ/HQr2qWjFPuIJfcad9QDTfOyCVsMCV6KGUSSeFiTHyObWgKd6z2DQ==
size: 182557416
- url: affine-0.17.0-canary.7-canary-windows-arm64.nsis.exe
sha512: ztugqKwPpxDDSK1OpzUPkGvL8wLXwg9rh985bs9ZvxydY037yKBAZOk96PPtow2qqRb5/9Xn8MuGrWgchqXkVg==
size: 133493672
releaseDate: 2024-08-29T08:20:51.573Z

View File

@@ -0,0 +1,39 @@
version: 0.18.0
files:
- url: affine-0.18.0-stable-windows-x64.exe
sha512: cF47Wcu69PXyMVswSzrdNktNO2lqkjsyJ/HQr2qWjFPuIJfcad9QDTfOyCVsMCV6KGUSSeFiTHyObWgKd6z2DQ==
size: 182557416
- url: affine-0.18.0-stable-windows-x64.nsis.exe
sha512: ztugqKwPpxDDSK1OpzUPkGvL8wLXwg9rh985bs9ZvxydY037yKBAZOk96PPtow2qqRb5/9Xn8MuGrWgchqXkVg==
size: 133493672
- url: affine-0.18.0-stable-windows-arm64.exe
sha512: cF47Wcu69PXyMVswSzrdNktNO2lqkjsyJ/HQr2qWjFPuIJfcad9QDTfOyCVsMCV6KGUSSeFiTHyObWgKd6z2DQ==
size: 182557416
- url: affine-0.18.0-stable-windows-arm64.nsis.exe
sha512: ztugqKwPpxDDSK1OpzUPkGvL8wLXwg9rh985bs9ZvxydY037yKBAZOk96PPtow2qqRb5/9Xn8MuGrWgchqXkVg==
size: 133493672
- url: affine-0.18.0-stable-linux-x64.appimage
sha512: qspZkDlItrHu02vSItbjc3I+t4FcOiHOzGt0Ap6IeZEFKal+hoOh4WIcUN16dlS/OoFm+is8yPBHqN/70xhWKA==
size: 181990592
- url: affine-0.18.0-stable-linux-x64.deb
sha512: fom2iuMiPUlnHAGJhQdAnWJwMggK4rloNkiWqH8ZHF1Q09oturgSMGgkUEWZWXsZPpORt545eYNv5Zg9aff8yQ==
size: 180105256
- url: affine-0.18.0-stable-linux-x64.flatpak
sha512: fom2iuMiPUlnHAGJhQdAnWJwMggK4rloNkiWqH8ZHF1Q09oturgSMGgkUEWZWXsZPpORt545eYNv5Zg9aff8yQ==
size: 180105256
- url: affine-0.18.0-stable-linux-x64.zip
sha512: fom2iuMiPUlnHAGJhQdAnWJwMggK4rloNkiWqH8ZHF1Q09oturgSMGgkUEWZWXsZPpORt545eYNv5Zg9aff8yQ==
size: 180105256
- url: affine-0.18.0-stable-macos-arm64.dmg
sha512: Tdy7dgrCHP95PjsZBt1evxUk7DUkn+JpseBQj1Gz60MmcsFx+0NtJvofZbUcsLFiS0IC32JM/szHlHiNGEznrQ==
size: 170556866
- url: affine-0.18.0-stable-macos-arm64.zip
sha512: pmYD0B5Z9hrzgjcHmRCKnNawoPJiO5r1RjBBZi+THVL3TyKXzpJBr9HTNQkjYnQYgqHX4q2eoONsDNCIoqTeBA==
size: 170382513
- url: affine-0.18.0-stable-macos-x64.dmg
sha512: k4a4GUmy/6MmSc1xVGJNeNCCtYylWWSRcfDoZA+syUhZFY6x3xrOft972ONsiRrJukXWlKrFmVTwoW68Ywe49A==
size: 176815834
- url: affine-0.18.0-stable-macos-x64.zip
sha512: PL24krtjeiQY53F7OuS+hh8EZP3YpbLle0JboXiddSrulypxzBRquOCCinNW88Kg8ZJbOrfTkxaNOHpOAVfeaQ==
size: 176948223
releaseDate: 2024-08-29T08:20:51.573Z

View File

@@ -2,6 +2,7 @@ import path from 'node:path';
import { fileURLToPath } from 'node:url';
import type { UpdateCheckResult } from 'electron-updater';
import { parseUpdateInfo } from 'electron-updater/out/providers/Provider';
import fs from 'fs-extra';
import { flatten } from 'lodash-es';
import { http, HttpResponse } from 'msw';
@@ -16,7 +17,10 @@ import {
vi,
} from 'vitest';
import { AFFiNEUpdateProvider } from '../../src/main/updater/affine-update-provider';
import {
AFFiNEUpdateProvider,
availableForMyPlatformAndInstaller,
} from '../../src/main/updater/affine-update-provider';
import { MockedAppAdapter, MockedUpdater } from './mocks';
const __dirname = fileURLToPath(new URL('.', import.meta.url));
@@ -27,23 +31,11 @@ vi.mock('electron', () => ({
},
}));
const platformTail = (() => {
// https://github.com/electron-userland/electron-builder/blob/master/packages/electron-updater/src/providers/Provider.ts#L30
const platform = process.platform;
if (platform === 'linux') {
const arch = process.env['TEST_UPDATER_ARCH'] || process.arch;
const archSuffix = arch === 'x64' ? '' : `-${arch}`;
return '-linux' + archSuffix;
} else {
return platform === 'darwin' ? '-mac' : '';
}
})();
describe('testing for client update', () => {
const expectReleaseList = [
{ buildType: 'stable', version: '0.16.3' },
{ buildType: 'beta', version: '0.16.3-beta.2' },
{ buildType: 'canary', version: '0.17.0-canary.7' },
{ buildType: 'stable', version: '0.18.0' },
];
const basicRequestHandlers = [
@@ -64,7 +56,7 @@ describe('testing for client update', () => {
expectReleaseList.map(({ version }) => {
return [
http.get(
`https://github.com/toeverything/AFFiNE/releases/download/v${version}/latest${platformTail}.yml`,
`https://github.com/toeverything/AFFiNE/releases/download/v${version}/latest.yml`,
async req => {
const buffer = await fs.readFile(
path.join(
@@ -83,6 +75,7 @@ describe('testing for client update', () => {
})
),
];
describe('release api request successfully', () => {
const server = setupServer(...basicRequestHandlers);
beforeAll(() => server.listen({ onUnhandledRequest: 'error' }));
@@ -108,4 +101,46 @@ describe('testing for client update', () => {
});
}
});
describe('filter valid installer files', async () => {
const platforms: NodeJS.Platform[] = ['darwin', 'win32', 'linux'];
const arches: NodeJS.Architecture[] = ['x64', 'arm64'];
for (const platform of platforms) {
for (const arch of arches) {
if (platform === 'linux' && arch === 'arm64') {
// not support arm64 on linux yet
continue;
}
const data = await fs.readFile(
path.join(__dirname, 'fixtures', 'releases', '0.18.0', `latest.yml`),
'utf-8'
);
const files = parseUpdateInfo(
data,
'',
new URL('https://affine.pro')
).files.map(file => file.url);
it(`filter for platform [${platform}] arch [${arch}]`, () => {
expect(
files.filter(file =>
availableForMyPlatformAndInstaller(file, platform, arch, false)
)
).toMatchSnapshot();
});
if (platform === 'win32') {
it(`filter for platform [${platform}] arch [${arch}] and is squirrel installer`, () => {
expect(
files.filter(file =>
availableForMyPlatformAndInstaller(file, platform, arch, true)
)
).toMatchSnapshot();
});
}
}
}
});
});