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

enhance(scripts/tag-web-features): print changes as patch code block #26052

Merged
merged 1 commit into from
Feb 28, 2025
Merged
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
44 changes: 41 additions & 3 deletions scripts/tag-web-features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ const main = async () => {
return node;
};

/**
* '{"removed":["foo"],"added":["bar"]}' => ['api.foo', 'api.bar']
*/
const changes: Record<string, string[]> = {};

for (const fp of bcdJsons) {
const src = await fs.readFile(fp, { encoding: 'utf-8' });
const data = JSON.parse(src);
Expand All @@ -83,7 +88,9 @@ const main = async () => {
continue;
}

/* eslint-disable-next-line no-constant-condition */
const added: string[] = [];
const removed: string[] = [];

while (true) {
const index = compat.tags?.findIndex(
(t) =>
Expand All @@ -96,18 +103,29 @@ const main = async () => {

// Remove any other feature tags (besides snapshots)
// Compat keys in multiple web-features features creates ambiguity for some consumers, see https://github.com/web-platform-dx/web-features/issues/1173
console.info(`Removing tag ${compat.tags[index]} from ${key}`);
const tag = compat.tags[index];
if (!process.env.GITHUB_ACTIONS) {
console.info(`Removing tag ${tag} from ${key}`);
}
removed.push(tag);
compat.tags.pop(index);
}

console.info(`Adding tag ${tag} to ${key}`);
if (!process.env.GITHUB_ACTIONS) {
console.info(`Adding tag ${tag} to ${key}`);
}
added.push(tag);

if (compat.tags) {
compat.tags.push(tag);
} else {
compat.tags = [tag];
}
updated = true;

const change = JSON.stringify({ removed, added });
changes[change] ??= [];
changes[change].push(key);
}
if (updated) {
await fs.writeFile(fp, stringifyAndOrderProperties(data) + '\n', {
Expand All @@ -119,6 +137,26 @@ const main = async () => {
for (const [key, feature] of bcdToFeature) {
console.warn('Not migrated:', feature, key);
}

if (process.env.GITHUB_ACTIONS) {
console.log(
'```patch' +
'\n' +
Object.entries(changes)
.sort(([a], [b]) => a.localeCompare(b))
.map(([json, keys]) => [JSON.parse(json), keys])
.map(([{ removed, added }, keys]) =>
keys
.map((key) => `# ${key}`)
.concat(removed.map((tag) => `- ${tag}`))
.concat(added.map((tag) => `+ ${tag}`))
.join('\n'),
)
.join('\n\n') +
'\n' +
'```',
);
}
};

if (esMain(import.meta)) {
Expand Down