From bcde9afce9077e7a54d8d6cb5076db9ec710aa38 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Thu, 28 Aug 2025 11:33:39 +0100 Subject: [PATCH] Revert "Switch to a build variant config instead of magic env vars (#2498)" (#2520) --- .github/workflows/build_linux.yaml | 3 +- .github/workflows/build_macos.yaml | 4 +- .github/workflows/build_prepare.yaml | 6 -- .github/workflows/build_windows.yaml | 8 +-- electron-builder.ts | 89 +++++++++++++--------------- element.io/nightly/build.json | 9 --- element.io/release/build.json | 7 --- 7 files changed, 43 insertions(+), 83 deletions(-) delete mode 100644 element.io/nightly/build.json delete mode 100644 element.io/release/build.json diff --git a/.github/workflows/build_linux.yaml b/.github/workflows/build_linux.yaml index a478ec8090..d4cd54860d 100644 --- a/.github/workflows/build_linux.yaml +++ b/.github/workflows/build_linux.yaml @@ -145,9 +145,8 @@ jobs: - name: Build App run: yarn build --publish never -l ${{ steps.config.outputs.build-args }} env: - VARIANT_PATH: variant.json # Only set for Nightly builds - VERSION: ${{ inputs.version }} + ED_NIGHTLY: ${{ inputs.version }} - name: Check native libraries run: | diff --git a/.github/workflows/build_macos.yaml b/.github/workflows/build_macos.yaml index 892f585643..056505aa5c 100644 --- a/.github/workflows/build_macos.yaml +++ b/.github/workflows/build_macos.yaml @@ -96,9 +96,8 @@ jobs: APPLE_APP_SPECIFIC_PASSWORD: ${{ secrets.APPLE_ID_PASSWORD }} CSC_KEY_PASSWORD: ${{ secrets.APPLE_CSC_KEY_PASSWORD }} CSC_LINK: ${{ secrets.APPLE_CSC_LINK }} - VARIANT_PATH: variant.json # Only set for Nightly builds - VERSION: ${{ inputs.version }} + ED_NIGHTLY: ${{ inputs.version }} - name: Check app was signed & notarised successfully if: inputs.sign != '' @@ -114,7 +113,6 @@ jobs: yarn build:universal --publish never env: CSC_IDENTITY_AUTO_DISCOVERY: false - VARIANT_PATH: variant.json - name: Generate releases.json if: inputs.base-url diff --git a/.github/workflows/build_prepare.yaml b/.github/workflows/build_prepare.yaml index 02fe91c4a9..f72a915f32 100644 --- a/.github/workflows/build_prepare.yaml +++ b/.github/workflows/build_prepare.yaml @@ -85,11 +85,6 @@ jobs: if: steps.branch-matching.outcome == 'failure' || steps.branch-matching.outcome == 'skipped' 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 - name: Generate cache hash files run: | @@ -175,4 +170,3 @@ jobs: electronVersion hakHash changelog.Debian - variant.json diff --git a/.github/workflows/build_windows.yaml b/.github/workflows/build_windows.yaml index cf63bd98b4..7e7251c721 100644 --- a/.github/workflows/build_windows.yaml +++ b/.github/workflows/build_windows.yaml @@ -193,14 +193,8 @@ jobs: - name: Build App run: yarn build --publish never -w ${{ steps.config.outputs.build-args }} env: - VARIANT_PATH: variant.json # Only set for Nightly builds - # 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) || '' }} + ED_NIGHTLY: ${{ inputs.version }} - name: Trust eSigner sandbox cert if: inputs.sign == '' diff --git a/electron-builder.ts b/electron-builder.ts index a802a81ce1..d2fd5370c2 100644 --- a/electron-builder.ts +++ b/electron-builder.ts @@ -1,12 +1,12 @@ import * as os from "node:os"; import * as fs from "node:fs"; -import * as path from "node:path"; import { type Configuration as BaseConfiguration, type Protocol } from "electron-builder"; /** * This script has different outputs depending on your os platform. * * 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 * build.win.signtoolOptions.signingHashAlgorithms and build.win.signtoolOptions.certificateSubjectName respectively if specified. * @@ -16,9 +16,13 @@ import { type Configuration as BaseConfiguration, type Protocol } from "electron * Passes $ED_DEBIAN_CHANGELOG to build.deb.fpm if specified */ -/** - * Interface describing relevant fields of the package.json file. - */ +const DEFAULT_APP_ID = "im.riot.app"; +const NIGHTLY_APP_ID = "im.riot.nightly"; +const NIGHTLY_DEB_NAME = "element-nightly"; + +const DEFAULT_PROTOCOL_SCHEME = "io.element.desktop"; +const NIGHTLY_PROTOCOL_SCHEME = "io.element.nightly"; + interface Pkg { name: string; productName: string; @@ -26,38 +30,11 @@ interface Pkg { version: string; } -/** - * Interface describing the variant configuration format. - */ -interface Variant extends Omit { - "appId": string; - "linux.executableName"?: string; - "linux.deb.name"?: string; - "protocols": string[]; -} - type Writable = NonNullable< T extends Function ? T : T extends object ? { -readonly [K in keyof T]: Writable } : T >; -// Load the package.json file to get the app metadata const pkg: Pkg = JSON.parse(fs.readFileSync("package.json", "utf8")); -// Load the default variant as a base configuration -let variant: Variant = { - ...pkg, - ...JSON.parse(fs.readFileSync(path.join("element.io", "release", "build.json"), "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) { - variant = { - ...variant, - ...JSON.parse(fs.readFileSync(`${process.env.VARIANT_PATH}`, "utf8")), - }; -} interface Configuration extends BaseConfiguration { extraMetadata: Partial> & @@ -81,7 +58,7 @@ const config: Omit, "electronFuses"> & { // Make all fuses required to ensure they are all explicitly specified electronFuses: Required; } = { - appId: variant.appId, + appId: DEFAULT_APP_ID, asarUnpack: "**/*.node", electronFuses: { enableCookieEncryption: true, @@ -110,8 +87,8 @@ const config: Omit, "electronFuses"> & { name: pkg.name, productName: pkg.productName, description: pkg.description, - electron_appId: variant.appId, - electron_protocol: variant.protocols[0], + electron_appId: DEFAULT_APP_ID, + electron_protocol: DEFAULT_PROTOCOL_SCHEME, }, linux: { target: ["tar.gz", "deb"], @@ -163,27 +140,14 @@ const config: Omit, "electronFuses"> & { output: "dist", }, protocols: { - name: variant.productName, - schemes: variant.protocols, + name: "element", + schemes: [DEFAULT_PROTOCOL_SCHEME, "element"], }, nativeRebuilder: "sequential", nodeGypRebuild: false, 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 * @param {string} process.env.ED_SIGNTOOL_SUBJECT_NAME @@ -194,6 +158,33 @@ if (process.env.ED_SIGNTOOL_SUBJECT_NAME && 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") { // Electron crashes on debian if there's a space in the path. // https://github.com/vector-im/element-web/issues/13171 diff --git a/element.io/nightly/build.json b/element.io/nightly/build.json deleted file mode 100644 index 1e028291a4..0000000000 --- a/element.io/nightly/build.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "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" -} diff --git a/element.io/release/build.json b/element.io/release/build.json deleted file mode 100644 index 33b85f7e48..0000000000 --- a/element.io/release/build.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "appId": "im.riot.app", - "name": "element-desktop", - "productName": "Element", - "description": "Element: the future of secure communication", - "protocols": ["io.element.desktop", "element"] -}