mirror of
https://github.com/cloudflare/wrangler-action.git
synced 2024-11-24 19:04:46 +01:00
(feat): Check for existing wrangler installation
This commit is contained in:
parent
ea5754c9ad
commit
f78ca6a656
1 changed files with 40 additions and 0 deletions
40
src/index.ts
40
src/index.ts
|
@ -10,6 +10,8 @@ import {
|
||||||
setFailed,
|
setFailed,
|
||||||
setOutput,
|
setOutput,
|
||||||
} from "@actions/core";
|
} from "@actions/core";
|
||||||
|
import { getExecOutput } from "@actions/exec";
|
||||||
|
import semverGt from "semver/functions/gt";
|
||||||
import { exec, execShell } from "./exec";
|
import { exec, execShell } from "./exec";
|
||||||
import { checkWorkingDirectory, semverCompare } from "./utils";
|
import { checkWorkingDirectory, semverCompare } from "./utils";
|
||||||
import { getPackageManager } from "./packageManagers";
|
import { getPackageManager } from "./packageManagers";
|
||||||
|
@ -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");
|
startGroup("📥 Installing Wrangler");
|
||||||
try {
|
try {
|
||||||
await exec(
|
await exec(
|
||||||
|
|
Loading…
Reference in a new issue