From 9df87a56d846d677032d6e56eb0db3820d2db0a0 Mon Sep 17 00:00:00 2001 From: suzhou Date: Wed, 22 Feb 2023 17:50:18 +0800 Subject: [PATCH] feature: patch pkg.branch when needed Signed-off-by: suzhou --- src/dev/build/tasks/create_package_json_task.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/dev/build/tasks/create_package_json_task.ts b/src/dev/build/tasks/create_package_json_task.ts index 8f9b41738eea..2789dfa0233a 100644 --- a/src/dev/build/tasks/create_package_json_task.ts +++ b/src/dev/build/tasks/create_package_json_task.ts @@ -29,6 +29,7 @@ */ import { copyWorkspacePackages } from '@osd/pm'; +import { parse } from 'semver'; import { read, write, Task } from '../lib'; @@ -37,6 +38,16 @@ export const CreatePackageJson: Task = { async run(config, log, build) { const pkg = config.getOpenSearchDashboardsPkg(); + /** + * OpenSearch server has a logic that if the pkg.branch is "main", + * set the docVersion to latest. So here we exclude main. + */ + const semverResult = parse(pkg.version); + const shouldPatch = semverResult && pkg.branch !== 'main'; + const branch = shouldPatch ? `${semverResult.major}.${semverResult.minor}` : pkg.branch; + if (shouldPatch) { + log.info(`Patch branch property: ${branch}`); + } const newPkg = { name: pkg.name, @@ -44,7 +55,7 @@ export const CreatePackageJson: Task = { description: pkg.description, keywords: pkg.keywords, version: config.getBuildVersion(), - branch: pkg.branch, + branch, build: { number: config.getBuildNumber(), sha: config.getBuildSha(),