Skip to content

Commit

Permalink
Tweak the fixture test for the pre-installed-wrangler test
Browse files Browse the repository at this point in the history
  • Loading branch information
petebacondarwin committed May 3, 2024
1 parent 2523489 commit de01fe0
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 1,279 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,11 @@ jobs:
run: |
cd ./test/pre-installed-wrangler
npm install
pwd
find .
- name: Support pre-installed wrangler
uses: ./
with:
workingDirectory: "./test/pre-installed-wrangler"
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
command: deploy --dry-run
command: action-test
40 changes: 20 additions & 20 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import {
setFailed,
setOutput,
} from "@actions/core";
import { getExecOutput } from "@actions/exec";
import semverEq from "semver/functions/eq";
import { exec, execShell } from "./exec";
import { checkWorkingDirectory, semverCompare } from "./utils";
import { getPackageManager } from "./packageManagers";
import { getExecOutput } from "@actions/exec";

const DEFAULT_WRANGLER_VERSION = "3.13.2";

Expand Down Expand Up @@ -88,39 +88,39 @@ async function installWrangler() {
startGroup("🔍 Checking for existing Wrangler installation");
let installedVersion = "";
try {
await exec("pwd", [], { cwd: config.workingDirectory, silent: false });
const { stdout } = await getExecOutput(
packageManager.exec,
["wrangler", "--version"],
{
cwd: config["workingDirectory"],
silent: true,
silent: config.QUIET_MODE,
},
);
const versionMatch = stdout.match(/wrangler (\d+\.\d+\.\d+)/);
if (!versionMatch) {
throw new Error(
`Unable to parse Wrangler version from the output: ${stdout}`,
);
if (versionMatch) {
installedVersion = versionMatch[1];
}
installedVersion = versionMatch[1];
if (config.didUserProvideWranglerVersion) {
if (semverEq(config.WRANGLER_VERSION, installedVersion)) {
info(`✅ Using Wrangler ${installedVersion}`, true);
endGroup();
return;
if (installedVersion) {
if (config.didUserProvideWranglerVersion) {
if (semverEq(config.WRANGLER_VERSION, installedVersion)) {
info(`✅ Using Wrangler ${installedVersion}`, true);
endGroup();
return;
} else {
info(
`Wrangler version ${installedVersion} is not equal to the required version. Installing...`,
true,
);
}
} else {
info(
`Wrangler version ${installedVersion} is not equal to the required version. Installing...`,
`✅ No wrangler version specified, using pre-installed wrangler version ${installedVersion}`,
true,
);
endGroup();
return;
}
} else {
info(
`✅ No wrangler version specified, using pre-installed wrangler version ${installedVersion}`,
true,
);
endGroup();
return;
}
} catch (error) {
debug(`Error checking Wrangler version: ${error}`);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env node
"use strict";

require("../index");
16 changes: 16 additions & 0 deletions test/pre-installed-wrangler/mock_packages/wrangler/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const args = Array.from(process.argv);
const command = args.pop();
switch (command) {
case "--version":
console.log(
"⛅️ wrangler 1.1.1 (update available 1.2.3)\n" +
"-------------------------------------------------------",
);
process.exit(0);
case "action-test":
console.log("Test successful.");
process.exit(0);
default:
console.error("Invalid command");
process.exit(1);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"private": true,
"name": "wrangler",
"version": "1.1.1",
"main": "index.js",
"bin": "bin/wrangler"
}
Loading

0 comments on commit de01fe0

Please sign in to comment.