cssun25
cssun25

Reputation: 381

Is there a way to set up electron-builder auto-updater to check for updates from Google Cloud Storage?

I would like to use the autoUpdater from electron-builder to update my apps. I'm not using Github Releases because I have a private repo and don't want to include the GH_TOKEN for security purposes. Instead I want to put the binaries and the latest.yml/latest-mac.yml files into a Google Storage Bucket.

I know that it is possible to use a generic provider to check for updates. But currently, I can't get electron-builder to even read the latest.yml. I've poured over the documentation and other github/stack overflow issues for hours and hours and haven't found anything to resolve this.

Here's the code I have in my main.js for electron/auto updater to set a new feed URL -

const data = {
  provider: 'generic',
  url: 'https://storage.cloud.google.com/my-project', //'my-project' is the name of the bucket
  channel: 'latest',
};
autoUpdater.setFeedURL(data);
autoUpdater.autoDownload = false;
autoUpdater.checkForUpdates();

The built app plus the yml files are in that bucket. When I try to run my app, I get a huge error that basically just copies over the Google Cloud Storage HTML/CSS instead of reading and processing the latest.yml file...

Error: Error: Cannot parse update info from latest-mac.yml in the latest release artifacts (https://storage.cloud.google.com/my-project/latest-mac.yml?noCache=1dh4pdr5e): YAMLException: end of the stream or a document separator is expected at line 11, column 14:
       font-family: 'Open Sans';
                  ^
     at generateError (/Users/somelocation/documents/some-project/node_modules/js-yaml/lib/js-yaml/loader.js:167:10)
     at throwError (/Users/somelocation/documents/some-project/node_modules/js-yaml/lib/js-yaml/loader.js:173:9)
     at readDocument (/Users/somelocation/documents/some-project/node_modules/js-yaml/lib/js-yaml/loader.js:1539:5)
     at loadDocuments (/Users/somelocation/documents/some-project/node_modules/js-yaml/lib/js-yaml/loader.js:1575:5)
     at load (/Users/somelocation/documents/some-project/node_modules/js-yaml/lib/js-yaml/loader.js:1596:19)
     at safeLoad (/Users/somelocation/documents/some-project/node_modules/js-yaml/lib/js-yaml/loader.js:1618:10)
     at parseUpdateInfo (/Users/somelocation/documents/some-project/node_modules/electron-updater/out/providers/Provider.js:131:37)
     at GenericProvider.getLatestVersion (/Users/somelocation/documents/some-project/node_modules/electron-updater/out/providers/GenericProvider.js:57:48)
     at processTicksAndRejections (internal/process/task_queues.js:86:5)
     at async MacUpdater.getUpdateInfoAndProvider (/Users/somelocation/documents/some-project/node_modules/electron-updater/out/AppUpdater.js:488:13), rawData:
 <!DOCTYPE html>
 <html lang="en">
   <head>
   <meta charset="utf-8">
   <meta content="width=300, initial-scale=1" name="viewport">
   <meta name="google-site-verification" content="LrdTUW9psUAMbh4Ia074-BPEVmcpBxF6Gwf0MSgQXZs">
   <title>Sign in - Google Accounts</title>

Is it possible at all to read the files from a Google Cloud Storage bucket rather than S3 or Github? Also, I've already tried eliminating an extra lines or tabs from the yml file.

Upvotes: 2

Views: 4184

Answers (2)

Ilya
Ilya

Reputation: 11

You should use GCP API instead of a browser URL.

This code worked for me:

"publish": {
   "provider": "generic",
   "url": "https://storage.googleapis.com/YOUR_BUCKET/"
}

https://cloud.google.com/storage/docs/json_api/v1 also can be used, but it requires OAuth

Upvotes: 1

Sajjad Al-khafaji
Sajjad Al-khafaji

Reputation: 16

try to execute this code after the app 'ready' event.

app.on('ready', () => {
    const feedURL = 'https://storage.cloud.google.com/my-project';
    autoUpdater.setFeedURL(feedURL); 
    autoUpdater.checkForUpdates(); 
});

Upvotes: 0

Related Questions