From 8455d259c0ac3683a14bbe1bcec087c2dc2ab027 Mon Sep 17 00:00:00 2001 From: Radon Rosborough Date: Fri, 1 Jan 2021 00:55:33 -0800 Subject: [PATCH] Attempt to patch more bugs --- tools/generate-build-script.js | 3 +- tools/plan-publish.js | 90 ++++++++++++++++++++-------------- tools/publish.bash | 2 +- 3 files changed, 54 insertions(+), 41 deletions(-) diff --git a/tools/generate-build-script.js b/tools/generate-build-script.js index 7d4479f..3385a3b 100644 --- a/tools/generate-build-script.js +++ b/tools/generate-build-script.js @@ -74,8 +74,7 @@ EOF`); install -d "\${pkg}/opt/riju/langs" cat <<"EOF" > "\${pkg}/opt/riju/langs/${id}.json" ${JSON.stringify(langConfig, null, 2)} -EOF -`); +EOF`); return parts.join("\n\n"); } diff --git a/tools/plan-publish.js b/tools/plan-publish.js index 734be88..ee0a6bb 100644 --- a/tools/plan-publish.js +++ b/tools/plan-publish.js @@ -149,32 +149,14 @@ function printTable(data, headers) { async function main() { const program = new Command(); program.option("--publish", "deploy newly built artifacts"); - program.option("--all", "show also unchanged artifacts"); + program.option("--show-all", "show also unchanged artifacts"); program.option( "--omit-unneeded-downloads", "don't download artifacts unless needed for dependent builds" ); program.parse(process.argv); let plan = await computePlan(); - const filteredPlan = plan.filter( - ({ desired, local, remote }) => desired !== local || desired !== remote - ); - console.log(); - if (filteredPlan.length === 0) { - console.log(`*** NO CHANGES REQUIRED TO ${plan.length} ARTIFACTS ***`); - } else { - console.log( - `*** CHANGES REQUIRED TO ${filteredPlan.length} of ${plan.length} ARTIFACTS ***` - ); - } - console.log(); - if (!program.all) { - plan = filteredPlan; - } - if (plan.length === 0) { - process.exit(0); - } - const tableData = plan.map( + let tableData = plan.map( ({ id, deps, @@ -187,22 +169,25 @@ async function main() { build, upload, }) => { - let action, details, func, couldPrune; + let action, details, func, couldPrune, noop; if (remote === desired && local === desired) { action = "(no action)"; details = desired; func = () => {}; couldPrune = true; + noop = true; } else if (remote === desired && local !== desired) { action = "download remote"; details = `${local} => ${desired}`; func = download; couldPrune = true; + noop = false; } else if (local === desired && remote !== desired) { action = "publish local"; details = `${remote} => ${desired}`; func = upload; couldPrune = false; + noop = false; } else { action = "rebuild and publish"; if (local === remote) { @@ -215,33 +200,62 @@ async function main() { await upload(); }; couldPrune = false; + noop = false; } - return { id, deps, couldPrune, artifact, name, action, details, func }; + return { + id, + deps, + couldPrune, + artifact, + name, + action, + details, + func, + noop, + }; } ); if (program.omitUnneededDownloads) { - // Recall that JavaScript object keys are sorted by insertion - // order. - const index = Object.fromEntries( - tableData.map((datum) => [datum.id, datum]).reverse() - ); - for (const [id, datum] of Object.entries(index)) { - // See if we can prune this step. - if (datum.couldPrune && _.every(datum.deps, index[dep].pruned)) { + for (const datum of [...tableData].reverse()) { + if ( + datum.couldPrune && + _.every( + tableData, + (otherDatum) => + otherDatum.pruned || !otherDatum.deps.includes(datum.id) + ) + ) { datum.pruned = true; - if (!datum.details.startsWith("(")) { - datum.details += " [skipping]"; + if (!datum.noop) { + datum.action += " [skipping]"; + datum.noop = true; } } } } - printTable(tableData, [ - { key: "artifact", title: "Type" }, - { key: "name", title: "Name" }, - { key: "action", title: "Action" }, - { key: "details", title: "Details" }, - ]); console.log(); + const filteredTableData = tableData.filter(({ noop }) => !noop); + if (filteredTableData.length === 0) { + console.log(`*** NO ACTION REQUIRED FOR ${plan.length} ARTIFACTS ***`); + } else { + console.log( + `*** ACTION REQUIRED FOR ${filteredTableData.length} of ${plan.length} ARTIFACTS ***` + ); + } + console.log(); + if (!program.showAll) { + tableData = filteredTableData; + } + if (tableData.length > 0) { + printTable(tableData, [ + { key: "artifact", title: "Type" }, + { key: "name", title: "Name" }, + { key: "action", title: "Action" }, + { key: "details", title: "Details" }, + ]); + console.log(); + } + tableData = filteredTableData; if (program.publish) { for (const { func } of tableData) { await func(); diff --git a/tools/publish.bash b/tools/publish.bash index 0ad8020..c14abe5 100755 --- a/tools/publish.bash +++ b/tools/publish.bash @@ -12,7 +12,7 @@ fi make pull-base scripts -node tools/plan-publish.js --publish --omit-unneeded-downloads +node tools/plan-publish.js --publish --show-all --omit-unneeded-downloads sha="$(git describe --match=always-omit-tag --always --abbrev=40 --dirty)"