From fa567b23598d7f91eab1f2aa182ae8b1e8b50099 Mon Sep 17 00:00:00 2001 From: sharon Date: Fri, 25 Oct 2024 12:23:23 -0400 Subject: [PATCH] Fix version build number in DEB and RPM package info (#5140) ### Summary - addresses https://github.com/posit-dev/positron/issues/5159 - related to #1373 - a follow-up to https://github.com/posit-dev/positron/pull/5072 to fix up the DEB and RPM package info build number ### Changes - The `positronBuildNumber` from the package.json file will always be zero -- instead, we need to use the calculated build number from show-version.js when possible. - We are already using the calculated build number in a few places, but a few were missing, resulting in a build number of zero `0` in the DEB and RPM package info. - The `positronBuildVersion` variable is now in a separate util file, so the value can be used across the gulpfiles. ### QA Notes I've checked the version output of the DEB on Ubuntu 24 (x86_64) and the RPM on Fedora 40 (arm). #### DEB 1. Run `dpkg --info .deb` 2. Confirm the Version field in the output shows `+-` Sample Output: ``` Package: positron Version: 2024.11.0+999-1729709839 ``` #### RPM 1. Run `rpm -qi .rpm` 2. Confirm the Version field in the output shows `+` Sample Output: ``` Name : positron Version : 2024.11.0+999 ``` --- build/gulpfile.reh.js | 3 ++- build/gulpfile.vscode.js | 10 +--------- build/gulpfile.vscode.linux.js | 12 ++++++++---- build/gulpfile.vscode.web.js | 10 +--------- build/utils.js | 19 +++++++++++++++++++ 5 files changed, 31 insertions(+), 23 deletions(-) create mode 100644 build/utils.js diff --git a/build/gulpfile.reh.js b/build/gulpfile.reh.js index d809898b031..28db854083c 100644 --- a/build/gulpfile.reh.js +++ b/build/gulpfile.reh.js @@ -29,7 +29,8 @@ const glob = require('glob'); const { compileBuildTask } = require('./gulpfile.compile'); const { compileExtensionsBuildTask, compileExtensionMediaBuildTask } = require('./gulpfile.extensions'); // --- Start Positron --- -const { vscodeWebEntryPoints, vscodeWebResourceIncludes, createVSCodeWebFileContentMapper, positronBuildNumber } = require('./gulpfile.vscode.web'); +const { vscodeWebEntryPoints, vscodeWebResourceIncludes, createVSCodeWebFileContentMapper } = require('./gulpfile.vscode.web'); +const { positronBuildNumber } = require('./utils'); // --- End Positron --- const cp = require('child_process'); const log = require('fancy-log'); diff --git a/build/gulpfile.vscode.js b/build/gulpfile.vscode.js index 826eea8ee4c..d933164c907 100644 --- a/build/gulpfile.vscode.js +++ b/build/gulpfile.vscode.js @@ -38,9 +38,9 @@ const glob = promisify(require('glob')); const rcedit = promisify(require('rcedit')); // --- Start Positron --- -const child_process = require('child_process'); const fancyLog = require('fancy-log'); const { getQuartoStream } = require('./lib/quarto'); +const { positronBuildNumber } = require('./utils'); // --- End Positron --- // Build @@ -342,14 +342,6 @@ function packageTask(platform, arch, sourceFolderName, destinationFolderName, op // --- Start Positron --- const positronVersion = product.positronVersion; - - // Use the POSITRON_BUILD_NUMBER var if it's set; otherwise, call - // show-version to compute it. - const positronBuildNumber = - process.env.POSITRON_BUILD_NUMBER ?? - child_process.execSync( - `node ${path.dirname(__dirname)}/versions/show-version.js --build`).toString().trim(); - // --- End Positron --- const quality = product.quality; diff --git a/build/gulpfile.vscode.linux.js b/build/gulpfile.vscode.linux.js index ccd36167298..a65e0489528 100644 --- a/build/gulpfile.vscode.linux.js +++ b/build/gulpfile.vscode.linux.js @@ -21,6 +21,10 @@ const path = require('path'); const cp = require('child_process'); const util = require('util'); +// --- Start Positron --- +const { positronBuildNumber } = require('./utils'); +// --- End Positron --- + const exec = util.promisify(cp.exec); const root = path.dirname(__dirname); const commit = getVersion(root); @@ -100,8 +104,8 @@ function prepareDebPackage(arch) { .pipe(replace('@@NAME@@', product.applicationName)) // --- Start Positron --- .pipe(replace('@@VERSION@@', product.version)) - .pipe(replace('@@POSITRONVERSION@@', `${product.positronVersion}+${product.positronBuildNumber}-${linuxPackageRevision}`)) - .pipe(replace('@@BUILDNUMBER@@', product.positronBuildNumber)) + .pipe(replace('@@POSITRONVERSION@@', `${product.positronVersion}+${positronBuildNumber}-${linuxPackageRevision}`)) + .pipe(replace('@@BUILDNUMBER@@', positronBuildNumber)) // --- End Positron --- .pipe(replace('@@ARCHITECTURE@@', debArch)) .pipe(replace('@@DEPENDS@@', dependencies.join(', '))) @@ -226,8 +230,8 @@ function prepareRpmPackage(arch) { .pipe(replace('@@ICON@@', product.linuxIconName)) // --- Start Positron --- .pipe(replace('@@VERSION@@', product.version)) - .pipe(replace('@@POSITRONVERSION@@', `${product.positronVersion}+${product.positronBuildNumber}`)) - .pipe(replace('@@BUILDNUMBER@@', product.positronBuildNumber)) + .pipe(replace('@@POSITRONVERSION@@', `${product.positronVersion}+${positronBuildNumber}`)) + .pipe(replace('@@BUILDNUMBER@@', positronBuildNumber)) // --- End Positron --- .pipe(replace('@@RELEASE@@', linuxPackageRevision)) .pipe(replace('@@ARCHITECTURE@@', rpmArch)) diff --git a/build/gulpfile.vscode.web.js b/build/gulpfile.vscode.web.js index c18944f859c..dab6f93bffd 100644 --- a/build/gulpfile.vscode.web.js +++ b/build/gulpfile.vscode.web.js @@ -24,7 +24,7 @@ const extensions = require('./lib/extensions'); const { isESM } = require('./lib/esm'); // --- Start Positron --- -const child_process = require('child_process'); +const { positronBuildNumber } = require('./utils'); // --- End Positron --- const REPO_ROOT = path.dirname(__dirname); @@ -135,14 +135,6 @@ const vscodeWebEntryPoints = isESM() ? [ buildfile.workbenchWeb() ].flat(); -// --- Begin Positron --- -// Use the POSITRON_BUILD_NUMBER var if it's set; otherwise, call show-version to compute it. -const positronBuildNumber = - process.env.POSITRON_BUILD_NUMBER ?? - child_process.execSync(`node ${REPO_ROOT}/versions/show-version.js --build`).toString().trim(); -exports.positronBuildNumber = positronBuildNumber; -// --- End Positron --- - /** * @param {object} product The parsed product.json file contents */ diff --git a/build/utils.js b/build/utils.js new file mode 100644 index 00000000000..1a4e8ec415c --- /dev/null +++ b/build/utils.js @@ -0,0 +1,19 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (C) 2024 Posit Software, PBC. All rights reserved. + * Licensed under the Elastic License 2.0. See LICENSE.txt for license information. + *--------------------------------------------------------------------------------------------*/ + +'use strict'; + +const child_process = require('child_process'); +const path = require('path'); + +const REPO_ROOT = path.dirname(__dirname); + +/** + * Get the build number for Positron. + */ +const positronBuildNumber = + process.env.POSITRON_BUILD_NUMBER ?? + child_process.execSync(`node ${REPO_ROOT}/versions/show-version.js --build`).toString().trim(); +exports.positronBuildNumber = positronBuildNumber;