-
Notifications
You must be signed in to change notification settings - Fork 44
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
Automate component version badges #2656
base: main
Are you sure you want to change the base?
Changes from 1 commit
e85a5cb
082607c
15e50a9
a10e7cf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
*/ | ||
|
||
import fs from 'fs'; | ||
import matter from 'gray-matter'; | ||
|
||
const readVersionFromPackageJson = (filePath) => { | ||
try { | ||
|
@@ -99,6 +100,75 @@ const updateComponentVersionHistory = (componentChangelogEntries, version) => { | |
}); | ||
}; | ||
|
||
const updateComponentFrontMatter = (componentChangelogEntries, version) => { | ||
Object.keys(componentChangelogEntries).forEach((componentName) => { | ||
const indexPath = `${allComponentsPath[componentName]}/index.md`; | ||
|
||
if (fs.existsSync(indexPath)) { | ||
// Fetch the index markdown file | ||
const indexContent = fs.readFileSync(indexPath, 'utf8'); | ||
|
||
// Parse the index file content | ||
const parsedFrontMatter = matter(indexContent); | ||
|
||
// Update the front matter | ||
if (!parsedFrontMatter.data.status) { | ||
parsedFrontMatter.data.status = {}; | ||
} | ||
if ( | ||
parsedFrontMatter.data.status.added !== version && | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Question: going forward, will we still need to manually add the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. indeed. either add it manually, or change it from Updated to Added where needed. We can try to add some logic there to distinguish additions from updates, but it's not going to be a clean cut and wasn't sure it's worth the effort. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes sense! We add stuff much less often. |
||
parsedFrontMatter.data.status.updated !== version | ||
) { | ||
parsedFrontMatter.data.status.updated = version; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Suggestion] This would defiantly make the implementation more complicated π , and is probably best raised in the doc, but for patch releases do we want to remove all "updated" badges from a previous minor release? Just thinking of the situation where we do a minor release, the badges get added, and then we have some need to do a patch release quickly after and the badges get removed before consumers are really even aware they were there. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a good point. Let me think about it, maybe we can prevent this from code rather than docs π€ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressed this scenario in a10e7cf by only cleaning "added" and "updated" badges on non-patch versions (minors and majors). |
||
} | ||
|
||
// Stringify the updated content | ||
const updatedContent = matter.stringify( | ||
parsedFrontMatter.content, | ||
parsedFrontMatter.data | ||
); | ||
|
||
// Write the updated content back to the index markdown file | ||
fs.writeFileSync(indexPath, updatedContent); | ||
} | ||
}); | ||
}; | ||
|
||
const cleanComponentFrontMatter = (components) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: I think version needs to be added to the args here? Otherwise I don't see where it is defined. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. right, yes, I believe I'm missing the second argument here β will update! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed in 15e50a9 thanks for spotting this! |
||
Object.keys(components).forEach((componentName) => { | ||
const indexPath = `${components[componentName]}/index.md`; | ||
|
||
if (fs.existsSync(indexPath)) { | ||
// Fetch the index markdown file | ||
const indexContent = fs.readFileSync(indexPath, 'utf8'); | ||
|
||
// Parse the index file content | ||
const parsedFrontMatter = matter(indexContent); | ||
|
||
// Clean the front matter status if 'added' or 'updated' are not matching the current version | ||
// Removing the deprecated status will be done manually as we cannot anticipate the removal | ||
if ( | ||
parsedFrontMatter.data.status && | ||
parsedFrontMatter.data.status.added !== version && | ||
parsedFrontMatter.data.status.updated !== version && | ||
(parsedFrontMatter.data.status.added || | ||
parsedFrontMatter.data.status.updated) | ||
) { | ||
delete parsedFrontMatter.data.status; | ||
} | ||
|
||
// Stringify the updated content | ||
const updatedContent = matter.stringify( | ||
parsedFrontMatter.content, | ||
parsedFrontMatter.data | ||
); | ||
|
||
// Write the updated content back to the index markdown file | ||
fs.writeFileSync(indexPath, updatedContent); | ||
} | ||
}); | ||
}; | ||
|
||
// Extract current version | ||
const version = readVersionFromPackageJson( | ||
'../packages/components/package.json' | ||
|
@@ -107,7 +177,12 @@ const version = readVersionFromPackageJson( | |
// Determine component paths | ||
const componentPaths = getComponentPaths('./docs/components'); | ||
const formComponentPaths = getComponentPaths('./docs/components/form'); | ||
const allComponentsPath = { ...componentPaths, ...formComponentPaths }; | ||
const utilityComponentPaths = getComponentPaths('./docs/utilities'); | ||
const allComponentsPath = { | ||
...componentPaths, | ||
...formComponentPaths, | ||
...utilityComponentPaths, | ||
}; | ||
|
||
// Read the main changelog entry for components | ||
const changelogContent = readChangelogContent( | ||
|
@@ -122,5 +197,11 @@ const componentChangelogEntries = extractComponentChangelogEntries( | |
currentVersionContent | ||
); | ||
|
||
// Add changelog entries for each component | ||
// Add changelog entries for each updated component | ||
updateComponentVersionHistory(componentChangelogEntries, version); | ||
|
||
// Clean previous front matter status for all components | ||
cleanComponentFrontMatter(allComponentsPath, version); | ||
|
||
// Update front matter for each updated component | ||
updateComponentFrontMatter(componentChangelogEntries, version); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really appreciate the comments!