MCPcopy Index your code
hub / github.com/coder/coder / downloadCoderVersion

Function downloadCoderVersion

site/e2e/helpers.ts:457–514  ·  view source on GitHub ↗
(
	version: string,
)

Source from the content-addressed store, hash-verified

455 * caches it so subsequent calls are fast.
456 */
457export const downloadCoderVersion = async (
458 version: string,
459): Promise<string> => {
460 let versionNumber = version;
461 if (versionNumber.startsWith("v")) {
462 versionNumber = versionNumber.slice(1);
463 }
464
465 const binaryName = `coder-e2e-${versionNumber}`;
466 const tempDir = "/tmp/coder-e2e-cache";
467 // The install script adds `./bin` automatically to the path :shrug:
468 const binaryPath = path.join(tempDir, "bin", binaryName);
469
470 const exists = await new Promise<boolean>((resolve) => {
471 const cp = spawn(binaryPath, ["version"]);
472 cp.on("close", (code) => {
473 resolve(code === 0);
474 });
475 cp.on("error", () => resolve(false));
476 });
477 if (exists) {
478 return binaryPath;
479 }
480
481 // Run our official install script to install the binary
482 await new Promise<void>((resolve, reject) => {
483 const cp = spawn(
484 path.join(__dirname, "../../install.sh"),
485 [
486 "--version",
487 versionNumber,
488 "--method",
489 "standalone",
490 "--prefix",
491 tempDir,
492 "--binary-name",
493 binaryName,
494 ],
495 {
496 env: {
497 ...process.env,
498 XDG_CACHE_HOME: "/tmp/coder-e2e-cache",
499 TRACE: "1", // tells install.sh to `set -x`, helpful if something goes wrong
500 },
501 },
502 );
503 cp.stderr.on("data", (data) => console.error(data.toString()));
504 cp.stdout.on("data", (data) => console.info(data.toString()));
505 cp.on("close", (code) => {
506 if (code === 0) {
507 resolve();
508 } else {
509 reject(new Error(`install.sh failed with code ${code}`));
510 }
511 });
512 });
513 return binaryPath;
514};

Callers 2

Calls 1

infoMethod · 0.80

Tested by

no test coverage detected