Make `execDependencyGraph` labels configurable (#220)
Summary: The `"PASS"` label only makes sense for tests. This commit makes the labels configurable, so that the verbiage can make more sense in other contexts, too. Test Plan: Apply a patch like ```diff diff --git a/config/travis.js b/config/travis.js index af0996b..b0ab3b6 100644 --- a/config/travis.js +++ b/config/travis.js @@ -10,7 +10,11 @@ function main() { process.argv.includes("--full") ? "FULL" : "BASIC"; - execDependencyGraph(makeTasks(mode)).then(({success}) => { + execDependencyGraph(makeTasks(mode), { + taskLaunchLabel: " YO ", + taskPassLabel: "WHEE", + taskFailLabel: "UHOH", + }).then(({success}) => { process.exitCode = success ? 0 : 1; }); } ``` and note that `GITHUB_TOKEN=none yarn travis --full` exhibits all desired messages. wchargin-branch: configurable-labels
This commit is contained in:
parent
2aeeca9a13
commit
4e8d5b574a
|
@ -26,11 +26,33 @@ type TaskResult = {|
|
||||||
type OverallResult = {|
|
type OverallResult = {|
|
||||||
+success: boolean,
|
+success: boolean,
|
||||||
|};
|
|};
|
||||||
|
|
||||||
|
// For best-looking results, the task pass, fail, and launch labels
|
||||||
|
// should all be of the same width. The default options use a
|
||||||
|
// 4-character string for each. Shorter strings with length of the same
|
||||||
|
// parity can be extended by symmetrically adding spaces.
|
||||||
|
type RunOptions = {|
|
||||||
|
+taskPassLabel?: string,
|
||||||
|
+taskFailLabel?: string,
|
||||||
|
+taskLaunchLabel?: string,
|
||||||
|
+overallPassLabel?: string,
|
||||||
|
+overallFailLabel?: string,
|
||||||
|
|};
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
const defaultOptions = {
|
||||||
|
taskPassLabel: "PASS",
|
||||||
|
taskFailLabel: "FAIL",
|
||||||
|
taskLaunchLabel: " GO ",
|
||||||
|
overallPassLabel: "SUCCESS",
|
||||||
|
overallFailLabel: "FAILURE",
|
||||||
|
};
|
||||||
|
|
||||||
exports.default = async function execDependencyGraph(
|
exports.default = async function execDependencyGraph(
|
||||||
tasks /*: $ReadOnlyArray<Task> */
|
tasks /*: $ReadOnlyArray<Task> */,
|
||||||
|
options /*:: ?: RunOptions */
|
||||||
) /*: Promise<OverallResult> */ {
|
) /*: Promise<OverallResult> */ {
|
||||||
|
const fullOptions = {...defaultOptions, ...(options || {})};
|
||||||
const tasksById /*: {[TaskId]: Task} */ = {};
|
const tasksById /*: {[TaskId]: Task} */ = {};
|
||||||
tasks.forEach((task) => {
|
tasks.forEach((task) => {
|
||||||
if (tasksById[task.id] !== undefined) {
|
if (tasksById[task.id] !== undefined) {
|
||||||
|
@ -43,6 +65,10 @@ exports.default = async function execDependencyGraph(
|
||||||
const tasksInProgress /*: Map<TaskId, Promise<TaskResult>> */ = new Map();
|
const tasksInProgress /*: Map<TaskId, Promise<TaskResult>> */ = new Map();
|
||||||
const remainingTasks /*: Set<TaskId> */ = new Set(Object.keys(tasksById));
|
const remainingTasks /*: Set<TaskId> */ = new Set(Object.keys(tasksById));
|
||||||
|
|
||||||
|
function spacedLabel(rawLabel /*: string */) /*: string */ {
|
||||||
|
return ` ${rawLabel} `;
|
||||||
|
}
|
||||||
|
|
||||||
function spawnTasksWhoseDependenciesHaveCompleted() {
|
function spawnTasksWhoseDependenciesHaveCompleted() {
|
||||||
for (const task of tasks) {
|
for (const task of tasks) {
|
||||||
if (!remainingTasks.has(task.id)) {
|
if (!remainingTasks.has(task.id)) {
|
||||||
|
@ -53,7 +79,11 @@ exports.default = async function execDependencyGraph(
|
||||||
}
|
}
|
||||||
// Ready to spawn!
|
// Ready to spawn!
|
||||||
remainingTasks.delete(task.id);
|
remainingTasks.delete(task.id);
|
||||||
console.log(chalk.bgBlue.bold.white(" GO ") + " " + task.id);
|
console.log(
|
||||||
|
chalk.bgBlue.bold.white(spacedLabel(fullOptions.taskLaunchLabel)) +
|
||||||
|
" " +
|
||||||
|
task.id
|
||||||
|
);
|
||||||
tasksInProgress.set(task.id, processTask(task));
|
tasksInProgress.set(task.id, processTask(task));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -84,8 +114,8 @@ exports.default = async function execDependencyGraph(
|
||||||
) {
|
) {
|
||||||
const success = result && result.success;
|
const success = result && result.success;
|
||||||
const badge = success
|
const badge = success
|
||||||
? chalk.bgGreen.bold.white(" PASS ")
|
? chalk.bgGreen.bold.white(spacedLabel(fullOptions.taskPassLabel))
|
||||||
: chalk.bgRed.bold.white(" FAIL ");
|
: chalk.bgRed.bold.white(spacedLabel(fullOptions.taskFailLabel));
|
||||||
console.log(`${badge} ${id}`);
|
console.log(`${badge} ${id}`);
|
||||||
|
|
||||||
if (mode === "OVERVIEW" && success) {
|
if (mode === "OVERVIEW" && success) {
|
||||||
|
@ -168,8 +198,8 @@ exports.default = async function execDependencyGraph(
|
||||||
}
|
}
|
||||||
const overallSuccess /*: boolean */ = failedTasks.length === 0;
|
const overallSuccess /*: boolean */ = failedTasks.length === 0;
|
||||||
const overallBadge = overallSuccess
|
const overallBadge = overallSuccess
|
||||||
? chalk.bgGreen.bold.white(" SUCCESS ")
|
? chalk.bgGreen.bold.white(spacedLabel(fullOptions.overallPassLabel))
|
||||||
: chalk.bgRed.bold.white(" FAILURE ");
|
: chalk.bgRed.bold.white(spacedLabel(fullOptions.overallFailLabel));
|
||||||
console.log("Final result: " + overallBadge);
|
console.log("Final result: " + overallBadge);
|
||||||
return Promise.resolve({success: overallSuccess});
|
return Promise.resolve({success: overallSuccess});
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue