Skip to content

Instantly share code, notes, and snippets.

@dansanti
Forked from Slauta/.gitlab-ci
Created August 14, 2023 14:40
Show Gist options
  • Select an option

  • Save dansanti/292803653c5c9506cf070dce60a3bb19 to your computer and use it in GitHub Desktop.

Select an option

Save dansanti/292803653c5c9506cf070dce60a3bb19 to your computer and use it in GitHub Desktop.

Revisions

  1. @Slauta Slauta revised this gist Jul 29, 2017. 1 changed file with 57 additions and 1 deletion.
    58 changes: 57 additions & 1 deletion main.js
    Original file line number Diff line number Diff line change
    @@ -1 +1,57 @@
    const electron = require("electron");
    // 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);
    }
    ...
  2. @Slauta Slauta revised this gist Jul 29, 2017. 3 changed files with 4 additions and 6 deletions.
    6 changes: 2 additions & 4 deletions .gitlab-ci
    Original file line number Diff line number Diff line change
    @@ -4,14 +4,12 @@ variables:
    stages:
    - build

    build:win32:
    build:
    image: slauta93/electron-builder-win
    stage: build
    artifacts:
    paths:
    - $CI_PROJECT_DIR/dist/*.*
    before_script:
    - npm install -g bower
    script:
    - sed "s/0.0.0/${VERSION_ID}/g" package.json > package2.json && mv package2.json package.json
    - sed "s/0.0.0/${VERSION_ID}/g" package.json > _package.json && mv _package.json package.json
    - npm install && npm run build
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -4,6 +4,6 @@ This repo contains the **bare minimum code** to have an auto-updating Electron a

    Install Xcode (from the App Store), then follow [these instructions](https://developer.apple.com/library/content/documentation/IDEs/Conceptual/AppDistributionGuide/MaintainingCertificates/MaintainingCertificates.html#//apple_ref/doc/uid/TP40012582-CH31-SW6) to make sure you have a "Mac Developer" certificate. If you'd like to export the certificate (for automated building, for instance) [you can](https://developer.apple.com/library/content/documentation/IDEs/Conceptual/AppDistributionGuide/MaintainingCertificates/MaintainingCertificates.html#//apple_ref/doc/uid/TP40012582-CH31-SW7). You would then follow [these instructions](https://github.com/electron-userland/electron-builder/wiki/Code-Signing).

    2. Setting you CI
    2. Setting you Gitlab-CI and edit package.json build scripts fron your platforms
    3. Pushing new code, and install last build
    4. Open the installed version of the app and see that it updates itself.
    2 changes: 1 addition & 1 deletion package.json
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@
    "scripts": {
    "start": "electron .",
    "pack": "node_modules/.bin/electron-builder --dir",
    "dist": "node_modules/.bin/electron-builder --win",
    "build": "node_modules/.bin/electron-builder --win",
    "postinstall": "",
    "install": "node-gyp install",
    },
  3. @Slauta Slauta revised this gist Jul 29, 2017. 3 changed files with 66 additions and 36 deletions.
    18 changes: 17 additions & 1 deletion .gitlab-ci
    Original file line number Diff line number Diff line change
    @@ -1 +1,17 @@
    build:
    variables:
    VERSION_ID: '1.0.$CI_PIPELINE_ID'

    stages:
    - build

    build:win32:
    image: slauta93/electron-builder-win
    stage: build
    artifacts:
    paths:
    - $CI_PROJECT_DIR/dist/*.*
    before_script:
    - npm install -g bower
    script:
    - sed "s/0.0.0/${VERSION_ID}/g" package.json > package2.json && mv package2.json package.json
    - npm install && npm run build
    37 changes: 3 additions & 34 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -1,40 +1,9 @@
    This repo contains the **bare minimum code** to have an auto-updating Electron app using [`electron-updater`](https://github.com/electron-userland/electron-builder/tree/master/packages/electron-updater) with releases stored on a plain HTTP server.

    This example uses `localhost` as the release server.

    1. For macOS, you will need a code-signing certificate.

    Install Xcode (from the App Store), then follow [these instructions](https://developer.apple.com/library/content/documentation/IDEs/Conceptual/AppDistributionGuide/MaintainingCertificates/MaintainingCertificates.html#//apple_ref/doc/uid/TP40012582-CH31-SW6) to make sure you have a "Mac Developer" certificate. If you'd like to export the certificate (for automated building, for instance) [you can](https://developer.apple.com/library/content/documentation/IDEs/Conceptual/AppDistributionGuide/MaintainingCertificates/MaintainingCertificates.html#//apple_ref/doc/uid/TP40012582-CH31-SW7). You would then follow [these instructions](https://github.com/electron-userland/electron-builder/wiki/Code-Signing).

    2. Install necessary dependencies with:

    yarn

    or

    npm install

    3. Build your app with:

    node_modules/.bin/build --win --mac --x64 --ia32

    4. Copy the files in the `dist/` directory to your webserver. Here's how to do it on a Linux system:

    mkdir -p wwwroot
    cp dist/*.json wwwroot/
    cp dist/*.yml wwwroot/
    cp dist/mac/*.zip wwwroot/
    cp dist/mac/*.dmg wwwroot/
    cp dist/*.exe wwwroot/

    5. Serve `wwwroot` over HTTP:

    node_modules/.bin/http-server wwwroot/ -p 8080

    6. Download and install the app from <http://127.0.0.1:8080>

    7. Update the version in `package.json`.

    8. Do steps 3 and 4 again.

    9. Open the installed version of the app and see that it updates itself.
    2. Setting you CI
    3. Pushing new code, and install last build
    4. Open the installed version of the app and see that it updates itself.
    47 changes: 46 additions & 1 deletion package.json
    Original file line number Diff line number Diff line change
    @@ -1 +1,46 @@
    {}
    {
    "name": "electron-updater-gitlab",
    "version": "0.0.0",
    "main": "main.js",
    "scripts": {
    "start": "electron .",
    "pack": "node_modules/.bin/electron-builder --dir",
    "dist": "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"
    }
    }
  4. @Slauta Slauta created this gist Jul 29, 2017.
    1 change: 1 addition & 0 deletions .gitlab-ci
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    build:
    40 changes: 40 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,40 @@
    This repo contains the **bare minimum code** to have an auto-updating Electron app using [`electron-updater`](https://github.com/electron-userland/electron-builder/tree/master/packages/electron-updater) with releases stored on a plain HTTP server.

    This example uses `localhost` as the release server.

    1. For macOS, you will need a code-signing certificate.

    Install Xcode (from the App Store), then follow [these instructions](https://developer.apple.com/library/content/documentation/IDEs/Conceptual/AppDistributionGuide/MaintainingCertificates/MaintainingCertificates.html#//apple_ref/doc/uid/TP40012582-CH31-SW6) to make sure you have a "Mac Developer" certificate. If you'd like to export the certificate (for automated building, for instance) [you can](https://developer.apple.com/library/content/documentation/IDEs/Conceptual/AppDistributionGuide/MaintainingCertificates/MaintainingCertificates.html#//apple_ref/doc/uid/TP40012582-CH31-SW7). You would then follow [these instructions](https://github.com/electron-userland/electron-builder/wiki/Code-Signing).

    2. Install necessary dependencies with:

    yarn

    or

    npm install

    3. Build your app with:

    node_modules/.bin/build --win --mac --x64 --ia32

    4. Copy the files in the `dist/` directory to your webserver. Here's how to do it on a Linux system:

    mkdir -p wwwroot
    cp dist/*.json wwwroot/
    cp dist/*.yml wwwroot/
    cp dist/mac/*.zip wwwroot/
    cp dist/mac/*.dmg wwwroot/
    cp dist/*.exe wwwroot/

    5. Serve `wwwroot` over HTTP:

    node_modules/.bin/http-server wwwroot/ -p 8080

    6. Download and install the app from <http://127.0.0.1:8080>

    7. Update the version in `package.json`.

    8. Do steps 3 and 4 again.

    9. Open the installed version of the app and see that it updates itself.
    1 change: 1 addition & 0 deletions main.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    const electron = require("electron");
    1 change: 1 addition & 0 deletions package.json
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    {}