feat(openapi-tooling): add breaking changes checks to the verify command
Signed-off-by: aramissennyeydd <aramis.sennyey@doordash.com>
This commit is contained in:
committed by
web-next-automation
parent
66670589d4
commit
665d118422
@@ -168,7 +168,7 @@ Options:
|
||||
-h, --help
|
||||
|
||||
Commands:
|
||||
verify [paths...]
|
||||
verify [options] [paths...]
|
||||
lint [options] [paths...]
|
||||
test [options] [paths...]
|
||||
fuzz [options]
|
||||
@@ -211,6 +211,7 @@ Options:
|
||||
Usage: backstage-repo-tools repo schema openapi verify [options] [paths...]
|
||||
|
||||
Options:
|
||||
--from <ref>
|
||||
-h, --help
|
||||
```
|
||||
|
||||
|
||||
@@ -96,7 +96,11 @@ function registerRepoCommand(program: Command) {
|
||||
openApiCommand
|
||||
.command('verify [paths...]')
|
||||
.description(
|
||||
'Verify that all OpenAPI schemas are valid and have a matching `schemas/openapi.generated.ts` file.',
|
||||
'Verify that all OpenAPI schemas are valid and set up correctly. This also verifies that your API has not changed in a breaking way.',
|
||||
)
|
||||
.option(
|
||||
'--from <ref>',
|
||||
'The base ref to compare against. Defaults to the fork point of the current branch.',
|
||||
)
|
||||
.action(
|
||||
lazy(() =>
|
||||
|
||||
@@ -29,8 +29,10 @@ import {
|
||||
YAML_SCHEMA_PATH,
|
||||
} from '../../../../lib/openapi/constants';
|
||||
import { getPathToOpenApiSpec } from '../../../../lib/openapi/helpers';
|
||||
import { exec } from '../../../../lib/exec';
|
||||
import { OptionValues } from 'commander';
|
||||
|
||||
async function verify(directoryPath: string) {
|
||||
async function verify(directoryPath: string, options: OptionValues) {
|
||||
let openapiPath = '';
|
||||
try {
|
||||
openapiPath = await getPathToOpenApiSpec(directoryPath);
|
||||
@@ -58,10 +60,39 @@ async function verify(directoryPath: string) {
|
||||
`\`${YAML_SCHEMA_PATH}\` and \`${TS_SCHEMA_PATH}\` do not match. Please run \`yarn backstage-repo-tools package schema openapi generate\` from '${path}' to regenerate \`${TS_SCHEMA_PATH}\`.`,
|
||||
);
|
||||
}
|
||||
|
||||
let baseRef = options.from ?? process.env.GITHUB_BASE_REF;
|
||||
if (!baseRef) {
|
||||
const { stdout: branch } = await exec('git merge-base --fork-point HEAD');
|
||||
baseRef = branch.toString().trim();
|
||||
}
|
||||
|
||||
try {
|
||||
const { stdout } = await exec('optic diff', [
|
||||
openapiPath,
|
||||
'--check',
|
||||
'--base',
|
||||
baseRef,
|
||||
]);
|
||||
// Log out the results as this still shows API changes that aren't breakages.
|
||||
console.log(
|
||||
stdout
|
||||
.toString()
|
||||
.split('\n')
|
||||
.filter(e => !e.startsWith('Rerun') && e.trim())
|
||||
.join('\n'),
|
||||
);
|
||||
} catch (err) {
|
||||
err.message = err.stdout;
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
export async function bulkCommand(paths: string[] = []): Promise<void> {
|
||||
const resultsList = await runner(paths, dir => verify(dir));
|
||||
export async function bulkCommand(
|
||||
paths: string[] = [],
|
||||
options: OptionValues,
|
||||
): Promise<void> {
|
||||
const resultsList = await runner(paths, dir => verify(dir, options));
|
||||
|
||||
let failed = false;
|
||||
for (const { relativeDir, resultText } of resultsList) {
|
||||
|
||||
Reference in New Issue
Block a user