Skip to content

Commit c39c8ef

Browse files
committed
updating electron-* versions, adding code for Mac code-signing/notarization, adding linux installer builds in docker
1 parent fb1b690 commit c39c8ef

File tree

8 files changed

+156
-19
lines changed

8 files changed

+156
-19
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
node_modules
22
dist/
33
yarn.lock
4+
package-lock.json
5+
/.idea
6+
*.iml
7+
docker.env

README.md

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,13 @@ If you can't use GitHub, you can use other providers:
99

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

12-
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://www.electron.build/code-signing).
12+
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 "Developer ID Application" 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://www.electron.build/code-signing).
13+
14+
This example application is set up to perform code-signing and notarization on Mac OS provided that a `Developer ID
15+
Application` certificate is installed in the default keychain. The following environment variables are important for the signing process:
16+
- `CSC_IDENTITY_AUTO_DISCOVERY` - controls whether `electron-builder` tries to sign the application; default is `true`, set to `false` to skip signing
17+
- `APPLEID` - the Apple ID to use for notarization (required for signing).
18+
- `APPLEIDPASS` - the password to use with the specified Apple ID for notarization (required for signing). Apple recommends setting up an app-specific password to safeguard the Apple ID password (see [Apple Support](https://support.apple.com/en-us/HT204397)) for more information.
1319

1420
2. Adjust `package.json` if needed.
1521

@@ -49,7 +55,7 @@ If you can't use GitHub, you can use other providers:
4955

5056
5. Publish for your platform with:
5157

52-
build -p always
58+
electron-builder -p always
5359

5460
or
5561

@@ -63,12 +69,16 @@ If you can't use GitHub, you can use other providers:
6369
},
6470
...
6571

66-
6. Release the release on GitHub by going to <https://github.com/YOUR_GIT_HUB_USERNAME/electron-updater-example/releases>, editing the release and clicking "Publish release."
72+
NOTE: The Mac OS signing/notarization process must be run on Mac OS. This application is set up to build Linux installers using the `electronuserland/builder` Docker image. Run:
73+
74+
npm run publish-linux-docker
6775

68-
7. Download and install the app from <https://github.com/YOUR_GIT_HUB_USERNAME/electron-updater-example/releases>.
76+
7. Release the release on GitHub by going to <https://github.com/YOUR_GIT_HUB_USERNAME/electron-updater-example/releases>, editing the release and clicking "Publish release."
6977

70-
8. Update the version in `package.json`, commit and push to GitHub.
78+
8. Download and install the app from <https://github.com/YOUR_GIT_HUB_USERNAME/electron-updater-example/releases>.
7179

72-
9. Do steps 5 and 6 again.
80+
9. Update the version in `package.json`, commit and push to GitHub.
7381

74-
10. Open the installed version of the app and see that it updates itself.
82+
10. Do steps 5 and 6 again.
83+
84+
11. Open the installed version of the app and see that it updates itself.

build/entitlements.mac.plist

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>com.apple.security.cs.debugger</key>
6+
<true/>
7+
<key>com.apple.security.cs.allow-jit</key>
8+
<true/>
9+
<key>com.apple.security.cs.allow-unsigned-executable-memory</key>
10+
<true/>
11+
<key>com.apple.security.cs.allow-dyld-environment-variables</key>
12+
<true/>
13+
<key>com.apple.security.cs.disable-library-validation</key>
14+
<true/>
15+
</dict>
16+
</plist>

build/linuxInstallers.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env bash
2+
3+
SCRIPT_DIR=$(dirname "$0")
4+
export WORKSPACE=$(cd "${SCRIPT_DIR}/.."; pwd)
5+
if [ -z "${GH_TOKEN}" ]; then
6+
echo "GH_TOKEN environment variable must be set prior to running this script">&2
7+
exit 1
8+
fi
9+
10+
EXAMPLE_ENV_FILE="${WORKSPACE}/docker.env"
11+
echo "EXAMPLE_USER=$(id -un)" > "${EXAMPLE_ENV_FILE}"
12+
# shellcheck disable=SC2129
13+
echo "EXAMPLE_UID=$(id -u)" >> "${EXAMPLE_ENV_FILE}"
14+
echo "EXAMPLE_GROUP=$(id -gn)" >> "${EXAMPLE_ENV_FILE}"
15+
echo "EXAMPLE_GID=$(id -g)" >> "${EXAMPLE_ENV_FILE}"
16+
echo "GH_TOKEN=${GH_TOKEN}" >> "${EXAMPLE_ENV_FILE}"
17+
18+
if [ -n "${HTTPS_PROXY}" ]; then
19+
echo "HTTPS_PROXY=${HTTPS_PROXY}" >> "${EXAMPLE_ENV_FILE}"
20+
fi
21+
22+
docker run --rm -v "${WORKSPACE}:/project" --env-file "${EXAMPLE_ENV_FILE}" electronuserland/builder /project/build/linuxInstallersInDocker.sh

build/linuxInstallersInDocker.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env /bin/bash
2+
if [ -z "${EXAMPLE_USER}" ] || [ -z "${EXAMPLE_UID}" ]; then
3+
echo "EXAMPLE_USER and EXAMPLE_UID environment variables must be set" 1>&2
4+
exit 1
5+
fi
6+
if [ -z "${EXAMPLE_GROUP}" ] || [ -z "${EXAMPLE_GID}" ]; then
7+
echo "EXAMPLE_GROUP and EXAMPLE_GID environment variables must be set" 1>&2
8+
exit 1
9+
fi
10+
11+
groupadd --gid "${EXAMPLE_GID}" "${EXAMPLE_GROUP}"
12+
useradd --gid "${EXAMPLE_GID}" --uid "${EXAMPLE_UID}" --shell /bin/bash --no-create-home "${EXAMPLE_USER}"
13+
14+
# Electron Builder seems to rely on the user's home directory being present...
15+
mkdir -p "/home/${EXAMPLE_USER}"
16+
chmod 777 "/home/${EXAMPLE_USER}"
17+
18+
# Electron Builder tries to create /scratch when it needs to build a binary (rather than using prebuilt binaries)
19+
# so create it prior to running it with the necessary permissions.
20+
mkdir -p "/scratch"
21+
chmod 777 "/scratch"
22+
23+
#
24+
# Build the installers
25+
#
26+
cd /project || exit
27+
NPM_COMMAND="npm run publish"
28+
if [ "${HTTPS_PROXY}" != "" ]; then
29+
NPM_COMMAND="HTTPS_PROXY=${HTTPS_PROXY} $NPM_COMMAND"
30+
fi
31+
32+
su "${EXAMPLE_USER}" --command "${NPM_COMMAND}"
33+
34+
NPM_EXIT_CODE=$?
35+
if [ ${NPM_EXIT_CODE} -ne 0 ]; then
36+
exit ${NPM_EXIT_CODE}
37+
fi

build/notarize.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const { notarize } = require('electron-notarize');
2+
const path = require('path');
3+
4+
exports.default = async function notarizing(context) {
5+
const { electronPlatformName, appOutDir } = context;
6+
if (electronPlatformName !== 'darwin') {
7+
return;
8+
}
9+
10+
const appName = context.packager.appInfo.productFilename;
11+
const appPath = path.normalize(path.join(process.cwd(), 'dist', 'mac', `${appName}.app`));
12+
console.log('calling notarize with appPath = %s', appPath);
13+
return await notarize({
14+
appBundleId: 'com.github.iffy.electronupdaterexample',
15+
appPath: appPath,
16+
appleId: process.env.APPLEID,
17+
appleIdPassword: process.env.APPLEIDPASS,
18+
});
19+
};

main.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// This is free and unencumbered software released into the public domain.
22
// See LICENSE for details
33

4-
const {app, BrowserWindow, Menu, protocol, ipcMain} = require('electron');
4+
const {app, BrowserWindow, Menu} = require('electron');
55
const log = require('electron-log');
66
const {autoUpdater} = require("electron-updater");
77

@@ -59,7 +59,12 @@ function sendStatusToWindow(text) {
5959
win.webContents.send('message', text);
6060
}
6161
function createDefaultWindow() {
62-
win = new BrowserWindow();
62+
win = new BrowserWindow({
63+
webPreferences: {
64+
nodeIntegration: true,
65+
contextIsolation: false
66+
}
67+
});
6368
win.webContents.openDevTools();
6469
win.on('closed', () => {
6570
win = null;

package.json

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,52 @@
11
{
22
"name": "electron-updater-example",
3-
"version": "0.7.1",
3+
"version": "0.7.2",
44
"main": "main.js",
55
"description": "electron-updater example project",
66
"author": "Matt Haggard",
77
"scripts": {
8-
"publish": "build -p always"
8+
"publish": "electron-builder -p always",
9+
"publish-linux-docker": "./build/linuxInstallers.sh"
910
},
1011
"devDependencies": {
11-
"electron": "^3.0.2",
12-
"electron-builder": "^20.28.4"
12+
"electron": "^14.0.1",
13+
"electron-builder": "^22.11.7"
1314
},
1415
"dependencies": {
15-
"electron-log": "^1.3.0",
16-
"electron-updater": "^4.0.6"
16+
"electron-log": "^4.4.1",
17+
"electron-updater": "^4.3.9"
1718
},
1819
"build": {
1920
"appId": "com.github.iffy.electronupdaterexample",
21+
"productName": "Electron Updater Example",
22+
"afterSign": "./build.notarize.js",
23+
"directories": {
24+
"output": "dist"
25+
},
26+
"files": [
27+
"!.DS_Store"
28+
],
2029
"mac": {
2130
"category": "your.app.category.type",
22-
"target": [
23-
"zip",
24-
"dmg"
25-
]
31+
"target": "default",
32+
"type": "distribution",
33+
"hardenedRuntime": true,
34+
"gatekeeperAsses": false,
35+
"entitlements": "./build/entitlements.mac.plist"
36+
},
37+
"dmg": {
38+
"sign": false
39+
},
40+
"win": {
41+
"target": "nsis"
42+
},
43+
"nsis": {
44+
"oneClick": false,
45+
"allowToChangeInstallationDirectory": true
46+
},
47+
"linux": {
48+
"category": "your.app.category.type",
49+
"target": "AppImage"
2650
}
2751
}
2852
}

0 commit comments

Comments
 (0)