Skip to content

Commit

Permalink
feature: patch pkg.branch when needed
Browse files Browse the repository at this point in the history
Signed-off-by: suzhou <suzhou@amazon.com>
  • Loading branch information
SuZhou-Joe committed Feb 22, 2023
1 parent 02e0bc1 commit 9df87a5
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/dev/build/tasks/create_package_json_task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
*/

import { copyWorkspacePackages } from '@osd/pm';
import { parse } from 'semver';

import { read, write, Task } from '../lib';

Expand All @@ -37,14 +38,24 @@ 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,
private: true,
description: pkg.description,
keywords: pkg.keywords,
version: config.getBuildVersion(),
branch: pkg.branch,
branch,
build: {
number: config.getBuildNumber(),
sha: config.getBuildSha(),
Expand Down

0 comments on commit 9df87a5

Please sign in to comment.