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

chore: fix dlint version and sanity check version after download #21058

Merged
merged 4 commits into from
Nov 2, 2023
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
17 changes: 12 additions & 5 deletions tools/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export { delay } from "../test_util/std/async/delay.ts";
// [toolName] --version output
const versions = {
"dprint": "dprint 0.40.0",
"dlint": "dlint 0.52.2",
"dlint": "dlint 0.51.0",
};

export const ROOT_PATH = dirname(dirname(fromFileUrl(import.meta.url)));
Expand Down Expand Up @@ -155,7 +155,7 @@ export async function getPrebuilt(toolName) {
const toolPath = getPrebuiltToolPath(toolName);
try {
await sanityCheckPrebuiltFile(toolPath);
const versionOk = await verifyVersion(toolName);
const versionOk = await verifyVersion(toolName, toolPath);
if (!versionOk) {
throw new Error("Version mismatch");
}
Expand Down Expand Up @@ -185,7 +185,10 @@ export async function downloadPrebuilt(toolName) {
}

const downloadPromise = DOWNLOAD_TASKS[toolName] = deferred();
const spinner = wait("Downloading prebuilt tool: " + toolName).start();
const spinner = wait({
text: "Downloading prebuilt tool: " + toolName,
interval: 1000,
}).start();
const toolPath = getPrebuiltToolPath(toolName);
const tempFile = `${toolPath}.temp`;

Expand All @@ -208,6 +211,11 @@ export async function downloadPrebuilt(toolName) {
await resp.body.pipeTo(file.writable);
spinner.text = `Checking prebuilt tool: ${toolName}`;
await sanityCheckPrebuiltFile(tempFile);
if (!await verifyVersion(toolName, tempFile)) {
throw new Error(
"Didn't get the correct version of the tool after downloading.",
);
}
spinner.text = `Successfully downloaded: ${toolName}`;
await Deno.rename(tempFile, toolPath);
} catch (e) {
Expand All @@ -220,14 +228,13 @@ export async function downloadPrebuilt(toolName) {
downloadPromise.resolve(null);
}

export async function verifyVersion(toolName) {
export async function verifyVersion(toolName, toolPath) {
const requiredVersion = versions[toolName];
if (!requiredVersion) {
return true;
}

try {
const toolPath = getPrebuiltToolPath(toolName);
const cmd = new Deno.Command(toolPath, {
args: ["--version"],
stdout: "piped",
Expand Down