electron-userland / electron-builder

A complete solution to package and build a ready for distribution Electron app with “auto update” support out of the box
https://www.electron.build
MIT License
13.69k stars 1.74k forks source link

afterAllArtifactBuild script fires before latest.yml is created #4446

Open cameronsutter opened 4 years ago

cameronsutter commented 4 years ago

In the afterAllArtifactBuild script, latest.yml (and latest-mac.yml) are not created yet or are not saved to the output directory yet.

mac CI logs output from afterAllArtifactBuild:

mac_output

windows CI logs output from afterAllArtifactBuild:

windows_output

The arrays starting on line 167 and 92 respectfully are all the files in the outDir folder.

Note: BUILD TYPE trial is something specific to my app

kzimny commented 4 years ago

Similar issue? #4435

BellezaEmporium commented 4 years ago

Maybe try to look at your folder when it's being built (try in your own PC, and then on CIs if it does change), or maybe it is already named like this.

(on mac, maybe try to chmod 777 the whole folder before renaming, idk)

cameronsutter commented 4 years ago

@kzimny it's not quite similar because that one deals with when the app is trying to update. My issue is during build.

@ShadixAced that's a good idea. I'll give that a try and see what's happening on my local computer

oltreseba commented 4 years ago

I'm having the same issue here. It really looks like afterAllArtifactBuild is called before latest-mac.yml is created. Therefore is quite a pain to setup a deploy system in the afterAllArtifactBuild.

I'm using version 22.2.0

stale[bot] commented 4 years ago

Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

oltreseba commented 4 years ago

Yes it is still relevant. latest-mac.yml (and alpha-mac.yml and beta-mac.yml if generateUpdatesFilesForAllChannels is set to true) is created after the event afterAllArtifactBuild is fired. It would make sense to fire the afterAllArtifactBuild event after all the files have been created.

kroko commented 3 years ago

Still relevant, because latest-mac.yml is actually not generated when version is valid semver alpha and generateUpdatesFilesForAllChannels: true.
If afterAllArtifactBuild was predictable a hook could be used, that would check if latest-mac.yml is generated, if not then create it by looking if there is beta-mac.yml or alpha-mac.yml and copy that as latest-mac.yml.

asd281533890 commented 3 years ago

I solved this problem by using chokidar

// afterAllArtifactBuild.js
const chokidar = require('chokidar')
const fs = require('fs')
const path = require('path')
exports.default = async buildResult => {
  const filePath = path.join(buildResult.outDir, 'latest.yml')
  fs.access(filePath, fs.contants.R_OK, err => {
    const watcher = chokidar.watch(filePath)
    watcher.on(err ? 'add' : 'change', (event, path) => {
        // await do something
        watcher.unwatch(filePath)
        process.exit(0)
      })
  })
}
panther7 commented 2 years ago

Still relevant in 23.0.0-alpha.3

ArmelChesnais commented 2 years ago

Still relevant in 23.0.2. I'm trying to automate a modification to the yml file before it gets uploaded, and this is impossible directly with afterAllArtifactBuild, as the yml file doesn't exist when afterAllArtifactBuild is called. The above solution by asd seems like a possible hack/workaround, but doesn't seem like it should be the expected approach.

If afterAllArtifactBuild is meant to be used solely for the application artifacts and not the yml file, then a new hook along the lines of "beforeUpload" should be available.

promotion-xu commented 2 years ago

I solved this problem by using chokidar

// afterAllArtifactBuild.js
const chokidar = require('chokidar')
const fs = require('fs')
const path = require('path')
exports.default = async buildResult => {
  const filePath = path.join(buildResult.outDir, 'latest.yml')
  fs.access(filePath, fs.contants.R_OK, err => {
    const watcher = chokidar.watch(filePath)
    watcher.on(err ? 'add' : 'change', (event, path) => {
        // await do something
        watcher.unwatch(filePath)
        process.exit(0)
      })
  })
}

fs.constants.R_OK is right

MiguelSOliveira commented 2 years ago

any news on this? can't seem to make it work with chokidar.

I want to wait until latest.yml is created so I can return more items in the array for this afterAllArtifactBuild method