Skip to content

Commit

Permalink
(feat): Check for existing wrangler installation
Browse files Browse the repository at this point in the history
  • Loading branch information
AdiRishi committed Feb 9, 2024
1 parent e3434a7 commit c97aabc
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import {
setFailed,
setOutput,
} from "@actions/core";
import { getExecOutput } from "@actions/exec";
import semverGt from "semver/functions/gt";
import { exec, execShell } from "./exec";
import { checkWorkingDirectory, semverCompare } from "./utils";
import { getPackageManager } from "./packageManagers";
Expand Down Expand Up @@ -82,6 +84,44 @@ async function installWrangler() {
);
}

startGroup("🔍 Checking for existing Wrangler installation");
let installedVersion = "";
try {
const { stdout } = await getExecOutput(
packageManager.exec,
["wrangler", "--version"],
{
cwd: config["workingDirectory"],
silent: true,
},
);
const versionMatch = stdout.match(/wrangler (\d+\.\d+\.\d+)/);
if (!versionMatch) {
throw new Error(
`Unable to parse Wrangler version from the output: ${stdout}`,
);
}
installedVersion = versionMatch[1];
if (semverGt(config["WRANGLER_VERSION"], installedVersion)) {
info(
`Wrangler version ${installedVersion} is less than required. Installing...`,
true,
);
} else {
info(`✅ Using Wrangler ${installedVersion}`, true);
endGroup();
return;
}
} catch (error) {
debug(`Error checking Wrangler version: ${error}`);
info(
"Wrangler not found or version is not compatible. Installing...",
true,
);
} finally {
endGroup();
}

startGroup("📥 Installing Wrangler");
try {
await exec(
Expand Down

0 comments on commit c97aabc

Please sign in to comment.