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

build(release-management): fix checklist and OpenAPI spec version bumps #3318

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading