Javascript 使用Gitlab进行电子更新

Javascript 使用Gitlab进行电子更新,javascript,electron,auto-update,Javascript,Electron,Auto Update,是否可以将Electron内置的自动更新程序与Gitlab标记一起使用 我已经看到,您可以通过使用Electron来发布GitHub,但我不确定Gitlab是否也可以使用Electron,因为需要使用GitHub令牌 如果没有使用Gitlab的选项,那么唯一的其他选项是(a)自托管squirrel服务器还是(b)github发行版?您可以使用通用主机,这是最简单的方法,请参阅: 您可以编辑updates.json/yml以指向gitlab版本,它不会比普通服务器更糟糕。不过,它不会检查gitl

是否可以将Electron内置的自动更新程序与Gitlab标记一起使用

我已经看到,您可以通过使用Electron来发布GitHub,但我不确定Gitlab是否也可以使用Electron,因为需要使用GitHub令牌


如果没有使用Gitlab的选项,那么唯一的其他选项是(a)自托管squirrel服务器还是(b)github发行版?

您可以使用通用主机,这是最简单的方法,请参阅:

您可以编辑updates.json/yml以指向gitlab版本,它不会比普通服务器更糟糕。不过,它不会检查gitlab凭据

您可以使用Amazon S3或Bintray,请参阅:

Google Compute声称可以将它们设置为与S3兼容,因此您也可以使用它们

您可以使用git+ssh语法使用与Github相同的Gitlab版本。还没有测试过,但请参见我的工作示例

.gitlab ci

variables:
  VERSION_ID: '1.0.$CI_PIPELINE_ID'

stages:
  - build

build:
  image: slauta93/electron-builder-win
  stage: build
  artifacts:
    paths:
      - $CI_PROJECT_DIR/dist/*.*
  script:
    - sed "s/0.0.0/${VERSION_ID}/g" package.json > _package.json && mv _package.json package.json
    - npm install && npm run build
main.js

// Inital app
const electron = require("electron");
const updater = require("electron-updater");
const autoUpdater = updater.autoUpdater;

...

///////////////////
// Auto upadater //
///////////////////
autoUpdater.requestHeaders = { "PRIVATE-TOKEN": "Personal access Token" };
autoUpdater.autoDownload = true;

autoUpdater.setFeedURL({
    provider: "generic",
    url: "https://gitlab.com/_example_repo_/-/jobs/artifacts/master/raw/dist?job=build"
});

autoUpdater.on('checking-for-update', function () {
    sendStatusToWindow('Checking for update...');
});

autoUpdater.on('update-available', function (info) {
    sendStatusToWindow('Update available.');
});

autoUpdater.on('update-not-available', function (info) {
    sendStatusToWindow('Update not available.');
});

autoUpdater.on('error', function (err) {
    sendStatusToWindow('Error in auto-updater.');
});

autoUpdater.on('download-progress', function (progressObj) {
    let log_message = "Download speed: " + progressObj.bytesPerSecond;
    log_message = log_message + ' - Downloaded ' + parseInt(progressObj.percent) + '%';
    log_message = log_message + ' (' + progressObj.transferred + "/" + progressObj.total + ')';
    sendStatusToWindow(log_message);
});

autoUpdater.on('update-downloaded', function (info) {
    sendStatusToWindow('Update downloaded; will install in 1 seconds');
});

autoUpdater.on('update-downloaded', function (info) {
    setTimeout(function () {
        autoUpdater.quitAndInstall();
    }, 1000);
});

autoUpdater.checkForUpdates();

function sendStatusToWindow(message) {
    console.log(message);
}
...
package.json

{
  "name": "electron-updater-gitlab",
  "version": "0.0.0",
  "main": "main.js",
  "scripts": {
    "start": "electron .",
    "pack": "node_modules/.bin/electron-builder --dir",
    "build": "node_modules/.bin/electron-builder --win",
    "postinstall": "",
    "install": "node-gyp install",
  },
  "build": {
    "appId": "com.electron.app",
    "publish": [
      {
        "provider": "generic",
        "url": "https://gitlab.com"
      }
    ],
    "win": {
      "target": [
        "nsis"
      ],
      "verifyUpdateCodeSignature": false
    },
    "mac": {
      "category": "public.app-category.productivity",
      "identity": "Mac Developer: username (XXXXXXXX)",
      "target": [
        "dmg"
      ]
    },
    "linux": {
      "target": [
        "AppImage"
      ]
    }
  },
  "dependencies": {
    "electron-updater": "^2.7.2"
  },
  "devDependencies": {
    "electron": "1.6.11",
    "electron-builder": "^19.16.2"
  }
}

在考虑了这个问题和其他问题的答案之后,我最终使用GitLab页面发布了我的构建工件。这使我能够使安装程序文件免费提供给我的组织中的每个人,而无需向所有人开放repo

.gitlab-ci.yml:
阶段:
-试验
-建造
-部署
测试应用程序:
阶段:测试
图:节点:lts
脚本:
-npm安装
-npm运行测试:颜色
电子释放构建:
仅:
-主人
阶段:建造
图片:electronuserland/建筑商:葡萄酒
脚本:
-npm ci
-npm运行包:发布
人工产品:
路径:
-电子释放/*.exe*
-电子释放/*.yml
过期时间:1个月
页:
阶段:部署
仅:
-主人
图片:阿尔卑斯山:最新
依赖项:
-电子释放构建
脚本:
#请注意,“public”已存在于该回购协议中,并有一个index.html
#充当下载页面。
-cp electron release/*.exe electron release/*.blockmap electron release/*.yml public
-EXE_FILENAME=$(查找./electron release-maxdepth 1-name“Maestro*.EXE”)
-EXE\u BASENAME=$(BASENAME“$EXE\u FILENAME”)
-sed-i“s/INSERT_FILE_NAME/${EXE_BASENAME}/g”。/public/index.html
人工产品:
路径:
-公开的
package.json的相关部分: 其他任何地方都不需要改变


这也简化了一些事情,因为我不认为我可以使用另一个答案中提出的提供者URL,因为权限(
https://gitlab.com/_example_repo_/-/jobs/artifacts/master/raw/dist?job=build
404给我)。

我刚得到这个回购设置。每个版本都包含*.exe文件作为链接资源。生成后,*.exe将作为包上载。对于其他正在寻找解决方案的人,我有一个基于@slauta93下面答案的示例repo设置,但针对gitlab api的更改进行了更新。
{
  "build": {
    "asar": true,
    "appId": "com.myapp.app",
    "productName": "myapp",
    "directories": {
      "output": "electron-release"
    },
    "extraFiles": [
      "build/icon.ico"
    ],
    "detectUpdateChannel": false,
    "publish": {
      "provider": "generic",
      "url": "https://myappgroup.pages.example.com/myapp"
    },
    "win": {
      "target": "nsis",
      "verifyUpdateCodeSignature": false,
      "icon": "build/icon.ico"
    },
    "nsis": {
      "oneClick": false,
      "perMachine": false,
      "allowElevation": true,
      "allowToChangeInstallationDirectory": true
    }
  }
}