Skip to content

Commit 457d88d

Browse files
committed
sign installer
1 parent 95ebf46 commit 457d88d

File tree

1 file changed

+78
-11
lines changed

1 file changed

+78
-11
lines changed

apps/remixdesktop/afterbuild.js

Lines changed: 78 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,99 @@
11
const fs = require('fs');
2+
const path = require('path');
3+
const { spawn } = require('child_process');
24

35
exports.default = async function afterbuild(context) {
4-
// do not run when not on macOS or when not in CI (CircleCI or GitHub Actions)
56
const isCI = process.env.CIRCLE_BRANCH || process.env.GITHUB_REF;
6-
if (process.platform !== 'darwin' || !isCI) {
7+
if (!isCI) {
78
return;
89
}
910

10-
1111
console.log('AFTER BUILD', context);
1212

13+
// Handle macOS DMG notarization
14+
if (process.platform === 'darwin') {
15+
await handleMacOSNotarization(context);
16+
}
17+
18+
// Handle Windows installer signing
19+
if (process.platform === 'win32') {
20+
await handleWindowsSigning(context);
21+
}
22+
};
23+
24+
async function handleMacOSNotarization(context) {
1325
const artifactPaths = context.artifactPaths;
14-
const newDmgs = artifactPaths.filter((dmg) => dmg.endsWith('.dmg')).map((dmg) => dmg); // Removed unnecessary quotes for consistency
26+
const newDmgs = artifactPaths.filter((dmg) => dmg.endsWith('.dmg')).map((dmg) => dmg);
1527

1628
let existingDmgs = [];
1729
try {
18-
// Attempt to read the existing dmgs.json file
1930
const data = fs.readFileSync('dmgs.json', 'utf8');
2031
const parsedData = JSON.parse(data);
21-
existingDmgs = parsedData.dmgs || []; // Ensure existingDmgs is an array
32+
existingDmgs = parsedData.dmgs || [];
2233
} catch (error) {
23-
// If there's an error reading the file (e.g., file does not exist), proceed with an empty array
2434
console.log('No existing dmgs.json or error reading file, creating new one.');
2535
}
2636

27-
// Combine existing and new dmgs, avoiding duplicates
2837
const combinedDmgs = [...new Set([...existingDmgs, ...newDmgs])];
29-
30-
// Write/overwrite the dmgs.json with the combined list of dmgs
3138
fs.writeFileSync('dmgs.json', JSON.stringify({ dmgs: combinedDmgs }, null, 2));
32-
};
39+
}
40+
41+
async function handleWindowsSigning(context) {
42+
try {
43+
// Get version from package.json
44+
const packageJsonPath = path.join(__dirname, 'package.json');
45+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
46+
const version = packageJson.version;
47+
48+
// Construct the installer path
49+
const installerPath = path.join(__dirname, 'release', `Remix-Desktop-Setup-${version}.exe`);
50+
51+
if (!fs.existsSync(installerPath)) {
52+
console.log(`Windows installer not found at ${installerPath}, skipping signing`);
53+
return;
54+
}
55+
56+
console.log(`Signing Windows installer: ${installerPath}`);
57+
58+
// Check if we have the required environment variables for signing
59+
const requiredEnvVars = ['SM_API_KEY', 'SM_CLIENT_CERT_FILE_B64', 'SM_CODE_SIGNING_CERT_SHA1_HASH'];
60+
const missingEnvVars = requiredEnvVars.filter(envVar => !process.env[envVar]);
61+
62+
if (missingEnvVars.length > 0) {
63+
console.log(`Missing required environment variables for signing: ${missingEnvVars.join(', ')}`);
64+
console.log('Skipping Windows installer signing');
65+
return;
66+
}
67+
68+
// Use the existing sign-windows.sh script
69+
await signWithScript(installerPath);
70+
71+
console.log(`Successfully signed Windows installer: ${installerPath}`);
72+
73+
} catch (error) {
74+
console.error('Error signing Windows installer:', error);
75+
// Don't fail the build, just log the error
76+
}
77+
}
78+
79+
function signWithScript(filePath) {
80+
return new Promise((resolve, reject) => {
81+
const child = spawn(
82+
'bash',
83+
[
84+
path.resolve(__dirname, 'sign-windows.sh'),
85+
filePath
86+
],
87+
{ stdio: 'inherit' }
88+
);
89+
90+
child.on('exit', (code) => {
91+
if (code === 0) {
92+
console.log('Windows installer signing completed successfully.');
93+
resolve();
94+
} else {
95+
reject(new Error(`Signing script exited with code ${code}`));
96+
}
97+
});
98+
});
99+
}

0 commit comments

Comments
 (0)