Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use buildVersion not buildNumber for fpm --iteration flag #7075

Merged
merged 5 commits into from Aug 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions .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)
5 changes: 4 additions & 1 deletion docs/configuration/configuration.md
Expand Up @@ -92,11 +92,14 @@ Env file `electron-builder.env` in the current dir ([example](https://github.com
<li>
<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>
</li>
<li>
<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>
</li>
</ul>
<hr>
<ul>
<li>
<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>
<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>
</li>
<li>
<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>
Expand Down
9 changes: 8 additions & 1 deletion packages/app-builder-lib/scheme.json
Expand Up @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion packages/app-builder-lib/src/appInfo.ts
Expand Up @@ -39,13 +39,14 @@ export class AppInfo {
buildVersion = info.config.buildVersion
}

this.buildNumber =
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 || buildNumberEnvs
if (buildVersion == null) {
buildVersion = this.version
if (!isEmptyOrSpaces(this.buildNumber)) {
Expand Down
8 changes: 7 additions & 1 deletion packages/app-builder-lib/src/configuration.ts
Expand Up @@ -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 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 `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

Expand Down
15 changes: 11 additions & 4 deletions packages/app-builder-lib/src/targets/fpm.ts
Expand Up @@ -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.buildNumber, 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("_")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change to it.replaceAll('-', '_')

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replaceAll isn't supported in Node 14.

)
)

use(options.fpm, it => args.push(...it))

args.push(`${appOutDir}/=${installPrefix}/${appInfo.sanitizedProductName}`)
for (const icon of await this.helper.icons) {
Expand Down
2 changes: 1 addition & 1 deletion packages/app-builder-lib/src/winPackager.ts
Expand Up @@ -297,7 +297,7 @@ export class WinPackager extends PlatformPackager<WindowsConfiguration> {
}

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)
Expand Down
3 changes: 2 additions & 1 deletion packages/builder-util/src/util.ts
Expand Up @@ -265,7 +265,8 @@ export class ExecError extends Error {
}
}

export function use<T, R>(value: T | null, task: (it: T) => R): R | null {
type Nullish = null | undefined
export function use<T, R>(value: T | Nullish, task: (value: T) => R): R | null {
return value == null ? null : task(value)
}

Expand Down
2 changes: 1 addition & 1 deletion packages/electron-builder/src/cli/install-app-deps.ts
Expand Up @@ -50,7 +50,7 @@ export async function installAppDeps(args: any) {
const [appDir, version] = await Promise.all<string>([
computeDefaultAppDirectory(
projectDir,
use(config.directories, it => it!.app)
use(config.directories, it => it.app)
),
getElectronVersion(projectDir, config, packageMetadata),
])
Expand Down