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

fix(packager): return success status from doSign function calls #7431

Merged

Conversation

nsrCodes
Copy link
Contributor

Recent changes (#7311) in platform packager afterSign hook show that the correct success status was not being returned after signing the app on macOS

This results in the app being signed but the terminal has the following message

skipping "afterSign" hook as no signing occurred, perhaps you intended "afterPack"?

found this on electron-builder v24.0.0-alpha.12

Couldn't get a local development environment properly setup, so hoping someone could help test if these help solve the issue

@changeset-bot
Copy link

changeset-bot bot commented Feb 20, 2023

🦋 Changeset detected

Latest commit: 02f1e04

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 8 packages
Name Type
app-builder-lib Patch
dmg-builder Patch
electron-builder-squirrel-windows Patch
electron-builder Patch
electron-forge-maker-appimage Patch
electron-forge-maker-nsis-web Patch
electron-forge-maker-nsis Patch
electron-forge-maker-snap Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@netlify
Copy link

netlify bot commented Feb 20, 2023

Deploy Preview for car-park-attendant-cleat-11576 ready!

Name Link
🔨 Latest commit 02f1e04
🔍 Latest deploy log https://app.netlify.com/sites/car-park-attendant-cleat-11576/deploys/6403a1048ef7800008b6ba78
😎 Deploy Preview https://deploy-preview-7431--car-park-attendant-cleat-11576.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@nsrCodes nsrCodes changed the title fix packager: return success status from dosign fix packager: return success status from doSign function calls Feb 20, 2023
Copy link
Collaborator

@mmaietta mmaietta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you so much for calling out this issue!

I found that the BluebirdPromise.map doesn't require return as this.sign throws an error if it fails. We can just return true after signing completes.

I'm going to pick up this work and file a new PR. I'll take a larger stab at refactoring this code (and investigate some other Promise<any> that ended up letting this issue sneak by intellisense.

@@ -269,6 +271,7 @@ export class WinPackager extends PlatformPackager<WindowsConfiguration> {
throw e
}
}
return didSign
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This didSign flag logic needs to be flipped in order to handle the continue within the catch

let didSign = false
for (let i = 0; i < 3; i++) {
  try {
    await sign(options, this)
    didSign = true
    break
  } catch (e: any) {
    // https://github.com/electron-userland/electron-builder/issues/1414
    const message = e.message
    if (message != null && message.includes("Couldn't resolve host name")) {
      log.warn({ error: message, attempt: i + 1 }, `cannot sign`)
      continue
    }
    throw e
  }
}
return didSign

@@ -366,7 +369,9 @@ export class WinPackager extends PlatformPackager<WindowsConfiguration> {
if (this.shouldSignFile(file)) {
const parentDir = path.dirname(file)
if (parentDir !== packContext.appOutDir) {
return new CopyFileTransformer(file => this.sign(file))
return new CopyFileTransformer(async file => {
await this.sign(file)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this change intentional?
file => this.sign(file) returns Promise<boolean>
async file => { await this.sign(file) } returns Promise<void> due to the brackets

Copy link
Contributor Author

@nsrCodes nsrCodes Feb 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was getting linting issues that this callback expected a return type of Promise<void>, which is why I made the change, but this seems like a linting issue which you fixed in the accompanying PR.
Removing these changes from here now

@@ -450,7 +450,7 @@ export default class MacPackager extends PlatformPackager<MacConfiguration> {
await BluebirdPromise.map(readdir(packContext.appOutDir), async (file: string): Promise<any> => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you change the return of this larger function to Promise<boolean>, intellisense will still flag that this function isn't returning the correct values. I'll take a look on refactoring this function entirely

Recent changes in platform packager afterSign hook show that the correct
success status was not being returned after signing the app on windows
and macOs
@nsrCodes nsrCodes force-pushed the fix-packager-sign-status branch from af9d68b to db2db2c Compare February 21, 2023 04:15
@nsrCodes nsrCodes force-pushed the fix-packager-sign-status branch from db2db2c to b403b5e Compare February 21, 2023 04:24
@nsrCodes
Copy link
Contributor Author

@mmaietta I have rebased this with master which contains your larger rewrite. Doing this just for completeness, and a few small improvements I thought were relevant.
In case this PR is now just redundant please close it.
If not, probably a better idea to squash and merge because the commit history isn't great 😓

Thanks for quickly releasing the fix!

@mmaietta mmaietta changed the title fix packager: return success status from doSign function calls fix(packager): return success status from doSign function calls Mar 4, 2023
@mmaietta mmaietta merged commit eb842f7 into electron-userland:master Mar 4, 2023
@github-actions github-actions bot mentioned this pull request Mar 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants