Skip to content

Commit

Permalink
build(release-management): fix checklist and OpenAPI spec version bumps
Browse files Browse the repository at this point in the history
1. After this change the steps within the release management documentation should
work without issues.
2. Currently the process is (was) broken due to our reliance on URL references
within the OpenAPI specifications which created a chicken-egg problem with the
release tag issuance and the building of the source code to be released.

This change depends on the other pull requests that are refactoring the cross-package
OpenAPI specification references:

Depends on #3288
Depends on #3315

Signed-off-by: Peter Somogyvari <peter.somogyvari@accenture.com>
  • Loading branch information
petermetz committed Jun 14, 2024
1 parent 5b378bb commit 6bdcedf
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 94 deletions.
5 changes: 3 additions & 2 deletions RELEASE_MANAGEMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ git rebase upstream/main
git push --force-with-lease
git checkout -b release-v1.1.3
yarn run configure
yarn lerna version 1.1.3 --ignore-scripts --conventional-commits --exact --git-remote upstream --message="chore(release): publish %s" --no-push --no-git-tag-version --no-ignore-changes --force-publish
yarn tools:bump-openapi-spec-dep-versions
yarn lerna version 1.1.3 --ignore-scripts --conventional-commits --exact --git-remote upstream --message="chore(release): publish %s" --no-push --no-git-tag-version --no-ignore-changes
yarn tools:bump-openapi-spec-dep-versions --target-version=1.1.3
yarn codegen
yarn build:dev
./tools/weaver-update-version.sh 1.1.3 .
./tools/go-gen-checksum.sh 1.1.3 .
```
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"lint": "yarn run format && yarn run spellcheck",
"format": "eslint '**/*.{js,ts}' --quiet --fix",
"spellcheck": "cspell lint --no-progress \"*/*/src/**/*.{js,ts}\"",
"tsc": "tsc --build --verbose",
"tsc": "NODE_OPTIONS=\"--max_old_space_size=3072\" tsc --build --verbose",
"codegen": "run-s 'codegen:warmup-*' codegen:lerna codegen:cleanup",
"codegen:cleanup": "rm --force --verbose ./openapitools.json",
"codegen:lerna": "lerna run codegen",
Expand Down
93 changes: 2 additions & 91 deletions tools/bump-openapi-spec-dep-versions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { URL } from "url";
import { fileURLToPath } from "url";
import path from "path";
import yargs from "yargs";
Expand All @@ -8,10 +7,7 @@ import { globby, Options as GlobbyOptions } from "globby";
import { RuntimeError } from "run-time-error";
import prettier from "prettier";
import { OpenAPIV3_1 } from "openapi-types";
import { isValidSemVer } from "semver-parser";
import fastSafeStringify from "fast-safe-stringify";

import { hasKey } from "./has-key";
import { getLatestSemVerGitTagV1 } from "./get-latest-sem-ver-git-tag";

const TAG = "[tools/bump-openapi-spec-dep-versions.ts]";
Expand Down Expand Up @@ -99,67 +95,6 @@ async function createRequest(
return req;
}

function traversePojoRefs(
file: string,
newVersion: string,
pojo: unknown,
replacements: ISpecRefReplacementV1[],
propPartPaths: string[],
): ISpecRefReplacementV1[] {
if (!pojo || typeof pojo !== "object") {
throw new RuntimeError(`Expected "pojo" as a Plain Old Javascript Object`);
}
Object.entries(pojo).forEach(([key, oldVal]: [string, unknown]) => {
if (!oldVal) {
return;
} else if (typeof oldVal === "object") {
propPartPaths.push(key);
traversePojoRefs(file, newVersion, oldVal, replacements, propPartPaths);
propPartPaths.pop();
} else if (key === "$ref") {
if (typeof oldVal !== "string") {
throw new RuntimeError(`Expected string value for $ref in ${file}`);
}
if (oldVal.startsWith("#")) {
// skip references that are local, e.g. pointint go a schema component
// within the same openapi.json specification file because these are
// not going to have a git tag in their URLs (because they aren't URLs)
return;
}
if (!hasKey(pojo, "$ref")) {
throw new RuntimeError(`Expected pojo to have a "$pref" property.`);
}

const aUrl = tryParseUrl(oldVal);
const urlPathParts = aUrl.pathname.split("/");

let dirty = false;

urlPathParts.forEach((x, idx) => {
if (isValidSemVer(x) && x !== newVersion) {
dirty = true;
urlPathParts[idx] = newVersion;
console.log(`${TAG} ${file} Swapping "${x}" to "${newVersion}"`);
}
});

if (dirty) {
aUrl.pathname = urlPathParts.join("/");
const newValue = aUrl.toString();
console.log(`${TAG} ${file} Swapping "${oldVal}" to "${newValue}"`);
pojo[key] = newValue;
const propertyPath = ".".concat(propPartPaths.join("."));
replacements.push({
newValue,
oldValue: oldVal,
propertyPath,
});
}
}
});
return replacements;
}

async function bumpOpenApiSpecDepVersionsOneFile(
filePathAbs: string,
filePathRel: string,
Expand All @@ -176,13 +111,7 @@ async function bumpOpenApiSpecDepVersionsOneFile(
openApiJson.info = { title: filePathRel, version: "0.0.0" };
}

const replacements = traversePojoRefs(
filePathRel,
newVersion,
openApiJson,
[],
[],
);
const replacements = [];

if (openApiJson.info.version !== newVersion) {
const oldVersion = openApiJson.info.version;
Expand Down Expand Up @@ -217,24 +146,6 @@ async function bumpOpenApiSpecDepVersionsOneFile(
return replacements;
}

function tryParseUrl(x: unknown): URL {
if (typeof x !== "string") {
throw new RuntimeError(`${TAG} tryParseUrl() expected string input.`);
}
try {
return new URL(x);
} catch (ex) {
console.error(`${TAG} parsing failed for ${x}`, ex);
let innerEx;
if (ex instanceof Error || typeof ex === "string") {
innerEx = ex;
} else {
innerEx = fastSafeStringify(ex);
}
throw new RuntimeError(`${TAG} parsing failed for ${x}`, innerEx);
}
}

export async function bumpOpenApiSpecDepVersions(
req: IBumpOpenAPISpecDepVersionsV1Request,
): Promise<IBumpOpenAPISpecDepVersionsV1Response> {
Expand All @@ -260,7 +171,7 @@ export async function bumpOpenApiSpecDepVersions(
ignore: ["**/node_modules"],
};

const DEFAULT_GLOB = "**/src/main/json/openapi.json";
const DEFAULT_GLOB = "**/src/main/json/openapi.tpl.json";

const oasPaths = await globby(DEFAULT_GLOB, globbyOpts);

Expand Down

0 comments on commit 6bdcedf

Please sign in to comment.