mirror of
https://github.com/element-hq/element-desktop.git
synced 2025-09-17 11:04:22 +02:00
Reintroduce "Switch to a build variant config instead of magic env vars" (#2522)
This commit is contained in:
committed by
GitHub
parent
5561e2efa3
commit
b8bedd9c22
3
.github/workflows/build_linux.yaml
vendored
3
.github/workflows/build_linux.yaml
vendored
@@ -145,8 +145,9 @@ jobs:
|
|||||||
- name: Build App
|
- name: Build App
|
||||||
run: yarn build --publish never -l ${{ steps.config.outputs.build-args }}
|
run: yarn build --publish never -l ${{ steps.config.outputs.build-args }}
|
||||||
env:
|
env:
|
||||||
|
VARIANT_PATH: variant.json
|
||||||
# Only set for Nightly builds
|
# Only set for Nightly builds
|
||||||
ED_NIGHTLY: ${{ inputs.version }}
|
VERSION: ${{ inputs.version }}
|
||||||
|
|
||||||
- name: Check native libraries
|
- name: Check native libraries
|
||||||
run: |
|
run: |
|
||||||
|
|||||||
4
.github/workflows/build_macos.yaml
vendored
4
.github/workflows/build_macos.yaml
vendored
@@ -96,8 +96,9 @@ jobs:
|
|||||||
APPLE_APP_SPECIFIC_PASSWORD: ${{ secrets.APPLE_ID_PASSWORD }}
|
APPLE_APP_SPECIFIC_PASSWORD: ${{ secrets.APPLE_ID_PASSWORD }}
|
||||||
CSC_KEY_PASSWORD: ${{ secrets.APPLE_CSC_KEY_PASSWORD }}
|
CSC_KEY_PASSWORD: ${{ secrets.APPLE_CSC_KEY_PASSWORD }}
|
||||||
CSC_LINK: ${{ secrets.APPLE_CSC_LINK }}
|
CSC_LINK: ${{ secrets.APPLE_CSC_LINK }}
|
||||||
|
VARIANT_PATH: variant.json
|
||||||
# Only set for Nightly builds
|
# Only set for Nightly builds
|
||||||
ED_NIGHTLY: ${{ inputs.version }}
|
VERSION: ${{ inputs.version }}
|
||||||
|
|
||||||
- name: Check app was signed & notarised successfully
|
- name: Check app was signed & notarised successfully
|
||||||
if: inputs.sign != ''
|
if: inputs.sign != ''
|
||||||
@@ -113,6 +114,7 @@ jobs:
|
|||||||
yarn build:universal --publish never
|
yarn build:universal --publish never
|
||||||
env:
|
env:
|
||||||
CSC_IDENTITY_AUTO_DISCOVERY: false
|
CSC_IDENTITY_AUTO_DISCOVERY: false
|
||||||
|
VARIANT_PATH: variant.json
|
||||||
|
|
||||||
- name: Generate releases.json
|
- name: Generate releases.json
|
||||||
if: inputs.base-url
|
if: inputs.base-url
|
||||||
|
|||||||
6
.github/workflows/build_prepare.yaml
vendored
6
.github/workflows/build_prepare.yaml
vendored
@@ -85,6 +85,11 @@ jobs:
|
|||||||
if: steps.branch-matching.outcome == 'failure' || steps.branch-matching.outcome == 'skipped'
|
if: steps.branch-matching.outcome == 'failure' || steps.branch-matching.outcome == 'skipped'
|
||||||
run: yarn run fetch --noverify -d ${{ inputs.config }} ${{ inputs.version }}
|
run: yarn run fetch --noverify -d ${{ inputs.config }} ${{ inputs.version }}
|
||||||
|
|
||||||
|
- name: Copy variant config
|
||||||
|
run: cp "$CONFIG_DIR/build.json" variant.json
|
||||||
|
env:
|
||||||
|
CONFIG_DIR: ${{ inputs.config }}
|
||||||
|
|
||||||
# We split this out to save the build_* scripts having to do it to make use of `hashFiles` in the cache action
|
# We split this out to save the build_* scripts having to do it to make use of `hashFiles` in the cache action
|
||||||
- name: Generate cache hash files
|
- name: Generate cache hash files
|
||||||
run: |
|
run: |
|
||||||
@@ -170,3 +175,4 @@ jobs:
|
|||||||
electronVersion
|
electronVersion
|
||||||
hakHash
|
hakHash
|
||||||
changelog.Debian
|
changelog.Debian
|
||||||
|
variant.json
|
||||||
|
|||||||
8
.github/workflows/build_windows.yaml
vendored
8
.github/workflows/build_windows.yaml
vendored
@@ -193,8 +193,14 @@ jobs:
|
|||||||
- name: Build App
|
- name: Build App
|
||||||
run: yarn build --publish never -w ${{ steps.config.outputs.build-args }}
|
run: yarn build --publish never -w ${{ steps.config.outputs.build-args }}
|
||||||
env:
|
env:
|
||||||
|
VARIANT_PATH: variant.json
|
||||||
# Only set for Nightly builds
|
# Only set for Nightly builds
|
||||||
ED_NIGHTLY: ${{ inputs.version }}
|
# The windows packager relies on parsing this as semver, so we have to make it look like one.
|
||||||
|
# This will give our update packages really stupid names, but we probably can't change that either
|
||||||
|
# because squirrel windows parses them for the version too. We don't really care: nobody sees them.
|
||||||
|
# We just give the installer a static name, so you'll just see this in the 'about' dialog.
|
||||||
|
# Turns out if you use 0.0.0 here it makes Squirrel windows crash, so we use 0.0.1.
|
||||||
|
VERSION: ${{ inputs.version && format('0.0.1-nightly.{0}', inputs.version) || '' }}
|
||||||
|
|
||||||
- name: Trust eSigner sandbox cert
|
- name: Trust eSigner sandbox cert
|
||||||
if: inputs.sign == ''
|
if: inputs.sign == ''
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
import * as os from "node:os";
|
import * as os from "node:os";
|
||||||
import * as fs from "node:fs";
|
import * as fs from "node:fs";
|
||||||
|
import * as path from "node:path";
|
||||||
import { type Configuration as BaseConfiguration, type Protocol } from "electron-builder";
|
import { type Configuration as BaseConfiguration, type Protocol } from "electron-builder";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This script has different outputs depending on your os platform.
|
* This script has different outputs depending on your os platform.
|
||||||
*
|
*
|
||||||
* On Windows:
|
* On Windows:
|
||||||
* Prefixes the nightly version with `0.0.1-nightly.` as it breaks if it is not semver
|
|
||||||
* Passes $ED_SIGNTOOL_THUMBPRINT and $ED_SIGNTOOL_SUBJECT_NAME to
|
* Passes $ED_SIGNTOOL_THUMBPRINT and $ED_SIGNTOOL_SUBJECT_NAME to
|
||||||
* build.win.signtoolOptions.signingHashAlgorithms and build.win.signtoolOptions.certificateSubjectName respectively if specified.
|
* build.win.signtoolOptions.signingHashAlgorithms and build.win.signtoolOptions.certificateSubjectName respectively if specified.
|
||||||
*
|
*
|
||||||
@@ -16,32 +16,68 @@ import { type Configuration as BaseConfiguration, type Protocol } from "electron
|
|||||||
* Passes $ED_DEBIAN_CHANGELOG to build.deb.fpm if specified
|
* Passes $ED_DEBIAN_CHANGELOG to build.deb.fpm if specified
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const DEFAULT_APP_ID = "im.riot.app";
|
/**
|
||||||
const NIGHTLY_APP_ID = "im.riot.nightly";
|
* Interface describing relevant fields of the package.json file.
|
||||||
const NIGHTLY_DEB_NAME = "element-nightly";
|
*/
|
||||||
|
|
||||||
const DEFAULT_PROTOCOL_SCHEME = "io.element.desktop";
|
|
||||||
const NIGHTLY_PROTOCOL_SCHEME = "io.element.nightly";
|
|
||||||
|
|
||||||
interface Pkg {
|
interface Pkg {
|
||||||
|
version: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Base metadata fields, used in both package.json and the variant configuration.
|
||||||
|
*/
|
||||||
|
interface Metadata {
|
||||||
name: string;
|
name: string;
|
||||||
productName: string;
|
productName: string;
|
||||||
description: string;
|
description: string;
|
||||||
version: string;
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extra metadata fields that are injected into the build to pass to the app at runtime.
|
||||||
|
*/
|
||||||
|
interface ExtraMetadata extends Metadata {
|
||||||
|
electron_appId: string;
|
||||||
|
electron_protocol: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface describing the variant configuration format.
|
||||||
|
*/
|
||||||
|
interface Variant extends Metadata {
|
||||||
|
"appId": string;
|
||||||
|
"linux.executableName"?: string;
|
||||||
|
"linux.deb.name"?: string;
|
||||||
|
"protocols": string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
type Writable<T> = NonNullable<
|
type Writable<T> = NonNullable<
|
||||||
T extends Function ? T : T extends object ? { -readonly [K in keyof T]: Writable<T[K]> } : T
|
T extends Function ? T : T extends object ? { -readonly [K in keyof T]: Writable<T[K]> } : T
|
||||||
>;
|
>;
|
||||||
|
|
||||||
const pkg: Pkg = JSON.parse(fs.readFileSync("package.json", "utf8"));
|
// Load the default variant as a base configuration
|
||||||
|
const DEFAULT_VARIANT = path.join("element.io", "release", "build.json");
|
||||||
|
let variant: Variant = JSON.parse(fs.readFileSync(DEFAULT_VARIANT, "utf8"));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If a variant is specified, we will use it to override the build-specific values.
|
||||||
|
* This allows us to have different builds for different purposes (e.g. stable, nightly).
|
||||||
|
*/
|
||||||
|
if (process.env.VARIANT_PATH) {
|
||||||
|
console.log(`Using variant configuration from '${process.env.VARIANT_PATH}':`);
|
||||||
|
variant = {
|
||||||
|
...variant,
|
||||||
|
...JSON.parse(fs.readFileSync(`${process.env.VARIANT_PATH}`, "utf8")),
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
console.warn(`No VARIANT_PATH specified, using default variant configuration '${DEFAULT_VARIANT}':`);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const key in variant) {
|
||||||
|
console.log(`${key}: ${variant[key]}`);
|
||||||
|
}
|
||||||
|
|
||||||
interface Configuration extends BaseConfiguration {
|
interface Configuration extends BaseConfiguration {
|
||||||
extraMetadata: Partial<Pick<Pkg, "version">> &
|
extraMetadata: Partial<Pick<Pkg, "version">> & ExtraMetadata;
|
||||||
Omit<Pkg, "version"> & {
|
|
||||||
electron_appId: string;
|
|
||||||
electron_protocol: string;
|
|
||||||
};
|
|
||||||
linux: BaseConfiguration["linux"];
|
linux: BaseConfiguration["linux"];
|
||||||
win: BaseConfiguration["win"];
|
win: BaseConfiguration["win"];
|
||||||
mac: BaseConfiguration["mac"];
|
mac: BaseConfiguration["mac"];
|
||||||
@@ -58,7 +94,7 @@ const config: Omit<Writable<Configuration>, "electronFuses"> & {
|
|||||||
// Make all fuses required to ensure they are all explicitly specified
|
// Make all fuses required to ensure they are all explicitly specified
|
||||||
electronFuses: Required<Configuration["electronFuses"]>;
|
electronFuses: Required<Configuration["electronFuses"]>;
|
||||||
} = {
|
} = {
|
||||||
appId: DEFAULT_APP_ID,
|
appId: variant.appId,
|
||||||
asarUnpack: "**/*.node",
|
asarUnpack: "**/*.node",
|
||||||
electronFuses: {
|
electronFuses: {
|
||||||
enableCookieEncryption: true,
|
enableCookieEncryption: true,
|
||||||
@@ -84,17 +120,17 @@ const config: Omit<Writable<Configuration>, "electronFuses"> & {
|
|||||||
],
|
],
|
||||||
extraResources: ["build/icon.*", "webapp.asar"],
|
extraResources: ["build/icon.*", "webapp.asar"],
|
||||||
extraMetadata: {
|
extraMetadata: {
|
||||||
name: pkg.name,
|
name: variant.name,
|
||||||
productName: pkg.productName,
|
productName: variant.productName,
|
||||||
description: pkg.description,
|
description: variant.description,
|
||||||
electron_appId: DEFAULT_APP_ID,
|
electron_appId: variant.appId,
|
||||||
electron_protocol: DEFAULT_PROTOCOL_SCHEME,
|
electron_protocol: variant.protocols[0],
|
||||||
},
|
},
|
||||||
linux: {
|
linux: {
|
||||||
target: ["tar.gz", "deb"],
|
target: ["tar.gz", "deb"],
|
||||||
category: "Network;InstantMessaging;Chat",
|
category: "Network;InstantMessaging;Chat",
|
||||||
icon: "build/icon.png",
|
icon: "build/icon.png",
|
||||||
executableName: pkg.name, // element-desktop or element-desktop-nightly
|
executableName: variant.name, // element-desktop or element-desktop-nightly
|
||||||
},
|
},
|
||||||
deb: {
|
deb: {
|
||||||
packageCategory: "net",
|
packageCategory: "net",
|
||||||
@@ -140,14 +176,27 @@ const config: Omit<Writable<Configuration>, "electronFuses"> & {
|
|||||||
output: "dist",
|
output: "dist",
|
||||||
},
|
},
|
||||||
protocols: {
|
protocols: {
|
||||||
name: "element",
|
name: variant.productName,
|
||||||
schemes: [DEFAULT_PROTOCOL_SCHEME, "element"],
|
schemes: variant.protocols,
|
||||||
},
|
},
|
||||||
nativeRebuilder: "sequential",
|
nativeRebuilder: "sequential",
|
||||||
nodeGypRebuild: false,
|
nodeGypRebuild: false,
|
||||||
npmRebuild: true,
|
npmRebuild: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allow specifying the version via env var.
|
||||||
|
* If unspecified, it will default to the version in package.json.
|
||||||
|
* @param {string} process.env.VERSION
|
||||||
|
*/
|
||||||
|
if (process.env.VERSION) {
|
||||||
|
config.extraMetadata.version = process.env.VERSION;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (variant["linux.deb.name"]) {
|
||||||
|
config.deb.fpm.push("--name", variant["linux.deb.name"]);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allow specifying windows signing cert via env vars
|
* Allow specifying windows signing cert via env vars
|
||||||
* @param {string} process.env.ED_SIGNTOOL_SUBJECT_NAME
|
* @param {string} process.env.ED_SIGNTOOL_SUBJECT_NAME
|
||||||
@@ -158,33 +207,6 @@ if (process.env.ED_SIGNTOOL_SUBJECT_NAME && process.env.ED_SIGNTOOL_THUMBPRINT)
|
|||||||
config.win.signtoolOptions!.certificateSha1 = process.env.ED_SIGNTOOL_THUMBPRINT;
|
config.win.signtoolOptions!.certificateSha1 = process.env.ED_SIGNTOOL_THUMBPRINT;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Allow specifying nightly version via env var
|
|
||||||
* @param {string} process.env.ED_NIGHTLY
|
|
||||||
*/
|
|
||||||
if (process.env.ED_NIGHTLY) {
|
|
||||||
config.deb.fpm = []; // Clear the fpm as the breaks deb fields don't apply to nightly
|
|
||||||
|
|
||||||
config.appId = config.extraMetadata.electron_appId = NIGHTLY_APP_ID;
|
|
||||||
config.extraMetadata.productName += " Nightly";
|
|
||||||
config.extraMetadata.name += "-nightly";
|
|
||||||
config.extraMetadata.description += " (nightly unstable build)";
|
|
||||||
config.linux.executableName += "-nightly";
|
|
||||||
config.deb.fpm.push("--name", NIGHTLY_DEB_NAME);
|
|
||||||
(config.protocols as Protocol).schemes[0] = config.extraMetadata.electron_protocol = NIGHTLY_PROTOCOL_SCHEME;
|
|
||||||
|
|
||||||
let version = process.env.ED_NIGHTLY;
|
|
||||||
if (os.platform() === "win32") {
|
|
||||||
// The windows packager relies on parsing this as semver, so we have to make it look like one.
|
|
||||||
// This will give our update packages really stupid names, but we probably can't change that either
|
|
||||||
// because squirrel windows parses them for the version too. We don't really care: nobody sees them.
|
|
||||||
// We just give the installer a static name, so you'll just see this in the 'about' dialog.
|
|
||||||
// Turns out if you use 0.0.0 here it makes Squirrel windows crash, so we use 0.0.1.
|
|
||||||
version = "0.0.1-nightly." + version;
|
|
||||||
}
|
|
||||||
config.extraMetadata.version = version;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (os.platform() === "linux") {
|
if (os.platform() === "linux") {
|
||||||
// Electron crashes on debian if there's a space in the path.
|
// Electron crashes on debian if there's a space in the path.
|
||||||
// https://github.com/vector-im/element-web/issues/13171
|
// https://github.com/vector-im/element-web/issues/13171
|
||||||
|
|||||||
9
element.io/nightly/build.json
Normal file
9
element.io/nightly/build.json
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"appId": "im.riot.nightly",
|
||||||
|
"name": "element-desktop-nightly",
|
||||||
|
"productName": "Element Nightly",
|
||||||
|
"description": "Element: the future of secure communication (nightly unstable build)",
|
||||||
|
"protocols": ["io.element.nightly", "element"],
|
||||||
|
"linux.executableName": "element-desktop-nightly",
|
||||||
|
"linux.deb.name": "element-nightly"
|
||||||
|
}
|
||||||
7
element.io/release/build.json
Normal file
7
element.io/release/build.json
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"appId": "im.riot.app",
|
||||||
|
"name": "element-desktop",
|
||||||
|
"productName": "Element",
|
||||||
|
"description": "Element: the future of secure communication",
|
||||||
|
"protocols": ["io.element.desktop", "element"]
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user