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

afterAllArtifactBuild Hook runs after file uploads / prevents them? #7145

Closed
hrueger opened this issue Sep 19, 2022 · 9 comments
Closed

afterAllArtifactBuild Hook runs after file uploads / prevents them? #7145

hrueger opened this issue Sep 19, 2022 · 9 comments
Labels

Comments

@hrueger
Copy link
Contributor

hrueger commented Sep 19, 2022

  • Electron-Builder Version: 23.3.3
  • Node Version: 16.13.0
  • Electron Version: 17.1.2
  • Electron Type (current, beta, nightly): current
  • Target: mac universal

I'm building a MacOS Universal app for the pkg target. As electron-notarize can not currently notarize .pkg files, I'm doing that myself in the afterAllArtifactBuild hook.

The notarization itself is working fine, however, the upload process starts before my script even runs. As the notarization script staples a ticket to the .pkg file, I want to upload the modified file.

The second problem is, that it just does not upload the latest-mac.yml, beta-mac.yml and alpha-mac.yml files at all.

Any idea?

@hrueger
Copy link
Contributor Author

hrueger commented Sep 19, 2022

probably linked to #4446, however, as I'm not using the .yml files in my script, this should not result in them not being uploaded.

@hrueger
Copy link
Contributor Author

hrueger commented Sep 20, 2022

I digged a little bit into the code and it seems like the uploading is done automatically here

packager.artifactCreated(event => {
const publishConfiguration = event.publishConfig
if (publishConfiguration == null) {
this.taskManager.addTask(this.artifactCreatedWithoutExplicitPublishConfig(event))
} else if (this.isPublish) {
if (debug.enabled) {
debug(`artifactCreated (isPublish: ${this.isPublish}): ${safeStringifyJson(event, new Set(["packager"]))},\n publishConfig: ${safeStringifyJson(publishConfiguration)}`)
}
this.scheduleUpload(publishConfiguration, event, this.getAppInfo(event.packager))
}
})
}
whenever an artifact is created.

However, that does not explain why the .yml files are not being uploaded at all.

I think the best idea would be to add another hook like in #6766 (maybe called beforePublish) which runs after all artifacts have been packaged but blocks all uploads.

Edit: I'm happy to create a PR if someone points me in the right direction where that hook would have to go.

@hrueger
Copy link
Contributor Author

hrueger commented Sep 22, 2022

After some more debugging, I found why the .yml files are not being uploaded: They are not even generated!

Because of the problems described above, I (hopefully temporarily) switched to a manual S3 notarization and upload script. That means I got rid of the afterAllArtifactBuild hook. If I build on MacOS for the universal arch and the pkg target, no .yml files are generated...

@mmaietta
Copy link
Collaborator

mmaietta commented Oct 7, 2022

latest.yml files are only created when there's a publish setting and under a few circumstances, such as --publish always being passed via command line. There should also be a setting within the config for this as well.

@hrueger
Copy link
Contributor Author

hrueger commented Oct 7, 2022

It's strange, though, because on Windows and Linux (using matrix builds in GitHub Actions) everything worked fine.
Just the hook causes problems...

@github-actions
Copy link
Contributor

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 30 days.

@github-actions github-actions bot added the Stale label Jun 19, 2023
@le4onardo
Copy link

Hi! I think I found a work around, so posting here for posterity 😄
Seems using artifactBuildCompleted event instead of afterAllArtifactBuild does wait the notarization before publishing!

require("dotenv").config();
const { spawn } = require("node:child_process");
const os = require("os");

exports.default = async function notarizing(context) {
  if (os.platform() !== "darwin") {
    console.log("Not notarizing app because not running on MacOS.");
    return;
  }

  const filename = context.file.endsWith(".dmg") ? context.file : false;
  if (!filename) {
    console.log(`Skipping ${context.file}`);
    return;
  }
  console.log("Notarizing app...");
  console.log(`Found artifact: ${filename}`);
  let auth = '--keychain-profile "AC_PASSWORD"';
  if (process.env.APPLE_ID && process.env.APPLE_ID_PASS && process.env.TEAM_ID) {
    auth = `--apple-id ${process.env.APPLE_ID} --password "${process.env.APPLE_ID_PASS}" --team-id ${process.env.TEAM_ID}`;
  }
  const content = await exec(`xcrun notarytool submit ${filename} ${auth} --wait`);
  const uuid = content.match(/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/g)[0];
  await exec(`xcrun notarytool log ${uuid} ${auth}`);
  await exec(`xcrun stapler staple ${filename}`);

  console.log("App notarized successfully.");
};

function exec(cmd) {
  return new Promise((resolve, reject) => {
    console.log(cmd);
    const proc = spawn(cmd, [], { shell: true });

    const chunks = [];
    proc.stdout.on("data", (data) => {
      console.log(data.toString());
      chunks.push(data);
    });
    proc.stderr.on("data", (data) => {
      console.error(data.toString());
      chunks.push(data);
    });
    proc.on("close", (code) => {
      console.log(`Process exited with code ${code}.`);
      resolve(Buffer.concat(chunks).toString("utf8"));
    });
  });
}

Its the same script @hrueger posted here but it skips all files that are not the required for notarization.
I didn't test it with a .pkg, but I guess its worth trying 🤔

@github-actions github-actions bot removed the Stale label Jun 23, 2023
@github-actions
Copy link
Contributor

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 30 days.

@github-actions github-actions bot added the Stale label Aug 24, 2023
Copy link
Contributor

This issue was closed because it has been stalled for 30 days with no activity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants