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

Automate component version badges #2656

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
85 changes: 83 additions & 2 deletions website/lib/changelog/generate-component-changelog-entries.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

import fs from 'fs';
import matter from 'gray-matter';

const readVersionFromPackageJson = (filePath) => {
try {
Expand Down Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

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

Really appreciate the comments!

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 &&
Copy link
Contributor

Choose a reason for hiding this comment

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

Question: going forward, will we still need to manually add the added tag?

Copy link
Member Author

Choose a reason for hiding this comment

The 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.

Copy link
Contributor

Choose a reason for hiding this comment

The 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;
Copy link
Contributor

@dchyun dchyun Jan 22, 2025

Choose a reason for hiding this comment

The 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.

Copy link
Member Author

Choose a reason for hiding this comment

The 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 πŸ€”

Copy link
Member Author

@alex-ju alex-ju Jan 23, 2025

Choose a reason for hiding this comment

The 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) => {
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Member Author

Choose a reason for hiding this comment

The 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!

Copy link
Member Author

Choose a reason for hiding this comment

The 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'
Expand All @@ -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(
Expand All @@ -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);
1 change: 1 addition & 0 deletions website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
"eslint-plugin-prettier": "^5.2.1",
"eslint-plugin-qunit": "^8.1.2",
"fs-extra": "^11.2.0",
"gray-matter": "^4.0.3",
"jsonapi-serializer": "^3.6.9",
"loader.js": "^4.7.0",
"lodash": "^4.17.21",
Expand Down
32 changes: 31 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -16255,6 +16255,18 @@ __metadata:
languageName: node
linkType: hard

"gray-matter@npm:^4.0.3":
version: 4.0.3
resolution: "gray-matter@npm:4.0.3"
dependencies:
js-yaml: "npm:^3.13.1"
kind-of: "npm:^6.0.2"
section-matter: "npm:^1.0.0"
strip-bom-string: "npm:^1.0.0"
checksum: 10/9a8f146a7a918d2524d5d60e0b4d45729f5bca54aa41247f971d9e4bc984943fda58159435763d463ec2abc8a0e238e807bd9b05e3a48f4a613a325c9dd5ad0c
languageName: node
linkType: hard

"growly@npm:^1.3.0":
version: 1.3.0
resolution: "growly@npm:1.3.0"
Expand Down Expand Up @@ -18880,7 +18892,7 @@ __metadata:
languageName: node
linkType: hard

"kind-of@npm:^6.0.2":
"kind-of@npm:^6.0.0, kind-of@npm:^6.0.2":
version: 6.0.3
resolution: "kind-of@npm:6.0.3"
checksum: 10/5873d303fb36aad875b7538798867da2ae5c9e328d67194b0162a3659a627d22f742fc9c4ae95cd1704132a24b00cae5041fc00c0f6ef937dc17080dc4dbb962
Expand Down Expand Up @@ -24149,6 +24161,16 @@ __metadata:
languageName: node
linkType: hard

"section-matter@npm:^1.0.0":
version: 1.0.0
resolution: "section-matter@npm:1.0.0"
dependencies:
extend-shallow: "npm:^2.0.1"
kind-of: "npm:^6.0.0"
checksum: 10/cedfda3a9238f66942d92531fe043dd134702a462cdc9e254cd6aa418c66ca0d229900e4da78ffd1a07051e7b239251c4dc4748e9d1c76bf41a37bff7a478556
languageName: node
linkType: hard

"select@npm:^1.1.2":
version: 1.1.2
resolution: "select@npm:1.1.2"
Expand Down Expand Up @@ -25279,6 +25301,13 @@ __metadata:
languageName: node
linkType: hard

"strip-bom-string@npm:^1.0.0":
version: 1.0.0
resolution: "strip-bom-string@npm:1.0.0"
checksum: 10/5635a3656d8512a2c194d6c8d5dee7ef0dde6802f7be9413b91e201981ad4132506656d9cf14137f019fd50f0269390d91c7f6a2601b1bee039a4859cfce4934
languageName: node
linkType: hard

"strip-bom@npm:^3.0.0":
version: 3.0.0
resolution: "strip-bom@npm:3.0.0"
Expand Down Expand Up @@ -27562,6 +27591,7 @@ __metadata:
eslint-plugin-prettier: "npm:^5.2.1"
eslint-plugin-qunit: "npm:^8.1.2"
fs-extra: "npm:^11.2.0"
gray-matter: "npm:^4.0.3"
jsonapi-serializer: "npm:^3.6.9"
loader.js: "npm:^4.7.0"
lodash: "npm:^4.17.21"
Expand Down