Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,8 @@ jobs:
path: |
${{ github.workspace }}/.release/studio/artifacts/*.zip
${{ github.workspace }}/.release/studio/artifacts/*.dmg
${{ github.workspace }}/.release/studio/artifacts/*.exe
${{ github.workspace }}/.release/studio/artifacts/*.blockmap
${{ github.workspace }}/.release/studio/artifacts/*.yml

- name: Upload Studio asset to GitHub Release
Expand All @@ -366,14 +368,18 @@ jobs:
tag_name: ${{ needs.release.outputs.version }}
target_commitish: ${{ github.event.inputs.branch }}
prerelease: ${{ contains(needs.release.outputs.version, 'beta') || contains(needs.release.outputs.version, 'alpha') || contains(needs.release.outputs.version, 'rc') }}
# The zip is the artifact users download; latest-*.yml (and
# The zip is the manual download artifact; latest-*.yml (and
# beta-*.yml on prereleases) is what electron-updater fetches to
# learn the version + sha512 of the matching zip. The dmg ships
# the same .app behind a drag-to-Applications installer for
# macOS users who want a regular GUI install.
# learn the version + sha512 of the matching updater artifact. On
# Windows that updater artifact is the NSIS setup.exe; the blockmap
# supports NSIS differential downloads. The dmg ships the same .app
# behind a drag-to-Applications installer for macOS users who want a
# regular GUI install.
files: |
${{ github.workspace }}/.release/studio/artifacts/*.zip
${{ github.workspace }}/.release/studio/artifacts/*.dmg
${{ github.workspace }}/.release/studio/artifacts/*.exe
${{ github.workspace }}/.release/studio/artifacts/*.blockmap
${{ github.workspace }}/.release/studio/artifacts/*.yml
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5 changes: 4 additions & 1 deletion .github/workflows/studio-package-validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,7 @@ jobs:
with:
if-no-files-found: error
name: studio_validation_${{ matrix.platform }}_${{ matrix.arch }}
path: ${{ github.workspace }}/.release/studio/artifacts/*.zip
path: |
${{ github.workspace }}/.release/studio/artifacts/*.zip
${{ github.workspace }}/.release/studio/artifacts/*.exe
${{ github.workspace }}/.release/studio/artifacts/*.blockmap
1 change: 1 addition & 0 deletions apps/studio/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"@types/react-dom": "^18.3.1",
"concurrently": "^8.2.0",
"electron": "41.2.0",
"electron-builder": "26.0.12",
"jsdom": "29.0.2",
"less": "^4.2.0",
"tailwindcss": "4.1.11",
Expand Down
139 changes: 135 additions & 4 deletions apps/studio/scripts/package-electron.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export const artifactDir = path.join(releaseWorkspaceDir, 'artifacts');
const packagingWorkspaceDir = path.join(releaseWorkspaceDir, 'workspace');
const packagedDir = path.join(releaseWorkspaceDir, 'packaged');
const packagedAppId = 'midscene-studio-beta';
const packagedWindowsAppId = 'ai.midscene.studio.beta';
const packagedProductName = 'Midscene Studio Beta';
const packagedIgnorePatterns = [
/^\/pnpm-lock\.yaml$/,
Expand Down Expand Up @@ -196,12 +197,24 @@ export const shouldUseShellForCommand = (
platform = process.platform,
) => platform === 'win32' && /\.(cmd|bat)$/i.test(command);

export const quoteWindowsShellArg = (arg) => {
if (arg === '') {
return '""';
}
if (!/[\s"&|<>()^]/.test(arg)) {
return arg;
}
return `"${arg.replace(/(["&|<>()^])/g, '^$1')}"`;
};

const run = (command, args, { cwd = workspaceRootDir, env } = {}) =>
new Promise((resolve, reject) => {
const child = spawn(command, args, {
const shell = shouldUseShellForCommand(command);
const spawnArgs = shell ? args.map(quoteWindowsShellArg) : args;
const child = spawn(command, spawnArgs, {
cwd,
env: env ? { ...process.env, ...env } : process.env,
shell: shouldUseShellForCommand(command),
shell,
stdio: 'inherit',
});

Expand Down Expand Up @@ -434,6 +447,57 @@ export const buildPackagerOptions = ({ arch, outDir, platform, stageDir }) => ({
const packageManagerCommand =
process.platform === 'win32' ? 'pnpm.cmd' : 'pnpm';

export const buildWindowsNsisArtifactName = (baseName) =>
`${baseName}-setup.exe`;

export const buildWindowsNsisConfig = ({ artifactName, iconPath }) => ({
appId: packagedWindowsAppId,
productName: packagedProductName,
directories: {
output: artifactDir,
},
win: {
// `@electron/packager` names the prepackaged executable from its `name`
// option. electron-builder does not rename that executable when using
// `--prepackaged`, so NSIS must target the exact same product filename for
// shortcuts, process shutdown, and updater relaunch.
executableName: packagedProductName,
target: [
{
target: 'nsis',
arch: ['x64'],
},
],
...(iconPath ? { icon: iconPath } : {}),
},
nsis: {
oneClick: true,
perMachine: false,
allowElevation: false,
artifactName,
shortcutName: packagedProductName,
uninstallDisplayName: packagedProductName,
createDesktopShortcut: 'always',
},
npmRebuild: false,
publish: null,
});

export const buildWindowsNsisInstallerArgs = ({
arch,
configPath,
packagedAppPath,
}) => [
'exec',
'electron-builder',
'--win',
'nsis',
`--${arch}`,
`--prepackaged=${packagedAppPath}`,
`--config=${configPath}`,
'--publish=never',
];

let cachedStudioElectronVersion;
let cachedStudioPackageJson;
let cachedWorkspacePackageCatalog;
Expand Down Expand Up @@ -2257,6 +2321,57 @@ export const notarizePackagedMacApp = async ({
return true;
};

export const buildWindowsNsisInstaller = async ({
arch,
baseName,
packagedAppPath,
}) => {
// electron-builder's NSIS target only ships x64-compatible installers on
// Windows; arm64 NSIS support is not yet stable upstream. The Studio
// package-validation and release workflows also only exercise x64 for the
// Windows matrix, so we guard here rather than let electron-builder fail
// with a less clear error downstream.
if (arch !== 'x64') {
throw new Error(
`Windows NSIS packaging only supports x64 for now, received "${arch}".`,
);
}

const artifactName = buildWindowsNsisArtifactName(baseName);
const installerPath = path.join(artifactDir, artifactName);
const configPath = path.join(artifactDir, `${baseName}.nsis.config.json`);
await removeIfExists(installerPath);
await removeIfExists(`${installerPath}.blockmap`);
await fs.mkdir(artifactDir, { recursive: true });
await fs.writeFile(
configPath,
`${JSON.stringify(
buildWindowsNsisConfig({
artifactName,
iconPath: resolvePackagerIconPath('win32'),
}),
null,
2,
)}\n`,
);

try {
await run(
packageManagerCommand,
buildWindowsNsisInstallerArgs({
arch,
configPath,
packagedAppPath,
}),
{ cwd: studioRootDir },
);
} finally {
await removeIfExists(configPath);
}

return installerPath;
};

export const packageStudioElectronApp = async ({
version,
platform = process.platform,
Expand Down Expand Up @@ -2349,11 +2464,22 @@ export const packageStudioElectronApp = async ({
artifactPath,
});

let updaterArtifactPath = artifactPath;
let windowsInstallerArtifactPath;
if (platform === 'win32') {
windowsInstallerArtifactPath = await buildWindowsNsisInstaller({
arch,
baseName,
packagedAppPath,
});
updaterArtifactPath = windowsInstallerArtifactPath;
}

// Emit the electron-updater channel manifest (latest-*.yml + beta-*.yml
// when the version is prerelease) so the GitHub Release surfaces the
// sha512/size the autoUpdater needs to verify the zip.
// sha512/size the autoUpdater needs to verify the matching update artifact.
const updateMetadata = await writeUpdateMetadataForArtifact({
artifactPath,
artifactPath: updaterArtifactPath,
artifactDir,
platform,
version: normalizedVersion,
Expand All @@ -2363,6 +2489,11 @@ export const packageStudioElectronApp = async ({
if (dmgArtifactPath) {
console.log(`Packaged Midscene Studio dmg: ${dmgArtifactPath}`);
}
if (windowsInstallerArtifactPath) {
console.log(
`Packaged Midscene Studio Windows installer: ${windowsInstallerArtifactPath}`,
);
}
for (const ymlPath of updateMetadata.writtenPaths) {
console.log(`Wrote updater manifest: ${ymlPath}`);
}
Expand Down
7 changes: 5 additions & 2 deletions apps/studio/src/main/updater-handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import path from 'node:path';
import { getDebug } from '@midscene/shared/logger';
import { IPC_CHANNELS } from '@shared/electron-contract';
import { app, ipcMain } from 'electron';
import type { UpdateStatus } from '../shared/updater-contract';
import {
type UpdateStatus,
isExternalDownloadOnlyPlatform,
} from '../shared/updater-contract';
import { type StudioUpdater, autoUpdater } from './updater';

const debugUpdaterHandlers = getDebug('studio:updater-handlers', {
Expand Down Expand Up @@ -236,7 +239,7 @@ export function resolveUpdaterCheckStatus(
releaseNotes: normalizeReleaseNotes(
(updateInfo as { releaseNotes?: unknown }).releaseNotes,
),
externalDownloadOnly: platform === 'win32' || platform === 'linux',
externalDownloadOnly: isExternalDownloadOnlyPlatform(platform),
};
}
}
Expand Down
24 changes: 12 additions & 12 deletions apps/studio/src/main/updater.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import { getDebug } from '@midscene/shared/logger';
import { IPC_CHANNELS } from '@shared/electron-contract';
import type { UpdateStatus } from '@shared/updater-contract';
import {
type UpdateStatus,
isExternalDownloadOnlyPlatform,
} from '@shared/updater-contract';
import type { BrowserWindow } from 'electron';
import { app } from 'electron';
import { autoUpdater } from 'electron-updater';

const debugUpdater = getDebug('studio:updater', { console: true });

// Studio ships on Windows/Linux as a zip from @electron/packager (no NSIS
// installer, no AppImage). electron-updater can't replace a running binary
// in either case — NsisUpdater needs an installer it doesn't have, and the
// Linux flow only knows how to relaunch an AppImage. We keep
// checkForUpdates working so the user sees that a new version exists, but
// route them to the GitHub Releases page to grab the next zip manually.
const EXTERNAL_DOWNLOAD_ONLY =
process.platform === 'win32' || process.platform === 'linux';
// Linux still ships as a plain zip from @electron/packager, and the updater
// only knows how to relaunch Linux AppImage/DEB/RPM-style targets. Windows
// release packaging now publishes an NSIS setup.exe, so NsisUpdater can keep
// the normal download + quitAndInstall path there.
const EXTERNAL_DOWNLOAD_ONLY = isExternalDownloadOnlyPlatform(process.platform);

const BACKGROUND_POLL_FIRST_DELAY_MS = 10_000;
const BACKGROUND_POLL_INTERVAL_MS = 30 * 60 * 1000;
Expand Down Expand Up @@ -49,9 +49,9 @@ export class StudioUpdater {

this.getMainWindow = getWindow;

// On macOS we route install through our own script and trigger
// download manually; on Windows/Linux the artifact is unusable
// without manual replacement. So autoDownload stays off everywhere.
// On macOS we route install through our own script and trigger downloads
// manually; Linux still routes users to the release page. Keep
// autoDownload off so the renderer-owned flow remains consistent.
autoUpdater.autoDownload = false;
autoUpdater.channel = 'latest';
autoUpdater.allowPrerelease = false;
Expand Down
6 changes: 3 additions & 3 deletions apps/studio/src/shared/external-links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ export const STUDIO_EXTERNAL_LINKS = {
'https://midscenejs.com/integrate-with-android.html#faq',
harmonyGettingStarted:
'https://midscenejs.com/harmony-getting-started.html#install-hdc',
// Used by the Windows portable build's "Open download page" action — the
// portable .exe can't replace itself, so we send the user to the GitHub
// Release to grab the next zip manually.
// Used by external-only update targets (currently Linux only — Windows now
// ships an NSIS installer that supports in-place update via NsisUpdater)
// to send the user to the GitHub Releases page for a manual download.
studioReleases: 'https://github.com/web-infra-dev/midscene/releases',
} as const;

Expand Down
13 changes: 13 additions & 0 deletions apps/studio/src/shared/updater-contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,19 @@ export type UpdateStatus =
| { state: 'downloaded'; version: string }
| { state: 'error'; message: string };

/**
* Platforms where electron-updater cannot apply the update in-place and the
* user must download the next release manually. Linux ships as a plain zip
* from @electron/packager; the updater only knows how to relaunch
* AppImage/DEB/RPM-style targets. Windows publishes an NSIS setup.exe, so
* NsisUpdater can keep the normal download + quitAndInstall path there.
*/
export function isExternalDownloadOnlyPlatform(
platform: NodeJS.Platform,
): boolean {
return platform === 'linux';
}

export interface UpdaterApi {
check: () => Promise<unknown>;
download: () => Promise<{ success: boolean; error?: string }>;
Expand Down
Loading
Loading