Skip to content

Commit

Permalink
feat: Add osxSign.continueOnError option (#1579)
Browse files Browse the repository at this point in the history
* Add `osxSign.continueOnError` option

* Update osxSign options tests

* Update NEWS.md
  • Loading branch information
futpib authored Oct 26, 2023
1 parent 1e4bf45 commit 4543f8a
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 7 deletions.
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

0 comments on commit 4543f8a

Please sign in to comment.