9

I have implemented Electron AutoUpdater with PRIVATE GitHub Repository as provider to publish electron application. Now, i can publish it using GitHub repository but Whenever AutoUpdater tries to download the updates from GitHub repository, Everytime it prompts with response code 404 Not found.. I have tried passing token in setFeedURL method and also set it in GH_TOKEN but seems like that does not work either.

autoUpdater.setFeedURL({ provider: 'github'
, owner: 'owner'
, repo: 'repo-name'
, token: 'token'
, private: true });

So, Is there any way to get it working with PRIVATE GitHub Repository ?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
CoronaVirus
  • 401
  • 2
  • 7
  • 20

4 Answers4

8

Are you using electron auto-updater module? from the API documentation, I can see that they don't support.

On the other hand, if you are using electron-updater module, make sure that you are following the recommended release workflow, and you should not use setFeedURL check the note here

Updated:

If you are using electron-updater and you are publishing to a private repository, you will need to make sure that your token will be available within the app-update.yml file, that's why many say it's not recommended, if the token is not set in your app-update.yml file you will get 404.

For electron-updater to auto add your token to the app-update.yml file the token should be set within the publish section like the following:

  "publish": [
    {
      "provider": "github",
      "private": true,
      "owner": "<github_owner>",
      "repo": "<repo_name>",
      "token": "<your github token>"
    }
  ],

This will produce a app-update.yml file like the following:

owner: <github_owner>
repo: <repo_name>
provider: github
private: true
token: <your github token>
updaterCacheDirName: electron-updater-private-updater

Check this small video

Here is my code https://github.com/linuxjuggler/electron-auto-update-example check the electron-builder.json file.

Update 2

Based on the note mentioned in the Quick Setup Guide section, you should never call setFeedURL.

Zaher
  • 1,120
  • 7
  • 18
  • Yes i am using electron-updater. referring the workflow mentioned setting GH_TOKEN and private option.but seems it is not available for all the users. – CoronaVirus Jul 17 '19 at 15:15
  • 1
    is it hard for you to share the code snippet for the whole update process, not just the setFeedURL one, cause I remember it worked with me when I test it? but to be honest I advise against using it for releasing your code as the final `app-update.yml` file will contain your `GH_TOKEN` in plain text, and since this the same key you are using for pushing the release anyone can then use it to release a new version. at least this is what I was thinking about. unless you are releasing it for a private group of users. – Zaher Jul 17 '19 at 22:27
  • Also when you release your code, what is the tag format you use? as github rely on the fact that your tag should prefixed with `v` (https://www.electron.build/configuration/publish#githuboptions) which is true by default. – Zaher Jul 17 '19 at 22:29
  • Yes, tag format are prefixed with v. just checked and confirmed. This is how i am checking for updates `autoUpdater.checkForUpdates(); autoUpdater.on('checking-for-update', () => { console.log("CHECKING FOR UPDATES !!"); }); ` and at start of script i am setting that setFeedURL – CoronaVirus Jul 18 '19 at 03:02
  • i read it works only for release-only github account. i set repository to release-only mode too. that did not work out either. – CoronaVirus Jul 18 '19 at 03:07
  • I'll create a test project today to remember what I did, and get back to you. – Zaher Jul 18 '19 at 09:12
  • Yeah it worked for me. somehow release-only repository worked. rest of the configuration was correct as yours. btw .. Great thanks. – CoronaVirus Jul 25 '19 at 02:54
  • Can we manage somehow target branch name on github to publish ? and targeting any specific branch name to download update from. i want to publish separate release for each environment Dev, QA and PROD based upon some branch strategy. Or any suggestion for this ? – CoronaVirus Jul 25 '19 at 02:57
  • Am not sure there is a way to do that, as I know the build will be based on the currently active branch, but you might need to read about channels https://www.electron.build/tutorials/release-using-channels.html this way each environment will get its own, but again am not sure if this is a perfect solution. – Zaher Jul 25 '19 at 08:39
  • Oh Man !! is this github private repo is unstable ? I literally changed nothing but this github auto update is again stopped working. 404 NOT FOUND `Error: Cannot download "https://api.github.com/repos/owner/repo-name/releases/assets/assets-number" status 404: Not Found ` – CoronaVirus Jul 26 '19 at 03:05
  • You may have hit the limit, https://www.electron.build/auto-update#private-github-update-repo , that's why github private is not recommended using S3 or something similar might be a better option that you should check. – Zaher Jul 26 '19 at 08:45
6

Auto-Update - you can see that private github repos works only for very special cases, and they are recommending to have a separate release-only repository to distribute releases so source is locked down, and you can distribute to controlled machines. It is a useful feature since no server is required, but special use case. Also, you can make this work with s3 bucket or some other upgrade servers.

bul3
  • 76
  • 3
  • yeah, Thanks for putting it on front. – CoronaVirus Jul 17 '19 at 15:17
  • 3
    Just to add to this, a public S3 bucket or a release-only repo are the most sane options. The answer marked as correct suggests putting the GitHub token in the repo, which I wouldn't recommend considering anyone with that token can read/write **any** GitHub repo on that account (that token is shipping with the client!). Nuts used to be a popular proxy server, but it hasn't been maintained, and I haven't found a fork that functions anymore. – Chris Hayes May 31 '21 at 16:21
0

I found this AutoUpdater Git Repo very helpful and my code is working now. Only change I needed to make is in github yml setting, add a token=<PersonalAccessToken> from github.

You can get Github personal token from Github > Settings > Developer Settings > Personal access tokens > Generate New Token

Vishnu
  • 2,135
  • 2
  • 30
  • 51
0

If anyone is still having this problem (I was stuck for weeks), I created a package to help with this. electron-github-autoupdater

It's pretty much an exact clone of Electron's autoUpdate API that accepts a config object for your private/enterprise github repo configuration and access token. It should just work.

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 15 '22 at 05:51