From 6a6c748029edc0a15260204b5a3233f7fce104ce Mon Sep 17 00:00:00 2001 From: Dave Jeffery Date: Fri, 19 Aug 2022 13:04:19 +0100 Subject: [PATCH 1/5] fix: use `buildVersion` not `buildNumber` for fpm `--iteration` flag (#6945) `buildNumber` is not overridable in the config and is provided directly by the CI, this should be `buildVersion` instead. Dashes are not supported for iteration in some versions of fpm, so replace with underscores. https://github.com/jordansissel/fpm/issues/1833 --- packages/app-builder-lib/src/targets/fpm.ts | 15 +++++++++++---- packages/builder-util/src/util.ts | 3 ++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/packages/app-builder-lib/src/targets/fpm.ts b/packages/app-builder-lib/src/targets/fpm.ts index 18e53b75b5..345b1d6e6a 100644 --- a/packages/app-builder-lib/src/targets/fpm.ts +++ b/packages/app-builder-lib/src/targets/fpm.ts @@ -180,10 +180,17 @@ export default class FpmTarget extends Target { } } - use(packager.info.metadata.license, it => args.push("--license", it!)) - use(appInfo.buildNumber, it => args.push("--iteration", it!)) - - use(options.fpm, it => args.push(...(it as any))) + use(packager.info.metadata.license, it => args.push("--license", it)) + use(appInfo.buildVersion, it => + args.push( + "--iteration", + // dashes are not supported for iteration in older versions of fpm + // https://github.com/jordansissel/fpm/issues/1833 + it.split("-").join("_") + ) + ) + + use(options.fpm, it => args.push(...it)) args.push(`${appOutDir}/=${installPrefix}/${appInfo.sanitizedProductName}`) for (const icon of await this.helper.icons) { diff --git a/packages/builder-util/src/util.ts b/packages/builder-util/src/util.ts index ebfbc7575f..d14f42685d 100644 --- a/packages/builder-util/src/util.ts +++ b/packages/builder-util/src/util.ts @@ -265,7 +265,8 @@ export class ExecError extends Error { } } -export function use(value: T | null, task: (it: T) => R): R | null { +type Nullish = null | undefined +export function use(value: T | Nullish, task: (value: T) => R): R | null { return value == null ? null : task(value) } From e7b33019d70f422af26502b86ba9a7297c0b23f2 Mon Sep 17 00:00:00 2001 From: Dave Jeffery Date: Mon, 22 Aug 2022 10:58:54 +0100 Subject: [PATCH 2/5] more lint fixes --- packages/app-builder-lib/src/winPackager.ts | 2 +- packages/electron-builder/src/cli/install-app-deps.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/app-builder-lib/src/winPackager.ts b/packages/app-builder-lib/src/winPackager.ts index 677c50dc83..cb8aebb082 100644 --- a/packages/app-builder-lib/src/winPackager.ts +++ b/packages/app-builder-lib/src/winPackager.ts @@ -297,7 +297,7 @@ export class WinPackager extends PlatformPackager { } use(appInfo.companyName, it => args.push("--set-version-string", "CompanyName", it)) - use(this.platformSpecificBuildOptions.legalTrademarks, it => args.push("--set-version-string", "LegalTrademarks", it!)) + use(this.platformSpecificBuildOptions.legalTrademarks, it => args.push("--set-version-string", "LegalTrademarks", it)) const iconPath = await this.getIconPath() use(iconPath, it => { files.push(it) diff --git a/packages/electron-builder/src/cli/install-app-deps.ts b/packages/electron-builder/src/cli/install-app-deps.ts index 59f510d0b6..13e565e671 100644 --- a/packages/electron-builder/src/cli/install-app-deps.ts +++ b/packages/electron-builder/src/cli/install-app-deps.ts @@ -50,7 +50,7 @@ export async function installAppDeps(args: any) { const [appDir, version] = await Promise.all([ computeDefaultAppDirectory( projectDir, - use(config.directories, it => it!.app) + use(config.directories, it => it.app) ), getElectronVersion(projectDir, config, packageMetadata), ]) From 0da0e9f8c2bd3e6c8ca26bddd10e0c8fc2413296 Mon Sep 17 00:00:00 2001 From: Dave Jeffery Date: Wed, 24 Aug 2022 00:35:55 +0100 Subject: [PATCH 3/5] fix: allow user to define explicit `buildNumber` in config (#6945) explicit `buildNumber` will take precedence over any envs --- packages/app-builder-lib/scheme.json | 9 ++++++++- packages/app-builder-lib/src/appInfo.ts | 3 ++- packages/app-builder-lib/src/configuration.ts | 8 +++++++- packages/app-builder-lib/src/targets/fpm.ts | 2 +- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/packages/app-builder-lib/scheme.json b/packages/app-builder-lib/scheme.json index dbc5d32e20..da77cf3720 100644 --- a/packages/app-builder-lib/scheme.json +++ b/packages/app-builder-lib/scheme.json @@ -6315,8 +6315,15 @@ "description": "Whether to build the application native dependencies from source.", "type": "boolean" }, + "buildNumber": { + "description": "The build number. Maps to the `--iteration` flag for builds using FPM on Linux. If not defined then will fallback to `BUILD_NUMBER` or `TRAVIS_BUILD_NUMBER` or `APPVEYOR_BUILD_NUMBER` or `CIRCLE_BUILD_NUM` or `BUILD_BUILDNUMBER` or `CI_PIPELINE_IID` env.", + "type": [ + "null", + "string" + ] + }, "buildVersion": { - "description": "The build version. Maps to the `CFBundleVersion` on macOS, and `FileVersion` metadata property on Windows. Defaults to the `version`.\nIf `TRAVIS_BUILD_NUMBER` or `APPVEYOR_BUILD_NUMBER` or `CIRCLE_BUILD_NUM` or `BUILD_NUMBER` or `bamboo.buildNumber` or `CI_PIPELINE_IID` env defined, it will be used as a build version (`version.build_number`).", + "description": "The build version. Maps to the `CFBundleVersion` on macOS, and `FileVersion` metadata property on Windows. Defaults to the `version`.\nIf `buildVersion` is not defined and `buildNumber` (or one of the `buildNumber envs) is defined, it will be used as a build version (`version.buildNumber`).", "type": [ "null", "string" diff --git a/packages/app-builder-lib/src/appInfo.ts b/packages/app-builder-lib/src/appInfo.ts index 344494ec5e..d17bbce960 100644 --- a/packages/app-builder-lib/src/appInfo.ts +++ b/packages/app-builder-lib/src/appInfo.ts @@ -39,13 +39,14 @@ export class AppInfo { buildVersion = info.config.buildVersion } - this.buildNumber = + const buildEnvs = process.env.BUILD_NUMBER || process.env.TRAVIS_BUILD_NUMBER || process.env.APPVEYOR_BUILD_NUMBER || process.env.CIRCLE_BUILD_NUM || process.env.BUILD_BUILDNUMBER || process.env.CI_PIPELINE_IID + this.buildNumber = info.config.buildNumber || buildEnvs if (buildVersion == null) { buildVersion = this.version if (!isEmptyOrSpaces(this.buildNumber)) { diff --git a/packages/app-builder-lib/src/configuration.ts b/packages/app-builder-lib/src/configuration.ts index d7efc31210..46f162f7b6 100644 --- a/packages/app-builder-lib/src/configuration.ts +++ b/packages/app-builder-lib/src/configuration.ts @@ -129,9 +129,15 @@ export interface Configuration extends PlatformSpecificBuildOptions { */ readonly npmRebuild?: boolean + /** + * The build number. Maps to the `--iteration` flag for builds using FPM on Linux. + * If not defined then will fallback to `BUILD_NUMBER` or `TRAVIS_BUILD_NUMBER` or `APPVEYOR_BUILD_NUMBER` or `CIRCLE_BUILD_NUM` or `BUILD_BUILDNUMBER` or `CI_PIPELINE_IID` env. + */ + readonly buildNumber?: string | null + /** * The build version. Maps to the `CFBundleVersion` on macOS, and `FileVersion` metadata property on Windows. Defaults to the `version`. - * If `TRAVIS_BUILD_NUMBER` or `APPVEYOR_BUILD_NUMBER` or `CIRCLE_BUILD_NUM` or `BUILD_NUMBER` or `bamboo.buildNumber` or `CI_PIPELINE_IID` env defined, it will be used as a build version (`version.build_number`). + * If `buildVersion` is not defined and `buildNumber` (or one of the `buildNumber envs) is defined, it will be used as a build version (`version.buildNumber`). */ readonly buildVersion?: string | null diff --git a/packages/app-builder-lib/src/targets/fpm.ts b/packages/app-builder-lib/src/targets/fpm.ts index 345b1d6e6a..1158b51031 100644 --- a/packages/app-builder-lib/src/targets/fpm.ts +++ b/packages/app-builder-lib/src/targets/fpm.ts @@ -181,7 +181,7 @@ export default class FpmTarget extends Target { } use(packager.info.metadata.license, it => args.push("--license", it)) - use(appInfo.buildVersion, it => + use(appInfo.buildNumber, it => args.push( "--iteration", // dashes are not supported for iteration in older versions of fpm From 6c28c0bada52a419232c42dd68efd72bec1a57bd Mon Sep 17 00:00:00 2001 From: Dave Jeffery Date: Wed, 24 Aug 2022 00:37:30 +0100 Subject: [PATCH 4/5] typo: buildEnvs -> buildNumberEnvs --- packages/app-builder-lib/src/appInfo.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/app-builder-lib/src/appInfo.ts b/packages/app-builder-lib/src/appInfo.ts index d17bbce960..e9615015c9 100644 --- a/packages/app-builder-lib/src/appInfo.ts +++ b/packages/app-builder-lib/src/appInfo.ts @@ -39,14 +39,14 @@ export class AppInfo { buildVersion = info.config.buildVersion } - const buildEnvs = + const buildNumberEnvs = process.env.BUILD_NUMBER || process.env.TRAVIS_BUILD_NUMBER || process.env.APPVEYOR_BUILD_NUMBER || process.env.CIRCLE_BUILD_NUM || process.env.BUILD_BUILDNUMBER || process.env.CI_PIPELINE_IID - this.buildNumber = info.config.buildNumber || buildEnvs + this.buildNumber = info.config.buildNumber || buildNumberEnvs if (buildVersion == null) { buildVersion = this.version if (!isEmptyOrSpaces(this.buildNumber)) { From 2ea46e4c434dd1e05c346474871ca29c0e9a9949 Mon Sep 17 00:00:00 2001 From: Dave Jeffery Date: Fri, 26 Aug 2022 00:37:42 +0100 Subject: [PATCH 5/5] update docs and changeset --- .changeset/tidy-singers-carry.md | 7 +++++++ docs/configuration/configuration.md | 5 ++++- packages/app-builder-lib/src/configuration.ts | 4 ++-- 3 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 .changeset/tidy-singers-carry.md diff --git a/.changeset/tidy-singers-carry.md b/.changeset/tidy-singers-carry.md new file mode 100644 index 0000000000..8b12cede99 --- /dev/null +++ b/.changeset/tidy-singers-carry.md @@ -0,0 +1,7 @@ +--- +"app-builder-lib": minor +"electron-builder": minor +"builder-util": patch +--- + +Allow explicit `buildNumber` in config. `buildNumber` will take precedence over any environment variables (#6945) diff --git a/docs/configuration/configuration.md b/docs/configuration/configuration.md index ad076af76e..7840161ede 100644 --- a/docs/configuration/configuration.md +++ b/docs/configuration/configuration.md @@ -92,11 +92,14 @@ Env file `electron-builder.env` in the current dir ([example](https://github.com
  • npmRebuild = true Boolean - Whether to rebuild native dependencies before starting to package the app.

  • +
  • +

    buildNumber String | “undefined” - The build number. Maps to the --iteration flag for builds using FPM on Linux. If not defined, then it will fallback to BUILD_NUMBER or TRAVIS_BUILD_NUMBER or APPVEYOR_BUILD_NUMBER or CIRCLE_BUILD_NUM or BUILD_BUILDNUMBER or CI_PIPELINE_IID env.

    +

    • -

      buildVersion String | “undefined” - The build version. Maps to the CFBundleVersion on macOS, and FileVersion metadata property on Windows. Defaults to the version. If TRAVIS_BUILD_NUMBER or APPVEYOR_BUILD_NUMBER or CIRCLE_BUILD_NUM or BUILD_NUMBER or bamboo.buildNumber or CI_PIPELINE_IID env defined, it will be used as a build version (version.build_number).

      +

      buildVersion String | “undefined” - The build version. Maps to the CFBundleVersion on macOS, and FileVersion metadata property on Windows. Defaults to the version. If buildVersion is not defined and buildNumber (or one of the buildNumber envs) is defined, it will be used as a build version (version.buildNumber).

    • electronCompile Boolean - Whether to use electron-compile to compile app. Defaults to true if electron-compile in the dependencies. And false if in the devDependencies or doesn’t specified.

      diff --git a/packages/app-builder-lib/src/configuration.ts b/packages/app-builder-lib/src/configuration.ts index 46f162f7b6..7171643e5a 100644 --- a/packages/app-builder-lib/src/configuration.ts +++ b/packages/app-builder-lib/src/configuration.ts @@ -131,13 +131,13 @@ export interface Configuration extends PlatformSpecificBuildOptions { /** * The build number. Maps to the `--iteration` flag for builds using FPM on Linux. - * If not defined then will fallback to `BUILD_NUMBER` or `TRAVIS_BUILD_NUMBER` or `APPVEYOR_BUILD_NUMBER` or `CIRCLE_BUILD_NUM` or `BUILD_BUILDNUMBER` or `CI_PIPELINE_IID` env. + * If not defined, then it will fallback to `BUILD_NUMBER` or `TRAVIS_BUILD_NUMBER` or `APPVEYOR_BUILD_NUMBER` or `CIRCLE_BUILD_NUM` or `BUILD_BUILDNUMBER` or `CI_PIPELINE_IID` env. */ readonly buildNumber?: string | null /** * The build version. Maps to the `CFBundleVersion` on macOS, and `FileVersion` metadata property on Windows. Defaults to the `version`. - * If `buildVersion` is not defined and `buildNumber` (or one of the `buildNumber envs) is defined, it will be used as a build version (`version.buildNumber`). + * If `buildVersion` is not defined and `buildNumber` (or one of the `buildNumber` envs) is defined, it will be used as a build version (`version.buildNumber`). */ readonly buildVersion?: string | null