vite-electron-builder icon indicating copy to clipboard operation
vite-electron-builder copied to clipboard

Auto-updater does not find new releases from the same day.

Open ryanbarr opened this issue 2 years ago • 3 comments

Describe the bug The auto-updater does not find new releases if they are released in the same day as the most recent release.

To Reproduce

  1. Create a new release draft.
  2. Publish the release.
  3. Repeat steps 1 and 2 in the same day.
  4. Attempt to have auto-update work.

Expected behavior If the latest.yml in /<repo>/releases/latest has a different version than the current, it should be considered the latest.

Screenshots N/A

Additional context This seems to stem from the fact that in semantic versioning, v1.2.3-456, the 456 would be considered a pre-release. It might be best to identify a way to utilize package.json and npm version to use proper semantic versioning for releases to avoid this problem.

ryanbarr avatar Jun 26 '22 08:06 ryanbarr

It may be upstream issue. Previously autoUodater correctly recognised 22.1.1-123 as newest than 22.1.1-100.

cawa-93 avatar Jun 26 '22 10:06 cawa-93

Could this be because of this commit : https://github.com/electron-userland/electron-builder/commit/1de0adbd615b3b3d26faeb6a449f522355b36041? With a version v1.2.3-456, wouldn't the channel be 456?

Easiest workaround I found was adding autoUpdater.allowPrerelease = false; but I think the whole versioning should be changed.

Moutard3 avatar Jul 03 '22 16:07 Moutard3

I think the best workflow would be the following: 1, You create a draft release on GitHub. Specify any version there. 2, This triggers CI. There, the application is compiled with the version specified in the release draft. 3, Binaries are then added to your draft 4, You publish a release.

However, I can't find a way to trigger an GitHub action on the release draft event 🤔

cawa-93 avatar Aug 27 '22 19:08 cawa-93

// Edit: This solution does not work properly. Here's one solution with moment.

In case anyone else stumbles across this, here's a little workaround for the automatic release process. In .electron-builder.config.js, remove one . character in the version string (the one that separates month from day) and replace the - with a .. Basically, you want to turn 22.10.15-575 into 22.1015.575.

if (process.env.VITE_APP_VERSION === undefined) {
  const now = new Date()
  process.env.VITE_APP_VERSION = `${now.getUTCFullYear() - 2000}.${
    now.getUTCMonth() + 1
  }${now.getUTCDate()}.${now.getUTCHours() * 60 + now.getUTCMinutes()}`
}

The next day, all of your old installs will probably auto update. But for new installations, this solution works immediately. Electron will auto update immediately when it detects a new version online. This is because semver now treats the new release as a new release instead of a small update.

Flixbox avatar Oct 15 '22 18:10 Flixbox

In case anyone else stumbles across this, here's a little workaround for the automatic release process. In .electron-builder.config.js, remove one . character in the version string (the one that separates month from day) and replace the - with a .. Basically, you want to turn 22.10.15-575 into 22.1015.575.

if (process.env.VITE_APP_VERSION === undefined) {
  const now = new Date()
  process.env.VITE_APP_VERSION = `${now.getUTCFullYear() - 2000}.${
    now.getUTCMonth() + 1
  }${now.getUTCDate()}.${now.getUTCHours() * 60 + now.getUTCMinutes()}`
}

The next day, all of your old installs will probably auto update. But for new installations, this solution works immediately. Electron will auto update immediately when it detects a new version online. This is because semver now treats the new release as a new release instead of a small update.

Then you will got: 22.1.31 -> 22.131 22.2.1 -> 22.21 Second is newest version but according to semver is oldest because 21 < 131.

Using day of year should solve it. I'll try to make the appropriate changes ASAP (if the fuckingRussians don't launch missiles into my city)

cawa-93 avatar Oct 15 '22 18:10 cawa-93

Correct. One option is to solve it with moment. I have no issues with adding another dependency, but for a template it might be better to find a vanillaJS solution.

This option also requires the deps to be installed in the CI before the release process is started.

const moment = require('moment')

if (process.env.VITE_APP_VERSION === undefined) {
  const now = moment.utc()
  process.env.VITE_APP_VERSION = `${now.year() - 2000}.${now.dayOfYear()}.${
    now.hours() * 60 + now.minutes()
  }`
}

Flixbox avatar Oct 15 '22 20:10 Flixbox

Now auto-generated version is: <short-year>.<day-of-year>.<minute-of-day>

cawa-93 avatar Oct 16 '22 08:10 cawa-93

Now app version just reading from root package.json. You can implement your own versioning logic in getVersion() See change note: https://github.com/cawa-93/vite-electron-builder/discussions/870

cawa-93 avatar Nov 14 '22 23:11 cawa-93