Skip to content

Commit 8166267

Browse files
authored
fix: allow user to define explicit buildNumber in config, useful for fpm --iteration flag (#7075)
1 parent 48cbb12 commit 8166267

File tree

9 files changed

+43
-11
lines changed

9 files changed

+43
-11
lines changed

.changeset/tidy-singers-carry.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"app-builder-lib": minor
3+
"electron-builder": minor
4+
"builder-util": patch
5+
---
6+
7+
Allow explicit `buildNumber` in config. `buildNumber` will take precedence over any environment variables (#6945)

docs/configuration/configuration.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,14 @@ Env file `electron-builder.env` in the current dir ([example](https://github.com
9292
<li>
9393
<p><code id="Configuration-npmRebuild">npmRebuild</code> = <code>true</code> Boolean - Whether to <a href="https://docs.npmjs.com/cli/rebuild">rebuild</a> native dependencies before starting to package the app.</p>
9494
</li>
95+
<li>
96+
<p><code id="Configuration-buildNumber">buildNumber</code> String | “undefined” - The build number. Maps to the <code>--iteration</code> flag for builds using FPM on Linux. If not defined, then it will fallback to <code>BUILD_NUMBER</code> or <code>TRAVIS_BUILD_NUMBER</code> or <code>APPVEYOR_BUILD_NUMBER</code> or <code>CIRCLE_BUILD_NUM</code> or <code>BUILD_BUILDNUMBER</code> or <code>CI_PIPELINE_IID</code> env.</p>
97+
</li>
9598
</ul>
9699
<hr>
97100
<ul>
98101
<li>
99-
<p><code id="Configuration-buildVersion">buildVersion</code> String | “undefined” - The build version. Maps to the <code>CFBundleVersion</code> on macOS, and <code>FileVersion</code> metadata property on Windows. Defaults to the <code>version</code>. If <code>TRAVIS_BUILD_NUMBER</code> or <code>APPVEYOR_BUILD_NUMBER</code> or <code>CIRCLE_BUILD_NUM</code> or <code>BUILD_NUMBER</code> or <code>bamboo.buildNumber</code> or <code>CI_PIPELINE_IID</code> env defined, it will be used as a build version (<code>version.build_number</code>).</p>
102+
<p><code id="Configuration-buildVersion">buildVersion</code> String | “undefined” - The build version. Maps to the <code>CFBundleVersion</code> on macOS, and <code>FileVersion</code> metadata property on Windows. Defaults to the <code>version</code>. If <code>buildVersion</code> is not defined and <code>buildNumber</code> (or one of the <code>buildNumber</code> envs) is defined, it will be used as a build version (<code>version.buildNumber</code>).</p>
100103
</li>
101104
<li>
102105
<p><code id="Configuration-electronCompile">electronCompile</code> Boolean - Whether to use <a href="http://github.com/electron/electron-compile">electron-compile</a> to compile app. Defaults to <code>true</code> if <code>electron-compile</code> in the dependencies. And <code>false</code> if in the <code>devDependencies</code> or doesn’t specified.</p>

packages/app-builder-lib/scheme.json

+8-1
Original file line numberDiff line numberDiff line change
@@ -6315,8 +6315,15 @@
63156315
"description": "Whether to build the application native dependencies from source.",
63166316
"type": "boolean"
63176317
},
6318+
"buildNumber": {
6319+
"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.",
6320+
"type": [
6321+
"null",
6322+
"string"
6323+
]
6324+
},
63186325
"buildVersion": {
6319-
"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`).",
6326+
"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`).",
63206327
"type": [
63216328
"null",
63226329
"string"

packages/app-builder-lib/src/appInfo.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,14 @@ export class AppInfo {
3939
buildVersion = info.config.buildVersion
4040
}
4141

42-
this.buildNumber =
42+
const buildNumberEnvs =
4343
process.env.BUILD_NUMBER ||
4444
process.env.TRAVIS_BUILD_NUMBER ||
4545
process.env.APPVEYOR_BUILD_NUMBER ||
4646
process.env.CIRCLE_BUILD_NUM ||
4747
process.env.BUILD_BUILDNUMBER ||
4848
process.env.CI_PIPELINE_IID
49+
this.buildNumber = info.config.buildNumber || buildNumberEnvs
4950
if (buildVersion == null) {
5051
buildVersion = this.version
5152
if (!isEmptyOrSpaces(this.buildNumber)) {

packages/app-builder-lib/src/configuration.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,15 @@ export interface Configuration extends PlatformSpecificBuildOptions {
129129
*/
130130
readonly npmRebuild?: boolean
131131

132+
/**
133+
* The build number. Maps to the `--iteration` flag for builds using FPM on Linux.
134+
* 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.
135+
*/
136+
readonly buildNumber?: string | null
137+
132138
/**
133139
* The build version. Maps to the `CFBundleVersion` on macOS, and `FileVersion` metadata property on Windows. Defaults to the `version`.
134-
* 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`).
140+
* 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`).
135141
*/
136142
readonly buildVersion?: string | null
137143

packages/app-builder-lib/src/targets/fpm.ts

+11-4
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,17 @@ export default class FpmTarget extends Target {
180180
}
181181
}
182182

183-
use(packager.info.metadata.license, it => args.push("--license", it!))
184-
use(appInfo.buildNumber, it => args.push("--iteration", it!))
185-
186-
use(options.fpm, it => args.push(...(it as any)))
183+
use(packager.info.metadata.license, it => args.push("--license", it))
184+
use(appInfo.buildNumber, it =>
185+
args.push(
186+
"--iteration",
187+
// dashes are not supported for iteration in older versions of fpm
188+
// https://github.com/jordansissel/fpm/issues/1833
189+
it.split("-").join("_")
190+
)
191+
)
192+
193+
use(options.fpm, it => args.push(...it))
187194

188195
args.push(`${appOutDir}/=${installPrefix}/${appInfo.sanitizedProductName}`)
189196
for (const icon of await this.helper.icons) {

packages/app-builder-lib/src/winPackager.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ export class WinPackager extends PlatformPackager<WindowsConfiguration> {
297297
}
298298

299299
use(appInfo.companyName, it => args.push("--set-version-string", "CompanyName", it))
300-
use(this.platformSpecificBuildOptions.legalTrademarks, it => args.push("--set-version-string", "LegalTrademarks", it!))
300+
use(this.platformSpecificBuildOptions.legalTrademarks, it => args.push("--set-version-string", "LegalTrademarks", it))
301301
const iconPath = await this.getIconPath()
302302
use(iconPath, it => {
303303
files.push(it)

packages/builder-util/src/util.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,8 @@ export class ExecError extends Error {
265265
}
266266
}
267267

268-
export function use<T, R>(value: T | null, task: (it: T) => R): R | null {
268+
type Nullish = null | undefined
269+
export function use<T, R>(value: T | Nullish, task: (value: T) => R): R | null {
269270
return value == null ? null : task(value)
270271
}
271272

packages/electron-builder/src/cli/install-app-deps.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export async function installAppDeps(args: any) {
5050
const [appDir, version] = await Promise.all<string>([
5151
computeDefaultAppDirectory(
5252
projectDir,
53-
use(config.directories, it => it!.app)
53+
use(config.directories, it => it.app)
5454
),
5555
getElectronVersion(projectDir, config, packageMetadata),
5656
])

0 commit comments

Comments
 (0)