Files
cypress/scripts/after-sign-hook.js
T
Bill Glesias 3caabd3a0f chore: update electron notary tool to v2 (#27380)
* chore: update electron-notarize to @electron/notarize v2. legacy tooling will stop working November 23 and this allows us to get ahead of the curve. see https://github.com/electron/notarize/commit/bf23272fa2a98b293ff74c29d2ceff549ac357bb. Also inquirer types were having issues in build which updated from v7 to v8. Nothing major changed there except dropping node 10 support

chore: add Team ID to mac os code sign as it is now needed by the new signing tool. see https://github.com/electron/notarize#notes-on-your-teamid. [run ci]

* chore: debug notary [run ci]
2023-07-25 09:51:02 -04:00

63 lines
1.8 KiB
JavaScript

// from https://medium.com/@TwitterArchiveEraser/notarize-electron-apps-7a5f988406db
// to enable running this hook, set in "electron-builder.json" the option
// "afterSign": "./scripts/after-sign-hook.js"
const fs = require('fs')
const path = require('path')
let electron_notarize = require('@electron/notarize')
module.exports = async function (params) {
// Only notarize the app on Mac OS.
if (process.platform !== 'darwin') {
console.log('not Mac, skipping after sign hook')
return
}
if (process.env.SKIP_NOTARIZATION) {
console.log('SKIP_NOTARIZATION set, skipping after sign hook')
return
}
console.log('afterSign hook triggered in', params.appOutDir)
// Same appId in electron-builder.
let appId = 'com.electron.cypress'
let appPath = path.join(params.appOutDir, `${params.packager.appInfo.productFilename}.app`)
if (!fs.existsSync(appPath)) {
throw new Error(`Cannot find application at: ${appPath}`)
}
console.log(`Notarizing ${appId} found at ${appPath}`)
if (!process.env.NOTARIZE_APP_APPLE_ID) {
throw new Error('Missing Apple id for notarization: NOTARIZE_APP_APPLE_ID')
}
if (!process.env.NOTARIZE_APP_PASSWORD) {
throw new Error('Missing Apple password for notarization: NOTARIZE_APP_PASSWORD')
}
if (!process.env.NOTARIZE_APP_TEAM_ID) {
throw new Error('Missing Apple team id for notarization: NOTARIZE_APP_TEAM_ID')
}
try {
await electron_notarize.notarize({
appBundleId: appId,
appPath,
appleId: process.env.NOTARIZE_APP_APPLE_ID,
appleIdPassword: process.env.NOTARIZE_APP_PASSWORD,
teamId: process.env.NOTARIZE_APP_TEAM_ID,
})
} catch (error) {
console.error('could not notarize application')
console.error(error)
throw error
}
console.log(`Done notarizing ${appId}`)
}