Skip to content
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
11 changes: 6 additions & 5 deletions .buildkite/scripts/steps/checks/capture_oas_snapshot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ source .buildkite/scripts/common/util.sh
.buildkite/scripts/setup_es_snapshot_cache.sh

echo --- Capture OAS snapshot
cmd="node scripts/capture_oas_snapshot \
cmd="node scripts/capture_oas_snapshot\
--include-path /api/status \
--include-path /api/alerting/rule/ \
--include-path /api/alerting/rules \
Expand All @@ -21,9 +21,6 @@ cmd="node scripts/capture_oas_snapshot \
--include-path /api/saved_objects/_export \
--include-path /api/maintenance_window \
--include-path /api/agent_builder"
if is_pr && ! is_auto_commit_disabled; then
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I guess we could avoid the extra cleanup of the --update flag if we just added it here, but thanks for doing that!

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@jloleysens
We could have, that's also a valid option - would you prefer that direction? (are there usecases where we don't want to write the file, just run the generation process?)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@delanni Nope, I think it makes sense to remove it. Just would have reduced the surface area of the change here a little bit :)

cmd="$cmd --update"
fi

if [[ $BUILDKITE_PULL_REQUEST != "false" && "$BUILDKITE_PULL_REQUEST_BASE_BRANCH" != "main" ]] || [[ $BUILDKITE_PULL_REQUEST == "false" && "$BUILDKITE_BRANCH" != "main" ]]; then
cmd="$cmd --no-serverless"
Expand All @@ -40,4 +37,8 @@ retry 5 15 run_check

node ./scripts/validate_oas_docs.js --assert-no-error-increase --skip-printing-issues --update-baseline

check_for_changed_files "capture_oas_snapshot.sh" true
if is_pr && ! is_auto_commit_disabled; then
check_for_changed_files "capture_oas_snapshot.sh" true
else
check_for_changed_files "capture_oas_snapshot.sh" false
fi
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ interface CaptureOasSnapshotArgs {
log: ToolingLog;
buildFlavour: 'serverless' | 'traditional';
outputFile: string;
update: boolean;
filters?: {
pathStartsWith?: string[];
excludePathsMatching?: string[];
Expand All @@ -34,7 +33,6 @@ export async function captureOasSnapshot({
log,
filters = {},
buildFlavour,
update,
outputFile,
}: CaptureOasSnapshotArgs): Promise<void> {
const { excludePathsMatching = [], pathStartsWith } = filters;
Expand Down Expand Up @@ -84,17 +82,9 @@ export async function captureOasSnapshot({
});

log.info(`Recieved OAS, writing to ${outputFile}...`);
if (update) {
await fs.writeFile(outputFile, sortAndPrettyPrint(currentOas));
const { size: sizeBytes } = await fs.stat(outputFile);
log.success(`OAS written to ${outputFile}. File size ~${twoDeci(sizeBytes / MB)} MB.`);
} else {
log.success(
`OAS recieved, not writing to file. Got OAS for ${
Object.keys(currentOas.paths).length
} paths.`
);
}
await fs.writeFile(outputFile, sortAndPrettyPrint(currentOas));
const { size: sizeBytes } = await fs.stat(outputFile);
log.success(`OAS written to ${outputFile}. File size ~${twoDeci(sizeBytes / MB)} MB.`);
} catch (err) {
log.error(`Failed to capture OAS: ${err}`);
throw err;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import path from 'node:path';
import { run } from '@kbn/dev-cli-runner';
import { REPO_ROOT } from '@kbn/repo-info';
import chalk from 'chalk';
import { captureOasSnapshot } from './capture_oas_snapshot';

export const sortAndPrettyPrint = (object: object) => {
Expand All @@ -35,7 +34,6 @@ run(
process.exit(1);
}

const update = flagsReader.boolean('update');
const pathStartsWith = flagsReader.arrayOfStrings('include-path');
const excludePathsMatching = flagsReader.arrayOfStrings('exclude-path') ?? [];

Expand All @@ -46,7 +44,6 @@ run(
buildFlavour: 'traditional',
outputFile: path.resolve(OAS_OUTPUT_DIR, 'bundle.json'),
filters: { pathStartsWith, excludePathsMatching },
update,
});
log.success('Captured OAS for traditional Kibana.');
}
Expand All @@ -58,7 +55,6 @@ run(
buildFlavour: 'serverless',
outputFile: path.resolve(OAS_OUTPUT_DIR, 'bundle.serverless.json'),
filters: { pathStartsWith, excludePathsMatching },
update,
});
log.success('Captured OAS for serverless Kibana.');
}
Expand All @@ -78,7 +74,6 @@ run(
help: `
--include-path Path to include. Path must start with provided value. Can be passed multiple times.
--exclude-path Path to exclude. Path must NOT start with provided value. Can be passed multiple times.
--update Write the current OAS bundles to ${chalk.cyan(OAS_OUTPUT_DIR)}.
--no-serverless Whether to skip OAS for serverless Kibana. Defaults to false.
--no-traditional Whether to skip OAS for traditional Kibana. Defaults to false.
`,
Expand Down