-
-
Notifications
You must be signed in to change notification settings - Fork 20
/
index.js
103 lines (81 loc) · 2.75 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
'use strict';
require('dotenv').config();
const path = require('path');
const fs = require('fs');
const readPkgUp = require('read-pkg-up');
const {notarize} = require('electron-notarize');
const yaml = require('js-yaml');
// eslint-disable-next-line import/no-unresolved
const util = require('builder-util');
const getAuthCreds = require('./validate');
const isEnvTrue = value => {
// eslint-disable-next-line no-eq-null, eqeqeq
if (value != null) {
value = value.trim();
}
return value === 'true' || value === '' || value === '1';
};
const getAppId = params => {
const {packager, outDir} = params;
// Try getting appId from the packager object
const config = packager.info._configuration;
const appId = config && config.appId;
if (appId) {
return appId;
}
// Try getting appId from the `builder-effective-config.yml`
const effectiveConfigPath = path.join(outDir, 'builder-effective-config.yaml');
// This doesn't exist in CI
if (fs.existsSync(effectiveConfigPath)) {
const buildConfig = fs.readFileSync(effectiveConfigPath);
const {appId} = yaml.safeLoad(buildConfig);
return appId;
}
// Try getting appId from `package.json` or from an env var
const {packageJson} = readPkgUp.sync();
return (packageJson.build && packageJson.build.appId) || process.env.APP_ID;
};
module.exports = async params => {
if (params.electronPlatformName !== 'darwin') {
return;
}
// https://github.com/electron-userland/electron-builder/blob/c11fa1f1033aeb7c378856d7db93369282d363f5/packages/app-builder-lib/src/codeSign/macCodeSign.ts#L22-L49
if (util.isPullRequest()) {
if (!isEnvTrue(process.env.CSC_FOR_PULL_REQUEST)) {
console.log('Skipping notarizing, since app was not signed.');
return;
}
}
// Read and validate auth information from environment variables
let authInfo;
try {
authInfo = await getAuthCreds();
} catch (error) {
console.log(`Skipping notarization: ${error.message}`);
return;
}
const appId = getAppId(params);
if (!appId) {
throw new Error('`appId` was not found');
}
const appPath = path.join(params.appOutDir, `${params.packager.appInfo.productFilename}.app`);
const notarizeOptions = {
...authInfo,
appPath,
appBundleId: appId
};
console.log(`📦 Start notarizing ${appId} found at ${appPath}`);
try {
const res = await notarize(notarizeOptions);
if (!res) {
console.log(`🌟 Notarizing ${appId} successfully !`);
}
} catch (error) {
const error1048Str = 'You must first sign the relevant contracts online. (1048)';
if (String(error).includes(error1048Str)) {
throw new Error('📃 Error(1048): You must first sign the relevant contracts online');
}
fs.writeFileSync('notarization-error.log', error.message);
throw new Error('❌ Notarization Error,please check notarization-error.log');
}
};