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

Add downgrade logic for branch in DocLinkService #3483

Merged
Prev Previous commit
Next Next commit
Update src/dev/build/tasks/create_package_json_task.ts
Signed-off-by: suzhou <suzhou@amazon.com>

Co-authored-by: Miki <amoo_miki@yahoo.com>
  • Loading branch information
SuZhou-Joe and AMoo-Miki authored Feb 23, 2023
commit b09c3eb47ea0d1500a66f27953351905e720f8e8
32 changes: 24 additions & 8 deletions src/dev/build/tasks/create_package_json_task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,38 @@ 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.
* OpenSearch server uses the `branch` property from `package.json` to
* build links to the documentation. If set to `main`, it would use `/latest`
* and if not, it would use the `version` to construct URLs.
*/
const semverResult = parse(config.getBuildVersion());
const shouldPatch = semverResult && pkg.branch !== 'main';
const branch = shouldPatch ? `${semverResult.major}.${semverResult.minor}` : pkg.branch;
if (shouldPatch) {
log.info(`Patch branch property: ${branch}`);
const buildVersion = config.getBuildVersion();
let branch;
if (pkg.branch === 'main') {
branch = pkg.branch;
} else {
const parsedBuildVersion = parse(buildVersion);
if (parsedBuildVersion) {
branch = `${parsedBuildVersion.major}.${parsedBuildVersion.minor}`;
log.info(`Updating package.branch to ${branch}`);
} else {
const validDocPathsPattern = /^\d+\.\d+$/;
if (validDocPathsPattern.test(pkg.branch)) {
branch = pkg.branch;
} else {
// package version was not parsable and branch is unusable
throw new Error(
Copy link
Member

Choose a reason for hiding this comment

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

Does this prevent the builds if they pass a non-valid doc paths pattern in the branch in the package?

Copy link
Member Author

@SuZhou-Joe SuZhou-Joe Mar 14, 2023

Choose a reason for hiding this comment

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

Yes, if no version can be specified after so many downgrade logic, we will prevent the build because there will be a doc link error if we continue to build.

`Failed to identify documentation path while generating package.json: encountered invalid build version (${buildVersion}) and branch property (${pkg.branch}).`
);
}
}
}

const newPkg = {
name: pkg.name,
private: true,
description: pkg.description,
keywords: pkg.keywords,
version: config.getBuildVersion(),
version: buildVersion,
branch,
build: {
number: config.getBuildNumber(),
Expand Down