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

ci: add workflow file for updating docs in website #258

Merged
merged 15 commits into from
Sep 16, 2024

Conversation

akshatnema
Copy link
Member

@akshatnema akshatnema commented Jul 28, 2024

Description

Draft PR to add github action to the bindings, for updating the docs inside AsyncAPI website.

Related issue(s)
Resolves #251

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Welcome to AsyncAPI. Thanks a lot for creating your first pull request. Please check out our contributors guide useful for opening a pull request.
Keep in mind there are also other channels you can use to interact with AsyncAPI community. For more details check out this issue.

@akshatnema akshatnema changed the title Added workflow file for updating docs in website feat: add workflow file for updating docs in website Jul 28, 2024
@akshatnema akshatnema marked this pull request as ready for review July 29, 2024 17:18
@aeworxet
Copy link

@asyncapi/bounty_team

Copy link
Member

@derberg derberg left a comment

Choose a reason for hiding this comment

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

.github/workflows/update-docs-in-website.yml Show resolved Hide resolved
Comment on lines 63 to 93
async function processMarkdownFiles(folderPath, isRoot = true) {
const items = await fs.readdir(folderPath, { withFileTypes: true });
for (const item of items) {
const fullPath = path.join(folderPath, item.name);
if (item.isDirectory()) {
// Always process subdirectories, mark isRoot as false for recursive calls
await processMarkdownFiles(fullPath, false);
} else if (item.name.endsWith('.md') && !isRoot) { // Skip root level .md files
const baseName = path.basename(fullPath, '.md');
const parentDirName = path.basename(folderPath);
const newFileName = `${parentDirName}.md`;
const newFullPath = path.join(folderPath, newFileName);
await fs.rename(fullPath, newFullPath);

const newData = `---\ntitle: '${parentDirName.charAt(0).toUpperCase() + parentDirName.slice(1)}'\nweight: ${itemIndex}\n---\n\n`;
let existingFileData = await fs.readFile(newFullPath, 'utf8');

existingFileData = existingFileData.replace(/<img\s+src="(?!http)(.*?)"/g, (match, src) => {
// Remove './' prefix from src path and prepend '/img/docs/'
const updatedSrc = src.replace(/^\.\//, '');
return `<img src="/img/docs/${updatedSrc}"`;
});

const updatedContent = newData + existingFileData;
await fs.writeFile(newFullPath, updatedContent);
itemIndex++;
}
}
}

await processMarkdownFiles(rootPath);
Copy link
Member

Choose a reason for hiding this comment

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

what is the reason for wrapping the code in async function that you later trigger anyway?

@derberg
Copy link
Member

derberg commented Aug 20, 2024

lemme know if you need some help

@asyncapi-bot asyncapi-bot added the bounty AsyncAPI Bounty label Aug 21, 2024
@akshatnema
Copy link
Member Author

Hey @derberg this is the test run I did for the above workflow run in the website - asyncapi/website#3179.

Also, PR for adding index.md in the website has been opened - asyncapi/website#3180. Kindly review it.

Copy link
Member

@derberg derberg left a comment

Choose a reason for hiding this comment

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

2 small things

also left comment in asyncapi/website#3180 (comment)

.github/workflows/update-docs-in-website.yml Outdated Show resolved Hide resolved
.github/workflows/update-docs-in-website.yml Outdated Show resolved Hide resolved
@akshatnema
Copy link
Member Author

@derberg Up for review

@@ -37,7 +37,7 @@ jobs:
uses: actions/github-script@v4
with:
script: |
const { writeFile } = require('fs').promises;
const { writeFile } = require('fs').promis;
Copy link
Member

Choose a reason for hiding this comment

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

why promis? should be promises

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for pointing it out. Resolved it.

@derberg derberg changed the title feat: add workflow file for updating docs in website ci: add workflow file for updating docs in website Sep 16, 2024
derberg
derberg previously approved these changes Sep 16, 2024
@derberg derberg merged commit 8ca5689 into asyncapi:master Sep 16, 2024
8 checks passed
@derberg
Copy link
Member

derberg commented Sep 16, 2024

merging, PR opened since July, other code owners could have a look - no need to wait for them as changes to bindings file were purely bug fix to markdown syntax

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bounty AsyncAPI Bounty
Projects
Status: Completed
Development

Successfully merging this pull request may close these issues.

Add automation to push bindings docs to website
4 participants