feat(desktop): add Windows NSIS installer (#12869)

Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
Jeffrey Aven
2026-10-15 01:15:45 +00:00
committed by GitHub
parent 7f57d5693f
commit dd17bf2021
15 changed files with 1107 additions and 63 deletions
@@ -0,0 +1,84 @@
#!/usr/bin/env node
const crypto = require('node:crypto');
const fs = require('node:fs');
const path = require('node:path');
// Copies set up by the Windows installer request this manifest (the channel set in
// src/utils/autoUpdater.ts). ZIP copies request latest.yml, which is never published for
// Windows, so they stay on the swap updater.
const MANIFEST_NAME = 'installer.yml';
const INSTALLER_NAME = 'Goose-win32-x64-setup.exe';
function usage() {
console.error(
'Usage: node scripts/generate-windows-update-manifest.js --version <version> [--directory <path>]'
);
}
function parseArgs(argv) {
const args = {
directory: process.cwd(),
version: '',
};
for (let i = 0; i < argv.length; i += 1) {
const arg = argv[i];
if (arg === '--version') {
args.version = argv[++i] || '';
} else if (arg === '--directory') {
args.directory = argv[++i] || '';
} else {
usage();
process.exit(1);
}
}
if (!args.version || !args.directory) {
usage();
process.exit(1);
}
args.version = args.version.replace(/^v/, '');
args.directory = path.resolve(args.directory);
return args;
}
function sha512(filePath) {
const hash = crypto.createHash('sha512');
hash.update(fs.readFileSync(filePath));
return hash.digest('base64');
}
function yamlString(value) {
return JSON.stringify(value);
}
function writeManifest({ directory, version }) {
const installerPath = path.join(directory, INSTALLER_NAME);
if (!fs.existsSync(installerPath)) {
throw new Error(`Missing required file: ${installerPath}`);
}
const digest = sha512(installerPath);
const manifest = [
`version: ${yamlString(version)}`,
'files:',
` - url: ${yamlString(INSTALLER_NAME)}`,
` sha512: ${yamlString(digest)}`,
` size: ${fs.statSync(installerPath).size}`,
`path: ${yamlString(INSTALLER_NAME)}`,
`sha512: ${yamlString(digest)}`,
`releaseDate: ${yamlString(new Date().toISOString())}`,
'',
].join('\n');
fs.writeFileSync(path.join(directory, MANIFEST_NAME), manifest);
}
try {
writeManifest(parseArgs(process.argv.slice(2)));
} catch (error) {
console.error(error instanceof Error ? error.message : error);
process.exit(1);
}
@@ -0,0 +1,54 @@
// electron-builder sign hook for the NSIS uninstaller and setup executable. The uninstaller is
// generated mid-build, so the signing job cannot sign it with the workflow action that signs the
// app executables. This runs the same cmdlet with the same arguments as that action, so every
// executable the installer ships carries the same signature.
const { spawnSync } = require('node:child_process');
const settings = {
Endpoint: 'AZURE_SIGNING_ENDPOINT',
CodeSigningAccountName: 'AZURE_SIGNING_ACCOUNT_NAME',
CertificateProfileName: 'AZURE_CERTIFICATE_PROFILE_NAME',
};
// The credential types the action excludes by default. The job signs in through the Azure CLI.
const excludedCredentials = [
'WorkloadIdentity',
'ManagedIdentity',
'SharedTokenCache',
'VisualStudio',
'VisualStudioCode',
'AzurePowerShell',
'AzureDeveloperCli',
'InteractiveBrowser',
];
function quote(value) {
return `'${value.replace(/'/g, "''")}'`;
}
exports.default = async ({ path }) => {
const missing = Object.values(settings).filter((name) => !process.env[name]);
if (missing.length > 0) {
throw new Error(`Cannot sign ${path}: ${missing.join(', ')} not set`);
}
const command = [
'Invoke-ArtifactSigning',
...Object.entries(settings).map(([param, name]) => `-${param} ${quote(process.env[name])}`),
`-Files ${quote(path)}`,
'-FileDigest SHA256',
'-TimestampRfc3161 http://timestamp.acs.microsoft.com',
'-TimestampDigest SHA256',
...excludedCredentials.map((name) => `-Exclude${name}Credential`),
].join(' ');
const result = spawnSync('pwsh', ['-NoProfile', '-NonInteractive', '-Command', command], {
stdio: 'inherit',
});
if (result.error) {
throw result.error;
}
if (result.status !== 0) {
throw new Error(`Invoke-ArtifactSigning exited with ${result.status} for ${path}`);
}
};