Skip to content

Commit

Permalink
feat(release): auto update (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
lsagetlethias committed Jan 10, 2022
1 parent 540da63 commit 637810d
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 32 deletions.
25 changes: 6 additions & 19 deletions .github/workflows/release.yml
Expand Up @@ -62,29 +62,14 @@ jobs:
target:
- linux
- mac
# - win32
# - win32-msi
- win64
- win64-msi
- win
include:
- target: linux
os: ubuntu-latest
ext: AppImage
- target: mac
os: macos-latest
ext: dmg
# - target: win32
# os: windows-latest
# ext: exe
# - target: win32-msi
# os: windows-latest
# ext: msi
- target: win64
- target: win
os: windows-latest
ext: exe
- target: win64-msi
os: windows-latest
ext: msi

name: Build binary for ${{ matrix.target }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
Expand Down Expand Up @@ -117,7 +102,9 @@ jobs:
uses: actions/upload-artifact@v2
with:
name: ${{ matrix.target }}-bin
path: electron/dist/*/archimail.${{ matrix.ext }}
path: |
electron/dist/*/archimail*.*
electron/dist/*/latest*.yml
Release:
needs: Build
Expand All @@ -134,7 +121,7 @@ jobs:
- name: Generate hashes
run: >-
find . -regextype posix-extended
-regex ".*/bin/.*/archimail\.(exe|AppImage|dmg|msi)$"
-regex ".*/bin/.*/archimail.*\.(exe|AppImage|dmg|msi|zip)$"
-type f
-exec bash -c "openssl dgst -sha512 {} > {}.sha512" \;
- name: Setup Node
Expand Down
6 changes: 4 additions & 2 deletions .releaserc.js
Expand Up @@ -31,7 +31,10 @@ if (releaseMode === "normal") {
plugins.push([
"@semantic-release/github",
{
assets: ["bin/**/archimail.@(exe|dmg|AppImage|msi)?(.sha512)"],
assets: [
"bin/**/archimail*.@(exe|dmg|AppImage|msi|zip)?(.sha512|blockmap)",
"bin/**/latest*.yml",
],
releasedLabels: false,
successComment: false,
},
Expand All @@ -53,7 +56,6 @@ if (releaseMode === "normal") {
/** @type {import("semantic-release").Options} */
const config = {
branches: [
"feature/release-ci",
"main",
{
channel: "next",
Expand Down
22 changes: 14 additions & 8 deletions package.json
Expand Up @@ -11,11 +11,8 @@
"dev": "electron-webpack dev",
"debug": "cross-env 'ELECTRON_ARGS=[\"--inspect-brk=9229\"]' yarn dev",
"compile": "electron-webpack",
"dist:win32": "electron-builder --windows portable --ia32",
"dist:win64": "electron-builder --windows portable --x64",
"dist:win32-msi": "electron-builder --windows portable --ia32 --windows=msi",
"dist:win64-msi": "electron-builder --windows portable --x64 --windows=msi",
"dist:mac": "electron-builder --mac dmg",
"dist:win": "electron-builder --x64 --win portable msi nsis",
"dist:mac": "electron-builder --mac dmg zip",
"dist:mac-local": "CSC_IDENTITY_AUTO_DISCOVERY=false electron-builder --mac dmg",
"dist:linux": "electron-builder --linux AppImage",
"start": "electron dist/main/main.js",
Expand Down Expand Up @@ -47,8 +44,9 @@
},
"//build.extraResources": "Static should be set again because it is overwritten",
"build": {
"generateUpdatesFilesForAllChannels": true,
"appId": "fr.gouv.social.fabrique.archimail",
"artifactName": "archimail.${ext}",
"artifactName": "archimail-${os}.${ext}",
"productName": "Archimail",
"afterSign": "scripts/notarize.js",
"files": [
Expand All @@ -71,7 +69,7 @@
}
],
"directories": {
"output": "electron/dist/${os}-${arch}"
"output": "electron/dist/${os}"
},
"mac": {
"category": "public.app-category.productivity",
Expand All @@ -82,7 +80,14 @@
"entitlementsInherit": "./electron/build/entitlements.mac.plist"
},
"win": {
"icon": "./electron/build/icon.png"
"icon": "./electron/build/icon.png",
"artifactName": "archimail-${os}-standalone.${ext}"
},
"msi": {
"artifactName": "archimail-${os}.${ext}"
},
"nsis": {
"artifactName": "archimail-${os}-setup.${ext}"
},
"linux": {
"category": "Office",
Expand Down Expand Up @@ -148,6 +153,7 @@
"@socialgouv/archimail-pst-extractor": "^0.0.2",
"d3": "^7.2.1",
"electron-store": "^8.0.1",
"electron-updater": "^4.6.1",
"json2csv": "^5.0.6",
"normalize.css": "^8.0.1",
"react": "^17.0.2",
Expand Down
2 changes: 1 addition & 1 deletion src/main/index.ts
Expand Up @@ -79,7 +79,7 @@ app.on("ready", async () => {
// load "main-process" modules
await loadModules(
...isomorphicModules,
new AppModule(mainWindowRetriever),
new AppModule(mainWindowRetriever, consoleToRendererService),
new DevToolsModule(),
new PstExtractorModule(containerModule.get("userConfigService")),
new MenuModule(
Expand Down
69 changes: 67 additions & 2 deletions src/main/modules/AppModule.ts
@@ -1,18 +1,24 @@
import { IS_DEV, IS_E2E } from "@common/config";
import type { Module } from "@common/modules/Module";
import { dialog } from "electron";
import type { ProgressInfo, UpdateInfo } from "electron-updater";
import { autoUpdater } from "electron-updater";

import type { MainWindowRetriever } from "..";
import type { ConsoleToRendererService } from "../services/ConsoleToRendererService";

/**
* Module to handle almost all global app related stuff like closing, navigating.
*/
export class AppModule implements Module {
constructor(private readonly mainWindowRetriever: MainWindowRetriever) {}
constructor(
private readonly mainWindowRetriever: MainWindowRetriever,
private readonly consoleToRendererService: ConsoleToRendererService
) {}

async init(): Promise<void> {
// can't await because mainWindow is created after this init
void this.mainWindowRetriever().then((mainWindow) => {
void this.mainWindowRetriever().then(async (mainWindow) => {
// prevent navigation
mainWindow.webContents.on("will-navigate", (event) => {
event.preventDefault();
Expand All @@ -38,6 +44,65 @@ export class AppModule implements Module {
}
});
}

autoUpdater.on("check-for-update", (evt) => {
this.consoleToRendererService.log(
mainWindow,
"[UPDATE] Check for update",
evt
);
});

autoUpdater.on("update-available", (info: UpdateInfo) => {
this.consoleToRendererService.log(
mainWindow,
"[UPDATE] Update available",
info
);
});

autoUpdater.on("update-not-available", (info: UpdateInfo) => {
this.consoleToRendererService.log(
mainWindow,
"[UPDATE] Update NOT available",
info
);
});

autoUpdater.on("error", (err) => {
this.consoleToRendererService.log(
mainWindow,
"[UPDATE] Error",
err
);
});

autoUpdater.on("download-progress", (progress: ProgressInfo) => {
this.consoleToRendererService.log(
mainWindow,
"[UPDATE] Progress...",
progress
);
});

const log = this.consoleToRendererService.log.bind(
this.consoleToRendererService,
mainWindow
);
autoUpdater.logger = {
debug: log,
error: log,
info: log,
warn: log,
};
this.consoleToRendererService.log(
mainWindow,
"Current version:",
autoUpdater.currentVersion.raw,
autoUpdater.currentVersion
);
autoUpdater.allowDowngrade = false;
await autoUpdater.checkForUpdatesAndNotify();
});

return Promise.resolve();
Expand Down
24 changes: 24 additions & 0 deletions yarn.lock
Expand Up @@ -2381,6 +2381,11 @@
resolved "https://registry.yarnpkg.com/@types/scheduler/-/scheduler-0.16.2.tgz#1a62f89525723dde24ba1b01b092bf5df8ad4d39"
integrity sha512-hppQEBDmlwhFAXKJX2KnWLYu5yMfi91yazPb2l+lbJiwW+wdo1gNeRA+3RgNSO39WYX2euey41KEwnqesU2Jew==

"@types/semver@^7.3.6":
version "7.3.9"
resolved "https://registry.yarnpkg.com/@types/semver/-/semver-7.3.9.tgz#152c6c20a7688c30b967ec1841d31ace569863fc"
integrity sha512-L/TMpyURfBkf+o/526Zb6kd/tchUP3iBDEPjqjb+U2MAJhVRxxrmr2fwpe08E7QsV7YLcpq0tUaQ9O9x97ZIxQ==

"@types/source-list-map@*":
version "0.1.2"
resolved "https://registry.yarnpkg.com/@types/source-list-map/-/source-list-map-0.1.2.tgz#0078836063ffaf17412349bba364087e0ac02ec9"
Expand Down Expand Up @@ -5745,6 +5750,20 @@ electron-to-chromium@^1.3.896:
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.5.tgz#912e8fd1645edee2f0f212558f40916eb538b1f9"
integrity sha512-YKaB+t8ul5crdh6OeqT2qXdxJGI0fAYb6/X8pDIyye+c3a7ndOCk5gVeKX+ABwivCGNS56vOAif3TN0qJMpEHw==

electron-updater@^4.6.1:
version "4.6.1"
resolved "https://registry.yarnpkg.com/electron-updater/-/electron-updater-4.6.1.tgz#80ca805c4f51b2e682aac29d18fed75d6a533d32"
integrity sha512-YsU1mHqXLrXXmBMsxhxy24PrbaB8rnpZDPmFa2gOkTYk/Ch13+R0fjsRSpPYvqtskVVY0ux8fu+HnUkVkqc7og==
dependencies:
"@types/semver" "^7.3.6"
builder-util-runtime "8.9.1"
fs-extra "^10.0.0"
js-yaml "^4.1.0"
lazy-val "^1.0.5"
lodash.escaperegexp "^4.1.2"
lodash.isequal "^4.5.0"
semver "^7.3.5"

electron-webpack-js@~2.4.1:
version "2.4.1"
resolved "https://registry.yarnpkg.com/electron-webpack-js/-/electron-webpack-js-2.4.1.tgz#5389cc22f34c71f6416d5ba1e043f9b0fd6130af"
Expand Down Expand Up @@ -9355,6 +9374,11 @@ lodash.get@^4.4.2:
resolved "https://registry.yarnpkg.com/lodash.get/-/lodash.get-4.4.2.tgz#2d177f652fa31e939b4438d5341499dfa3825e99"
integrity sha1-LRd/ZS+jHpObRDjVNBSZ36OCXpk=

lodash.isequal@^4.5.0:
version "4.5.0"
resolved "https://registry.yarnpkg.com/lodash.isequal/-/lodash.isequal-4.5.0.tgz#415c4478f2bcc30120c22ce10ed3226f7d3e18e0"
integrity sha1-QVxEePK8wwEgwizhDtMib30+GOA=

lodash.ismatch@^4.4.0:
version "4.4.0"
resolved "https://registry.yarnpkg.com/lodash.ismatch/-/lodash.ismatch-4.4.0.tgz#756cb5150ca3ba6f11085a78849645f188f85f37"
Expand Down

0 comments on commit 637810d

Please sign in to comment.