1
- const { notarize } = require ( '@electron/notarize' )
2
- const fs = require ( 'fs' )
3
- const { exec } = require ( 'child_process' ) // Import the exec function
4
-
5
- // read the environment variables from process
1
+ const { notarize } = require ( '@electron/notarize' ) ;
2
+ const { spawn, exec } = require ( 'child_process' ) ;
3
+ const path = require ( 'path' ) ;
4
+
5
+ // Windows signing function
6
+ function signWindowsBinaries ( appOutDir ) {
7
+ const filesToSign = [
8
+ path . join ( appOutDir , 'Remix-Desktop.exe' ) ,
9
+ path . join ( appOutDir , 'resources' , 'app.asar.unpacked' , 'node_modules' , 'node-pty' , 'build' , 'Release' , 'winpty-agent.exe' ) ,
10
+ path . join ( appOutDir , 'resources' , 'app.asar.unpacked' , 'node_modules' , '@vscode' , 'ripgrep' , 'bin' , 'rg.exe' ) ,
11
+ ] ;
12
+
13
+ console . log ( 'Signing the following Windows files:' , filesToSign ) ;
14
+
15
+ return new Promise ( ( resolve , reject ) => {
16
+ const child = spawn (
17
+ 'bash' ,
18
+ [
19
+ path . resolve ( __dirname , 'sign-windows.sh' ) ,
20
+ filesToSign . join ( ';' )
21
+ ] ,
22
+ { stdio : 'inherit' }
23
+ ) ;
24
+
25
+ child . on ( 'exit' , ( code ) => {
26
+ if ( code === 0 ) {
27
+ console . log ( 'Windows signing completed successfully.' ) ;
28
+ resolve ( ) ;
29
+ } else {
30
+ reject ( new Error ( `Signing script exited with code ${ code } ` ) ) ;
31
+ }
32
+ } ) ;
33
+ } ) ;
34
+ }
6
35
7
- console . log ( process . env . DO_NOT_NOTARIZE )
36
+ // macOS notarization function
37
+ async function notarizeMac ( context ) {
38
+ const { electronPlatformName, appOutDir } = context ;
8
39
9
- if ( process . env . DO_NOT_NOTARIZE ) {
10
- console . log ( 'NOTARIZING DISABLED' )
11
- exports . default = async function notarizing ( context ) {
12
- return [ ]
40
+ if ( electronPlatformName !== 'darwin' ) {
41
+ console . log ( 'Skipping notarization: not darwin or CIRCLE_BRANCH not set.' ) ;
42
+ return ;
13
43
}
14
- } else {
15
-
16
- exports . default = async function notarizing ( context ) {
17
- const { electronPlatformName, appOutDir } = context // Provided by electron-builder
18
-
19
- console . log ( 'NOTARIZING' )
20
-
21
- if ( electronPlatformName !== 'darwin' || ! process . env . CIRCLE_BRANCH ) {
22
- return
23
- }
24
-
25
- const appName = context . packager . appInfo . productFilename
26
- const appPath = `${ appOutDir } /${ appName } .app`
27
44
28
- // Function to promisify the exec command
29
- function execShellCommand ( cmd ) {
30
- return new Promise ( ( resolve , reject ) => {
31
- exec ( cmd , ( error , stdout , stderr ) => {
32
- if ( error ) {
33
- reject ( new Error ( `Error: ${ error . message } ` ) ) ;
34
- return ;
35
- }
36
- if ( stderr ) {
37
- reject ( new Error ( `Stderr: ${ stderr } ` ) ) ;
38
- return ;
39
- }
40
- console . log ( `stdout: ${ stdout } ` ) ;
41
- resolve ( stdout ) ;
42
- } ) ;
45
+ const appName = context . packager . appInfo . productFilename ;
46
+ const appPath = `${ appOutDir } /${ appName } .app` ;
47
+
48
+ async function execShellCommand ( cmd ) {
49
+ return new Promise ( ( resolve , reject ) => {
50
+ exec ( cmd , ( error , stdout , stderr ) => {
51
+ if ( error ) {
52
+ reject ( new Error ( `Error: ${ error . message } ` ) ) ;
53
+ return ;
54
+ }
55
+ if ( stderr ) {
56
+ reject ( new Error ( `Stderr: ${ stderr } ` ) ) ;
57
+ return ;
58
+ }
59
+ console . log ( `stdout: ${ stdout } ` ) ;
60
+ resolve ( stdout ) ;
43
61
} ) ;
44
- }
62
+ } ) ;
63
+ }
45
64
46
- // Function to check if the app is stapled
47
- // Async function to check the stapling status
48
- async function checkStapleStatus ( ) {
49
- try {
50
- console . log ( `xcrun stapler validate "${ appPath } "` )
51
- await execShellCommand ( `xcrun stapler validate "${ appPath } "` ) ;
52
- console . log ( 'App is already stapled. No action needed.' ) ;
53
- return true
54
- } catch ( error ) {
55
- console . log ( `App is not stapled: ${ error . message } ` ) ;
56
- return false
57
- }
65
+ async function checkStapleStatus ( ) {
66
+ try {
67
+ console . log ( `xcrun stapler validate "${ appPath } "` ) ;
68
+ await execShellCommand ( `xcrun stapler validate "${ appPath } "` ) ;
69
+ console . log ( 'App is already stapled.' ) ;
70
+ return true ;
71
+ } catch ( error ) {
72
+ console . log ( `App is not stapled: ${ error . message } ` ) ;
73
+ return false ;
58
74
}
75
+ }
59
76
77
+ async function runNotarize ( ) {
78
+ console . log ( 'Notarizing app...' ) ;
79
+ await notarize ( {
80
+ appBundleId : 'org.ethereum.remix-ide' ,
81
+ appPath,
82
+ appleId : process . env . APPLE_ID ,
83
+ appleIdPassword : process . env . APPLE_ID_PASSWORD ,
84
+ teamId : process . env . APPLE_TEAM_ID ,
85
+ } ) ;
86
+
87
+ console . log ( 'Stapling...' ) ;
88
+ await execShellCommand ( `xcrun stapler staple "${ appPath } "` ) ;
89
+ }
60
90
91
+ if ( ! ( await checkStapleStatus ( ) ) ) {
92
+ await runNotarize ( ) ;
93
+ await checkStapleStatus ( ) ;
94
+ }
95
+ }
96
+
97
+ // Main export
98
+ exports . default = async function afterSign ( context ) {
99
+ const { appOutDir } = context ;
100
+
101
+ // Skip signing for local builds
102
+ const isCI = process . env . CI ||
103
+ process . env . GITHUB_ACTIONS ||
104
+ process . env . CIRCLECI ||
105
+ process . env . APPVEYOR ||
106
+ process . env . TRAVIS ;
107
+
108
+ if ( ! isCI || process . env . DO_NOT_NOTARIZE == 'true' || process . env . DO_NOT_SIGN == 'true' ) {
109
+ console . log ( 'Skipping signing: local build detected (no CI environment).' ) ;
110
+ return ;
111
+ }
61
112
62
-
63
- async function runNotarize ( ) {
64
-
65
- console . log ( 'NOTARIZING + ' , `xcrun stapler staple "${ appPath } "` )
66
- console . log ( {
67
- appBundleId : 'org.ethereum.remix-ide' , // Your app's bundle ID
68
- appPath : `${ appOutDir } /${ appName } .app` , // Path to your .app
69
- appleId : process . env . APPLE_ID , // Your Apple ID
70
- appleIdPassword : process . env . APPLE_ID_PASSWORD , // App-specific password
71
- teamId : process . env . APPLE_TEAM_ID , // Your Apple Developer team ID (optional)
72
- } )
73
-
74
- try {
75
- const r = await notarize ( {
76
- appBundleId : 'org.ethereum.remix-ide' , // Your app's bundle ID
77
- appPath : `${ appOutDir } /${ appName } .app` , // Path to your .app
78
- appleId : process . env . APPLE_ID , // Your Apple ID
79
- appleIdPassword : process . env . APPLE_ID_PASSWORD , // App-specific password
80
- teamId : process . env . APPLE_TEAM_ID , // Your Apple Developer team ID (optional)
81
- } )
82
-
83
- console . log ( r )
84
-
85
- // Stapling the app
86
- console . log ( 'STAPLING' , `xcrun stapler staple "${ appPath } "` )
87
-
88
- await execShellCommand ( `xcrun stapler staple "${ appPath } "` )
89
-
90
- } catch ( error ) {
91
- console . error ( 'Error during notarization:' , error )
92
- throw new Error ( 'Error during notarization' , error )
93
- }
94
-
95
- }
96
-
97
- if ( ! await checkStapleStatus ( ) ) {
98
- await runNotarize ( )
99
- await checkStapleStatus ( )
100
- } else {
101
- return [ ]
102
- }
113
+ if ( process . platform === 'darwin' ) {
114
+ await notarizeMac ( context ) ;
115
+ } else if ( process . platform === 'win32' ) {
116
+ await signWindowsBinaries ( appOutDir ) ;
117
+ } else {
118
+ console . log ( 'No signing needed for this platform.' ) ;
103
119
}
104
- }
120
+ } ;
0 commit comments