Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add osxSign.continueOnError option #1579

Merged
merged 3 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

[Unreleased]: https://github.com/electron/electron-packager/compare/v17.1.2...main

### Changed

* Added `osxSign.continueOnError` option. Setting it to `false` will fail the build if there was an error signing the app instead of the default behavior of printing a warning. (#1579)

## [17.1.2] - 2023-08-18

[17.1.2]: https://github.com/electron/electron-packager/compare/v17.1.1...v17.1.2
Expand Down
11 changes: 10 additions & 1 deletion src/mac.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,11 @@ class MacApp extends App {
await signApp(signOpts)
} catch (err) {
// Although not signed successfully, the application is packed.
common.warning(`Code sign failed; please retry manually. ${err}`, this.opts.quiet)
if (signOpts.continueOnError) {
common.warning(`Code sign failed; please retry manually. ${err}`, this.opts.quiet)
} else {
throw err
}
}
}
}
Expand Down Expand Up @@ -418,6 +422,11 @@ function createSignOpts (properties, platform, app, version, quiet) {
signOpts.identity = null
}

// Default to `continueOnError: true` since this was the default behavior before this option was added
if (signOpts.continueOnError !== false) {
signOpts.continueOnError = true
}

return signOpts
}

Expand Down
31 changes: 25 additions & 6 deletions test/darwin.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,38 +319,44 @@ if (!(process.env.CI && process.platform === 'win32')) {
test('osxSign: default args', t => {
const args = true
const signOpts = mac.createSignOpts(args, 'darwin', 'out', 'version')
t.deepEqual(signOpts, { identity: null, app: 'out', platform: 'darwin', version: 'version' })
t.deepEqual(signOpts, { identity: null, app: 'out', platform: 'darwin', version: 'version', continueOnError: true })
})

test('osxSign: identity=true sets autodiscovery mode', t => {
const args = { identity: true }
const signOpts = mac.createSignOpts(args, 'darwin', 'out', 'version')
t.deepEqual(signOpts, { identity: null, app: 'out', platform: 'darwin', version: 'version' })
t.deepEqual(signOpts, { identity: null, app: 'out', platform: 'darwin', version: 'version', continueOnError: true })
})

test('osxSign: optionsForFile passed to @electron/osx-sign', t => {
const optionsForFile = () => ({ entitlements: 'path-to-entitlements' })
const args = { optionsForFile }
const signOpts = mac.createSignOpts(args, 'darwin', 'out', 'version')
t.deepEqual(signOpts, { app: 'out', platform: 'darwin', version: 'version', optionsForFile })
t.deepEqual(signOpts, { app: 'out', platform: 'darwin', version: 'version', optionsForFile, continueOnError: true })
})

test('osxSign: app not overwritten', t => {
const args = { app: 'some-other-path' }
const signOpts = mac.createSignOpts(args, 'darwin', 'out', 'version')
t.deepEqual(signOpts, { app: 'out', platform: 'darwin', version: 'version' })
t.deepEqual(signOpts, { app: 'out', platform: 'darwin', version: 'version', continueOnError: true })
})

test('osxSign: platform not overwritten', t => {
const args = { platform: 'mas' }
const signOpts = mac.createSignOpts(args, 'darwin', 'out', 'version')
t.deepEqual(signOpts, { app: 'out', platform: 'darwin', version: 'version' })
t.deepEqual(signOpts, { app: 'out', platform: 'darwin', version: 'version', continueOnError: true })
})

test('osxSign: binaries not set', t => {
const args = { binaries: ['binary1', 'binary2'] }
const signOpts = mac.createSignOpts(args, 'darwin', 'out', 'version')
t.deepEqual(signOpts, { app: 'out', platform: 'darwin', version: 'version' })
t.deepEqual(signOpts, { app: 'out', platform: 'darwin', version: 'version', continueOnError: true })
})

test('osxSign: continueOnError=false', t => {
const args = { continueOnError: false }
const signOpts = mac.createSignOpts(args, 'darwin', 'out', 'version')
t.deepEqual(signOpts, { app: 'out', platform: 'darwin', version: 'version', continueOnError: false })
})

if (process.platform === 'darwin') {
Expand All @@ -363,6 +369,19 @@ if (!(process.env.CI && process.platform === 'win32')) {
await exec(`codesign --verify --verbose ${appPath}`)
t.pass('codesign should verify successfully')
}))

test.serial('end-to-end failed codesign throws an error with osxOpts.continueOnError=false', darwinTest(async (t, opts) => {
opts.osxSign = { identity: 'something else', continueOnError: false }

await t.throwsAsync(() => packager(opts))
}))

test.serial('end-to-end failed codesign does not throw an error with osxOpts.continueOnError=true', darwinTest(async (t, opts) => {
opts.osxSign = { identity: 'something else' }

await packager(opts)
t.pass('codesign should fail but continue due to continueOnError=true')
}))
}

test.serial('macOS: binary naming', darwinTest(binaryNameTest))
Expand Down