kibana/packages/kbn-validate-next-docs-cli/validate_next_docs_cli.ts
Kibana Machine 4c2729fda0
[8.x] [ci] Work around docosaurus errors (#206097) (#206150)
# Backport

This will backport the following commits from `main` to `8.x`:
- [[ci] Work around docosaurus errors
(#206097)](https://github.com/elastic/kibana/pull/206097)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Alex
Szabo","email":"alex.szabo@elastic.co"},"sourceCommit":{"committedDate":"2025-01-09T22:33:30Z","message":"[ci]
Work around docosaurus errors (#206097)\n\n## Summary\nThis workaround
removes the folder that needs to be built differently\nafter cloning the
repos.\n\nSee:
https://github.com/elastic/kibana/issues/206077","sha":"b3b81331b5cc7a52d31ecdaed847b0a03fe48729","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Team:Operations","release_note:skip","v9.0.0","backport:prev-major","ci:build-next-docs"],"title":"[ci]
Work around docosaurus
errors","number":206097,"url":"https://github.com/elastic/kibana/pull/206097","mergeCommit":{"message":"[ci]
Work around docosaurus errors (#206097)\n\n## Summary\nThis workaround
removes the folder that needs to be built differently\nafter cloning the
repos.\n\nSee:
https://github.com/elastic/kibana/issues/206077","sha":"b3b81331b5cc7a52d31ecdaed847b0a03fe48729"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/206097","number":206097,"mergeCommit":{"message":"[ci]
Work around docosaurus errors (#206097)\n\n## Summary\nThis workaround
removes the folder that needs to be built differently\nafter cloning the
repos.\n\nSee:
https://github.com/elastic/kibana/issues/206077","sha":"b3b81331b5cc7a52d31ecdaed847b0a03fe48729"}}]}]
BACKPORT-->

Co-authored-by: Alex Szabo <alex.szabo@elastic.co>
2025-01-10 00:31:36 +00:00

93 lines
3 KiB
TypeScript

/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the "Elastic License
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/
import { run } from '@kbn/dev-cli-runner';
import { createFailError } from '@kbn/dev-cli-errors';
import { REPO_ROOT } from '@kbn/repo-info';
import { Repos } from './repos';
import { Config, Source } from './config';
import { quietFail } from './error';
run(
async ({ log, flagsReader }) => {
const cloneOnly = flagsReader.boolean('clone-only');
const repos = new Repos(log);
const docsRepo = await repos.init('elastic/docs.elastic.dev');
const contentConfig = new Config(docsRepo);
const sources = contentConfig.getSources().filter((s) => s.location !== 'elastic/kibana');
if (sources.some((s) => s.type !== 'github')) {
throw createFailError(
'expected all content.js sources from docs.elastic.dev to have "type: github"'
);
}
const localCloneSources = await Promise.all(
sources.map(async (source): Promise<Source> => {
const repo = await repos.init(source.location);
// TODO: Remove this, once https://github.com/elastic/kibana/issues/206077 is resolved
if (source.location === 'elastic/kibana-team') {
log.info(
'Removing internal.kibana.dev from elastic/kibana-team - see https://github.com/elastic/kibana/issues/206077 for more details.'
);
await repo.run('rm', ['-rf', 'internal.kibana.dev'], { desc: 'rm internal.kibana.dev' });
}
return {
type: 'file',
location: repo.resolve(),
};
})
);
if (cloneOnly) {
log.success('cloned repos');
return;
}
log.info('[docs.elastic.dev] updated sources to point to local repos');
contentConfig.setSources([
...localCloneSources,
{
type: 'file',
location: REPO_ROOT,
},
]);
const showOutput = flagsReader.boolean('debug') || flagsReader.boolean('verbose');
try {
log.info('[docs.elastic.dev] installing deps with yarn');
await docsRepo.run('yarn', [], { desc: 'yarn install', showOutput });
log.info('[docs.elastic.dev] initializing docsmobile');
await docsRepo.run('yarn', ['docsmobile', 'init'], {
desc: 'yarn docsmobile init',
showOutput,
});
log.info('[docs.elastic.dev] building');
await docsRepo.run('yarn', ['build'], { desc: 'yarn build', showOutput });
} catch {
quietFail(`failed to build docs`);
}
log.success('docs built successfully');
},
{
flags: {
boolean: ['clone-only'],
help: `
--clone-only Simply clone the repos, used to populate the worker images
`,
},
}
);