Skip to content

Commit bcde9af

Browse files
authored
Revert "Switch to a build variant config instead of magic env vars (#2498)" (#2520)
1 parent a509579 commit bcde9af

File tree

7 files changed

+43
-83
lines changed

7 files changed

+43
-83
lines changed

.github/workflows/build_linux.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,8 @@ jobs:
145145
- name: Build App
146146
run: yarn build --publish never -l ${{ steps.config.outputs.build-args }}
147147
env:
148-
VARIANT_PATH: variant.json
149148
# Only set for Nightly builds
150-
VERSION: ${{ inputs.version }}
149+
ED_NIGHTLY: ${{ inputs.version }}
151150

152151
- name: Check native libraries
153152
run: |

.github/workflows/build_macos.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,8 @@ jobs:
9696
APPLE_APP_SPECIFIC_PASSWORD: ${{ secrets.APPLE_ID_PASSWORD }}
9797
CSC_KEY_PASSWORD: ${{ secrets.APPLE_CSC_KEY_PASSWORD }}
9898
CSC_LINK: ${{ secrets.APPLE_CSC_LINK }}
99-
VARIANT_PATH: variant.json
10099
# Only set for Nightly builds
101-
VERSION: ${{ inputs.version }}
100+
ED_NIGHTLY: ${{ inputs.version }}
102101

103102
- name: Check app was signed & notarised successfully
104103
if: inputs.sign != ''
@@ -114,7 +113,6 @@ jobs:
114113
yarn build:universal --publish never
115114
env:
116115
CSC_IDENTITY_AUTO_DISCOVERY: false
117-
VARIANT_PATH: variant.json
118116

119117
- name: Generate releases.json
120118
if: inputs.base-url

.github/workflows/build_prepare.yaml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,6 @@ jobs:
8585
if: steps.branch-matching.outcome == 'failure' || steps.branch-matching.outcome == 'skipped'
8686
run: yarn run fetch --noverify -d ${{ inputs.config }} ${{ inputs.version }}
8787

88-
- name: Copy variant config
89-
run: cp "$CONFIG_DIR/build.json" variant.json
90-
env:
91-
CONFIG_DIR: ${{ inputs.config }}
92-
9388
# We split this out to save the build_* scripts having to do it to make use of `hashFiles` in the cache action
9489
- name: Generate cache hash files
9590
run: |
@@ -175,4 +170,3 @@ jobs:
175170
electronVersion
176171
hakHash
177172
changelog.Debian
178-
variant.json

.github/workflows/build_windows.yaml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -193,14 +193,8 @@ jobs:
193193
- name: Build App
194194
run: yarn build --publish never -w ${{ steps.config.outputs.build-args }}
195195
env:
196-
VARIANT_PATH: variant.json
197196
# Only set for Nightly builds
198-
# The windows packager relies on parsing this as semver, so we have to make it look like one.
199-
# This will give our update packages really stupid names, but we probably can't change that either
200-
# because squirrel windows parses them for the version too. We don't really care: nobody sees them.
201-
# We just give the installer a static name, so you'll just see this in the 'about' dialog.
202-
# Turns out if you use 0.0.0 here it makes Squirrel windows crash, so we use 0.0.1.
203-
VERSION: ${{ inputs.version && format('0.0.1-nightly.{0}', inputs.version) || '' }}
197+
ED_NIGHTLY: ${{ inputs.version }}
204198

205199
- name: Trust eSigner sandbox cert
206200
if: inputs.sign == ''

electron-builder.ts

Lines changed: 40 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import * as os from "node:os";
22
import * as fs from "node:fs";
3-
import * as path from "node:path";
43
import { type Configuration as BaseConfiguration, type Protocol } from "electron-builder";
54

65
/**
76
* This script has different outputs depending on your os platform.
87
*
98
* On Windows:
9+
* Prefixes the nightly version with `0.0.1-nightly.` as it breaks if it is not semver
1010
* Passes $ED_SIGNTOOL_THUMBPRINT and $ED_SIGNTOOL_SUBJECT_NAME to
1111
* build.win.signtoolOptions.signingHashAlgorithms and build.win.signtoolOptions.certificateSubjectName respectively if specified.
1212
*
@@ -16,48 +16,25 @@ import { type Configuration as BaseConfiguration, type Protocol } from "electron
1616
* Passes $ED_DEBIAN_CHANGELOG to build.deb.fpm if specified
1717
*/
1818

19-
/**
20-
* Interface describing relevant fields of the package.json file.
21-
*/
19+
const DEFAULT_APP_ID = "im.riot.app";
20+
const NIGHTLY_APP_ID = "im.riot.nightly";
21+
const NIGHTLY_DEB_NAME = "element-nightly";
22+
23+
const DEFAULT_PROTOCOL_SCHEME = "io.element.desktop";
24+
const NIGHTLY_PROTOCOL_SCHEME = "io.element.nightly";
25+
2226
interface Pkg {
2327
name: string;
2428
productName: string;
2529
description: string;
2630
version: string;
2731
}
2832

29-
/**
30-
* Interface describing the variant configuration format.
31-
*/
32-
interface Variant extends Omit<Pkg, "version"> {
33-
"appId": string;
34-
"linux.executableName"?: string;
35-
"linux.deb.name"?: string;
36-
"protocols": string[];
37-
}
38-
3933
type Writable<T> = NonNullable<
4034
T extends Function ? T : T extends object ? { -readonly [K in keyof T]: Writable<T[K]> } : T
4135
>;
4236

43-
// Load the package.json file to get the app metadata
4437
const pkg: Pkg = JSON.parse(fs.readFileSync("package.json", "utf8"));
45-
// Load the default variant as a base configuration
46-
let variant: Variant = {
47-
...pkg,
48-
...JSON.parse(fs.readFileSync(path.join("element.io", "release", "build.json"), "utf8")),
49-
};
50-
51-
/**
52-
* If a variant is specified, we will use it to override the build-specific values.
53-
* This allows us to have different builds for different purposes (e.g. stable, nightly).
54-
*/
55-
if (process.env.VARIANT_PATH) {
56-
variant = {
57-
...variant,
58-
...JSON.parse(fs.readFileSync(`${process.env.VARIANT_PATH}`, "utf8")),
59-
};
60-
}
6138

6239
interface Configuration extends BaseConfiguration {
6340
extraMetadata: Partial<Pick<Pkg, "version">> &
@@ -81,7 +58,7 @@ const config: Omit<Writable<Configuration>, "electronFuses"> & {
8158
// Make all fuses required to ensure they are all explicitly specified
8259
electronFuses: Required<Configuration["electronFuses"]>;
8360
} = {
84-
appId: variant.appId,
61+
appId: DEFAULT_APP_ID,
8562
asarUnpack: "**/*.node",
8663
electronFuses: {
8764
enableCookieEncryption: true,
@@ -110,8 +87,8 @@ const config: Omit<Writable<Configuration>, "electronFuses"> & {
11087
name: pkg.name,
11188
productName: pkg.productName,
11289
description: pkg.description,
113-
electron_appId: variant.appId,
114-
electron_protocol: variant.protocols[0],
90+
electron_appId: DEFAULT_APP_ID,
91+
electron_protocol: DEFAULT_PROTOCOL_SCHEME,
11592
},
11693
linux: {
11794
target: ["tar.gz", "deb"],
@@ -163,27 +140,14 @@ const config: Omit<Writable<Configuration>, "electronFuses"> & {
163140
output: "dist",
164141
},
165142
protocols: {
166-
name: variant.productName,
167-
schemes: variant.protocols,
143+
name: "element",
144+
schemes: [DEFAULT_PROTOCOL_SCHEME, "element"],
168145
},
169146
nativeRebuilder: "sequential",
170147
nodeGypRebuild: false,
171148
npmRebuild: true,
172149
};
173150

174-
/**
175-
* Allow specifying the version via env var.
176-
* If unspecified, it will default to the version in package.json.
177-
* @param {string} process.env.VERSION
178-
*/
179-
if (process.env.VERSION) {
180-
config.extraMetadata.version = process.env.VERSION;
181-
}
182-
183-
if (variant["linux.deb.name"]) {
184-
config.deb.fpm.push("--name", variant["linux.deb.name"]);
185-
}
186-
187151
/**
188152
* Allow specifying windows signing cert via env vars
189153
* @param {string} process.env.ED_SIGNTOOL_SUBJECT_NAME
@@ -194,6 +158,33 @@ if (process.env.ED_SIGNTOOL_SUBJECT_NAME && process.env.ED_SIGNTOOL_THUMBPRINT)
194158
config.win.signtoolOptions!.certificateSha1 = process.env.ED_SIGNTOOL_THUMBPRINT;
195159
}
196160

161+
/**
162+
* Allow specifying nightly version via env var
163+
* @param {string} process.env.ED_NIGHTLY
164+
*/
165+
if (process.env.ED_NIGHTLY) {
166+
config.deb.fpm = []; // Clear the fpm as the breaks deb fields don't apply to nightly
167+
168+
config.appId = config.extraMetadata.electron_appId = NIGHTLY_APP_ID;
169+
config.extraMetadata.productName += " Nightly";
170+
config.extraMetadata.name += "-nightly";
171+
config.extraMetadata.description += " (nightly unstable build)";
172+
config.linux.executableName += "-nightly";
173+
config.deb.fpm.push("--name", NIGHTLY_DEB_NAME);
174+
(config.protocols as Protocol).schemes[0] = config.extraMetadata.electron_protocol = NIGHTLY_PROTOCOL_SCHEME;
175+
176+
let version = process.env.ED_NIGHTLY;
177+
if (os.platform() === "win32") {
178+
// The windows packager relies on parsing this as semver, so we have to make it look like one.
179+
// This will give our update packages really stupid names, but we probably can't change that either
180+
// because squirrel windows parses them for the version too. We don't really care: nobody sees them.
181+
// We just give the installer a static name, so you'll just see this in the 'about' dialog.
182+
// Turns out if you use 0.0.0 here it makes Squirrel windows crash, so we use 0.0.1.
183+
version = "0.0.1-nightly." + version;
184+
}
185+
config.extraMetadata.version = version;
186+
}
187+
197188
if (os.platform() === "linux") {
198189
// Electron crashes on debian if there's a space in the path.
199190
// https://github.com/vector-im/element-web/issues/13171

element.io/nightly/build.json

Lines changed: 0 additions & 9 deletions
This file was deleted.

element.io/release/build.json

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)