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

[test] Fail the CI when new unexpected files are created #38039

Merged
merged 2 commits into from
Jul 24, 2023
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
14 changes: 7 additions & 7 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ jobs:
steps:
- run:
name: Should not have any git not staged
command: git diff --exit-code
command: git add -A && git diff --exit-code --staged
- run:
name: Check for duplicated packages
command: yarn deduplicate
Expand Down Expand Up @@ -222,35 +222,35 @@ jobs:
command: yarn proptypes
- run:
name: '`yarn proptypes` changes committed?'
command: git diff --exit-code
command: git add -A && git diff --exit-code --staged
- run:
name: 'Write "use client" directive'
command: yarn rsc:build
- run:
name: '`yarn rsc:build` changes detected, "use client" missing from exports'
command: git diff --exit-code
command: git add -A && git diff --exit-code --staged
- run:
name: Generate the documentation
command: yarn docs:api
- run:
name: '`yarn docs:api` changes committed?'
command: git diff --exit-code
command: git add -A && git diff --exit-code --staged
- run:
name: Update the navigation translations
command: yarn docs:i18n
- run:
name: '`yarn docs:i18n` changes committed?'
command: git diff --exit-code
command: git add -A && git diff --exit-code --staged
- run:
name: '`yarn extract-error-codes` changes committed?'
command: |
yarn extract-error-codes
git diff --exit-code
git add -A && git diff --exit-code --staged
- run:
name: '`yarn docs:link-check` changes committed?'
command: |
yarn docs:link-check
git diff --exit-code
git add -A && git diff --exit-code --staged
test_types:
<<: *defaults
resource_class: 'medium+'
Expand Down
74 changes: 39 additions & 35 deletions packages/api-docs-builder/buildApiUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -589,14 +589,47 @@ export function generateBaseUIApiPages() {
) {
const { components, hooks } = markdownHeaders;

const tokens = markdown.pathname.split('/');
const name = tokens[tokens.length - 1];
const importStatement = `docs/data${markdown.pathname}/${name}.md`;
const demosSource = `
import * as React from 'react';
import MarkdownDocs from 'docs/src/modules/components/MarkdownDocsV2';
import AppFrame from 'docs/src/modules/components/AppFrame';
import * as pageProps from '${importStatement}?@mui/markdown';

export default function Page(props) {
const { userLanguage, ...other } = props;
return <MarkdownDocs {...pageProps} {...other} />;
}

Page.getLayout = (page) => {
return <AppFrame>{page}</AppFrame>;
};
`;

const componentPageDirectory = `docs/pages/${productName}-ui/react-${componentName}/`;
if (!fs.existsSync(componentPageDirectory)) {
fs.mkdirSync(componentPageDirectory, { recursive: true });
}
writePrettifiedFile(
path.join(process.cwd(), `${componentPageDirectory}/index.js`),
demosSource,
);

if ((!components || components.length === 0) && (!hooks || hooks.length === 0)) {
// Early return if it's a markdown file without components/hooks.
return;
}

let apiTabImportStatements = '';
let staticProps = 'export const getStaticProps = () => {';
let componentsApiDescriptions = '';
let componentsPageContents = '';
let hooksApiDescriptions = '';
let hooksPageContents = '';

if (components) {
if (components && components.length > 0) {
components.forEach((component: string) => {
const componentNameKebabCase = kebabCase(component);
apiTabImportStatements += `import ${component}ApiJsonPageContent from '../../api/${componentNameKebabCase}.json';`;
Expand All @@ -613,7 +646,7 @@ export function generateBaseUIApiPages() {
});
}

if (hooks) {
if (hooks && hooks.length > 0) {
hooks.forEach((hook: string) => {
const hookNameKebabCase = kebabCase(hook);
apiTabImportStatements += `import ${hook}ApiJsonPageContent from '../../api/${hookNameKebabCase}.json';`;
Expand Down Expand Up @@ -645,25 +678,6 @@ export function generateBaseUIApiPages() {

staticProps += ` },},};};`;

const tokens = markdown.pathname.split('/');
const name = tokens[tokens.length - 1];
const importStatement = `docs/data${markdown.pathname}/${name}.md`;
const demosSource = `
import * as React from 'react';
import MarkdownDocs from 'docs/src/modules/components/MarkdownDocsV2';
import AppFrame from 'docs/src/modules/components/AppFrame';
import * as pageProps from '${importStatement}?@mui/markdown';

export default function Page(props) {
const { userLanguage, ...other } = props;
return <MarkdownDocs {...pageProps} {...other} />;
}

Page.getLayout = (page) => {
return <AppFrame>{page}</AppFrame>;
};
`;

const tabsApiSource = `
import * as React from 'react';
import MarkdownDocs from 'docs/src/modules/components/MarkdownDocsV2';
Expand Down Expand Up @@ -691,24 +705,14 @@ export const getStaticPaths = () => {
${staticProps}
`;

const componentPageDirectory = `docs/pages/${productName}-ui/react-${componentName}/`;
if (!fs.existsSync(componentPageDirectory)) {
fs.mkdirSync(componentPageDirectory, { recursive: true });
}
const demosSourcePath = path.join(process.cwd(), `${componentPageDirectory}/index.js`);
writePrettifiedFile(demosSourcePath, demosSource);

if ((components ?? []).length === 0 && (hooks ?? []).length === 0) {
// Early return if it's a markdown file without components/hooks.
return;
}

const docsTabsPagesDirectory = `${componentPageDirectory}/[docsTab]`;
if (!fs.existsSync(docsTabsPagesDirectory)) {
fs.mkdirSync(docsTabsPagesDirectory, { recursive: true });
}
const tabsApiPath = path.join(process.cwd(), `${docsTabsPagesDirectory}/index.js`);
writePrettifiedFile(tabsApiPath, tabsApiSource);
writePrettifiedFile(
path.join(process.cwd(), `${docsTabsPagesDirectory}/index.js`),
tabsApiSource,
);
}
});
}