Skip to content

Commit

Permalink
Use progress bar instead of listr2 for release changes (#21632)
Browse files Browse the repository at this point in the history
  • Loading branch information
queengooborg committed Dec 15, 2023
1 parent 8c151ec commit 3e56990
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 49 deletions.
43 changes: 42 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"c8": "~8.0.0",
"chalk": "~5.3.0",
"chalk-template": "~1.1.0",
"cli-progress": "^3.12.0",
"compare-versions": "~6.1.0",
"deep-diff": "~1.0.2",
"es-main": "~1.3.0",
Expand All @@ -63,7 +64,6 @@
"husky": "^8.0.1",
"json-schema-to-typescript": "~13.1.0",
"lint-staged": "^15.0.1",
"listr2": "^8.0.0",
"mocha": "~10.2.0",
"open-cli": "~7.2.0",
"ora": "~7.0.1",
Expand Down
9 changes: 7 additions & 2 deletions scripts/release/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ export const applyMirroring = (feature: WalkOutput): void => {
}
};

/**
* Retrieves the previous version of a browser.
* @param browser The name of the browser.
* @param version The current version of the browser.
* @returns The previous version of the browser.
*/
const getPreviousVersion = (
browser: BrowserName,
version: VersionValue,
Expand All @@ -72,8 +78,7 @@ const getPreviousVersion = (

/**
* Add version_last
* @param {WalkOutput} feature The BCD to transform
* @returns {void}
* @param feature The BCD to transform
*/
export const addVersionLast = (feature: WalkOutput): void => {
for (const [browser, supportData] of Object.entries(
Expand Down
85 changes: 40 additions & 45 deletions scripts/release/changes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export interface Changes {
}

import chalk from 'chalk-template';
import { Listr, ListrTask } from 'listr2';
import cliProgress from 'cli-progress';

import diffFeatures from '../diff-features.js';

Expand Down Expand Up @@ -70,12 +70,10 @@ const pullsFromGitHub = (fromDate: string): FeatureChange[] =>
/**
* Get the diff from the pull request
* @param pull The pull request to test
* @param task The Listr task this is run in
* @returns The changes from the pull request
*/
const getDiff = (
pull: FeatureChange,
task: ListrTask,
): { added: string[]; removed: string[] } => {
let diff;

Expand All @@ -88,13 +86,19 @@ const getDiff = (
}

if (diff.added.length && diff.removed.length) {
task.title += chalk` - {blue ({green ${diff.added.length} added}, {red ${diff.removed.length} removed})}`;
console.log(
chalk` | #${pull.number} - {blue ({green ${diff.added.length} added}, {red ${diff.removed.length} removed})}`,
);
} else if (diff.added.length) {
task.title += chalk` - {blue ({green ${diff.added.length} added})}`;
console.log(
chalk` | #${pull.number} - {blue ({green ${diff.added.length} added})}`,
);
} else if (diff.removed.length) {
task.title += chalk` - {blue ({red ${diff.removed.length} removed})}`;
console.log(
chalk` | #${pull.number} - {blue ({red ${diff.removed.length} removed})}`,
);
} else {
task.title += chalk` - {blue (No feature count changes)}`;
console.log(chalk` | #${pull.number} - {blue (No feature count changes)}`);
}

return diff;
Expand All @@ -106,52 +110,43 @@ const getDiff = (
* @returns The changes from all of the pull requests
*/
export const getChanges = async (date: string): Promise<Changes> => {
const progressBar = new cliProgress.SingleBar(
{},
cliProgress.Presets.shades_classic,
);
const pulls = pullsFromGitHub(date);

const changes: Changes = {
added: [],
removed: [],
};

const tasks: ListrTask[] = pulls.map((pull) => ({
title: `#${pull.number}`,
/**
* Get the diff from the pull request
* @param task The Listr task this is run in
*/
task: (task: ListrTask) => {
const diff = getDiff(pull, task);

changes.added.push(
...diff.added.map((feature) => ({
number: pull.number,
url: pull.url,
feature,
})),
);

changes.removed.push(
...diff.removed.map((feature) => ({
number: pull.number,
url: pull.url,
feature,
})),
);
},
}));

// XXX remove verbose renderer when https://github.com/SamVerschueren/listr/issues/150 fixed
const runner = new Listr(tasks, {
exitOnError: false,
renderer: 'verbose',
concurrent: 1,
rendererOptions: {
collapseSkips: false,
collapseErrors: false,
} as any,
});
progressBar.start(pulls.length, 0);

for (const pull of pulls) {
const diff = getDiff(pull);

changes.added.push(
...diff.added.map((feature) => ({
number: pull.number,
url: pull.url,
feature,
})),
);

changes.removed.push(
...diff.removed.map((feature) => ({
number: pull.number,
url: pull.url,
feature,
})),
);

progressBar.increment();
}

runner.run();
progressBar.stop();
console.log('\n');

changes.added.sort((a, b) => a.feature.localeCompare(b.feature));
changes.removed.sort((a, b) => a.feature.localeCompare(b.feature));
Expand Down

0 comments on commit 3e56990

Please sign in to comment.