Merge pull request #265 from Maximo-Guk/maximo/revert-235

Revert "(feat): Use existing wrangler installation when appropriate #235"
This commit is contained in:
Jacob Hands 2024-05-24 10:15:49 -05:00 committed by GitHub
commit baf8bc61f1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
36 changed files with 37 additions and 328 deletions

View file

@ -0,0 +1,5 @@
---
"wrangler-action": patch
---
Reverts #235 which may have caused the latest version of wrangler to be installed, if no wrangler version was found

View file

@ -29,7 +29,7 @@ jobs:
- name: Only build app - name: Only build app
uses: ./ uses: ./
with: with:
workingDirectory: "./test/only-build" workingDirectory: "./test/base"
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
command: deploy --dry-run command: deploy --dry-run
@ -38,11 +38,12 @@ jobs:
uses: ./ uses: ./
with: with:
quiet: true quiet: true
workingDirectory: "./test/build-quiet" workingDirectory: "./test/base"
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
command: deploy --dry-run command: deploy --dry-run
# START Setup and teardown of Worker Environment Tests
- name: Environment support - name: Environment support
uses: ./ uses: ./
with: with:
@ -51,7 +52,6 @@ jobs:
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
environment: dev environment: dev
preCommands: npx wrangler deploy --env dev # https://github.com/cloudflare/wrangler-action/issues/162 preCommands: npx wrangler deploy --env dev # https://github.com/cloudflare/wrangler-action/issues/162
postCommands: npx wrangler delete --name wrangler-action-dev-environment-test --force
secrets: | secrets: |
SECRET1 SECRET1
SECRET2 SECRET2
@ -59,12 +59,21 @@ jobs:
SECRET1: ${{ secrets.SECRET1 }} SECRET1: ${{ secrets.SECRET1 }}
SECRET2: ${{ secrets.SECRET2 }} SECRET2: ${{ secrets.SECRET2 }}
- name: Clean up Deployed Environment Worker
uses: ./
with:
workingDirectory: "./test/base"
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
command: delete --name wrangler-action-dev-environment-test --force
# END Setup and teardown of Worker Environment Tests
# START Setup and teardown of Workers w/ Secrets Tests # START Setup and teardown of Workers w/ Secrets Tests
- name: Deploy app secrets w/ hardcoded Wrangler v2 - name: Deploy app secrets w/ hardcoded Wrangler v2
uses: ./ uses: ./
with: with:
wranglerVersion: "2.20.0" wranglerVersion: "2.20.0"
workingDirectory: "./test/secrets-v2" workingDirectory: "./test/base"
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
secrets: | secrets: |
@ -75,13 +84,13 @@ jobs:
SECRET2: ${{ secrets.SECRET2 }} SECRET2: ${{ secrets.SECRET2 }}
- name: Health Check Deployed Worker - name: Health Check Deployed Worker
run: node .github/workflows/workerHealthCheck.cjs wrangler-action-test-secrets-v2 run: node .github/workflows/workerHealthCheck.cjs
shell: bash shell: bash
- name: Deploy app secrets w/ default version - name: Deploy app secrets w/ default version
uses: ./ uses: ./
with: with:
workingDirectory: "./test/secrets-default" workingDirectory: "./test/base"
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
secrets: | secrets: |
@ -92,23 +101,22 @@ jobs:
SECRET2: ${{ secrets.SECRET2 }} SECRET2: ${{ secrets.SECRET2 }}
- name: Health Check Deployed Worker - name: Health Check Deployed Worker
run: node .github/workflows/workerHealthCheck.cjs wrangler-action-test-secrets-default run: node .github/workflows/workerHealthCheck.cjs
shell: bash shell: bash
- name: Clean Up Deployed Workers - name: Clean Up Deployed Workers
uses: ./ uses: ./
with: with:
workingDirectory: "./test/secrets-default" workingDirectory: "./test/base"
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
command: delete --name wrangler-action-test-secrets-v2 --force command: delete --name wrangler-action-test --force
postCommands: npx wrangler delete --name wrangler-action-test-secrets-default --force
# END Setup and teardown of Workers w/ Secrets Tests # END Setup and teardown of Workers w/ Secrets Tests
- name: Support packageManager variable - name: Support packageManager variable
uses: ./ uses: ./
with: with:
workingDirectory: "./test/specify-package-manager" workingDirectory: "./test/empty"
packageManager: "npm" packageManager: "npm"
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
@ -117,7 +125,7 @@ jobs:
- name: Support unspecified packageManager with no lockfile - name: Support unspecified packageManager with no lockfile
uses: ./ uses: ./
with: with:
workingDirectory: "./test/unspecified-package-manager" workingDirectory: "./test/empty"
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
command: deploy --dry-run command: deploy --dry-run
@ -151,14 +159,3 @@ jobs:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
command: deploy --dry-run command: deploy --dry-run
- name: Change directory to pre-installed-wrangler and install dependencies
run: |
cd ./test/pre-installed-wrangler
npm install
- name: Support pre-installed wrangler
uses: ./
with:
workingDirectory: "./test/pre-installed-wrangler"
command: action-test

View file

@ -1,7 +1,8 @@
const { execSync } = require("child_process"); const { execSync } = require("child_process");
function workerHealthCheck(workerName) { function workerHealthCheck() {
const url = `https://${workerName}.devprod-testing7928.workers.dev/secret-health-check`; const url =
"https://wrangler-action-test.devprod-testing7928.workers.dev/secret-health-check";
const buffer = execSync(`curl ${url}`); const buffer = execSync(`curl ${url}`);
@ -16,13 +17,4 @@ function workerHealthCheck(workerName) {
return response; return response;
} }
const args = Array.from(process.argv); workerHealthCheck();
const workerName = args.pop();
if (!workerName) {
throw new Error(
"Please provide the worker name as an argument when calling this program.",
);
}
workerHealthCheck(workerName);

View file

@ -10,8 +10,6 @@ import {
setFailed, setFailed,
setOutput, setOutput,
} from "@actions/core"; } from "@actions/core";
import { getExecOutput } from "@actions/exec";
import semverEq from "semver/functions/eq";
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";
@ -23,7 +21,6 @@ const DEFAULT_WRANGLER_VERSION = "3.13.2";
*/ */
const config = { const config = {
WRANGLER_VERSION: getInput("wranglerVersion") || DEFAULT_WRANGLER_VERSION, WRANGLER_VERSION: getInput("wranglerVersion") || DEFAULT_WRANGLER_VERSION,
didUserProvideWranglerVersion: Boolean(getInput("wranglerVersion")),
secrets: getMultilineInput("secrets"), secrets: getMultilineInput("secrets"),
workingDirectory: checkWorkingDirectory(getInput("workingDirectory")), workingDirectory: checkWorkingDirectory(getInput("workingDirectory")),
CLOUDFLARE_API_TOKEN: getInput("apiToken"), CLOUDFLARE_API_TOKEN: getInput("apiToken"),
@ -85,64 +82,6 @@ async function installWrangler() {
); );
} }
startGroup("🔍 Checking for existing Wrangler installation");
let installedVersion = "";
let installedVersionSatisfiesRequirement = false;
try {
const { stdout } = await getExecOutput(
packageManager.exec,
["wrangler", "--version"],
{
cwd: config["workingDirectory"],
silent: config.QUIET_MODE,
},
);
// There are two possible outputs from `wrangler --version`:
// ` ⛅️ wrangler 3.48.0 (update available 3.53.1)`
// and
// `3.48.0`
const versionMatch =
stdout.match(/wrangler (\d+\.\d+\.\d+)/) ??
stdout.match(/^(\d+\.\d+\.\d+)/);
if (versionMatch) {
installedVersion = versionMatch[1];
}
if (config.didUserProvideWranglerVersion) {
installedVersionSatisfiesRequirement = semverEq(
installedVersion,
config["WRANGLER_VERSION"],
);
}
if (!config.didUserProvideWranglerVersion && installedVersion) {
info(
`✅ No wrangler version specified, using pre-installed wrangler version ${installedVersion}`,
true,
);
endGroup();
return;
}
if (
config.didUserProvideWranglerVersion &&
installedVersionSatisfiesRequirement
) {
info(`✅ Using Wrangler ${installedVersion}`, true);
endGroup();
return;
}
info(
"⚠️ Wrangler not found or version is incompatible. Installing...",
true,
);
} catch (error) {
debug(`Error checking Wrangler version: ${error}`);
info(
"⚠️ Wrangler not found or version is incompatible. Installing...",
true,
);
} finally {
endGroup();
}
startGroup("📥 Installing Wrangler"); startGroup("📥 Installing Wrangler");
try { try {
await exec( await exec(

View file

@ -17,6 +17,7 @@ export default {
return new Response("OK"); return new Response("OK");
} }
// @ts-expect-error
return Response.json({ return Response.json({
...request, ...request,
headers: Object.fromEntries(request.headers), headers: Object.fromEntries(request.headers),

View file

@ -1,4 +1,4 @@
name = "wrangler-action-test-only-build" name = "wrangler-action-test"
main = "./index.ts" main = "./index.ts"
compatibility_date = "2023-07-07" compatibility_date = "2023-07-07"
workers_dev = true workers_dev = true

View file

@ -1,4 +0,0 @@
name = "wrangler-action-test-build-quiet"
main = "./index.ts"
compatibility_date = "2023-07-07"
workers_dev = true

View file

@ -17,6 +17,7 @@ export default {
return new Response("OK"); return new Response("OK");
} }
// @ts-expect-error
return Response.json({ return Response.json({
...request, ...request,
headers: Object.fromEntries(request.headers), headers: Object.fromEntries(request.headers),

View file

@ -1,4 +1,4 @@
name = "wrangler-action-test-secrets-v2" name = "wrangler-action-test"
main = "./index.ts" main = "./index.ts"
compatibility_date = "2023-07-07" compatibility_date = "2023-07-07"
workers_dev = true workers_dev = true

View file

@ -12,6 +12,7 @@ export default {
return new Response(`${SECRET1} ${SECRET2}`); return new Response(`${SECRET1} ${SECRET2}`);
} }
// @ts-expect-error
return Response.json({ return Response.json({
...request, ...request,
headers: Object.fromEntries(request.headers), headers: Object.fromEntries(request.headers),

View file

@ -17,6 +17,7 @@ export default {
return new Response("OK"); return new Response("OK");
} }
// @ts-expect-error
return Response.json({ return Response.json({
...request, ...request,
headers: Object.fromEntries(request.headers), headers: Object.fromEntries(request.headers),

View file

@ -1,25 +0,0 @@
type Env = {
SECRET1?: string;
SECRET2?: string;
};
export default {
fetch(request: Request, env: Env) {
const url = new URL(request.url);
if (url.pathname === "/secret-health-check") {
const { SECRET1, SECRET2 } = env;
if (SECRET1 !== "SECRET_1_VALUE" || SECRET2 !== "SECRET_2_VALUE") {
throw new Error("SECRET1 or SECRET2 is not defined");
}
return new Response("OK");
}
return Response.json({
...request,
headers: Object.fromEntries(request.headers),
});
},
};

View file

@ -1,10 +0,0 @@
{
"name": "wrangler-action-test",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "wrangler-action-test"
}
}
}

View file

@ -1,5 +0,0 @@
{
"name": "wrangler-action-test",
"license": "MIT",
"private": true
}

View file

@ -17,6 +17,7 @@ export default {
return new Response("OK"); return new Response("OK");
} }
// @ts-expect-error
return Response.json({ return Response.json({
...request, ...request,
headers: Object.fromEntries(request.headers), headers: Object.fromEntries(request.headers),

View file

@ -1,25 +0,0 @@
type Env = {
SECRET1?: string;
SECRET2?: string;
};
export default {
fetch(request: Request, env: Env) {
const url = new URL(request.url);
if (url.pathname === "/secret-health-check") {
const { SECRET1, SECRET2 } = env;
if (SECRET1 !== "SECRET_1_VALUE" || SECRET2 !== "SECRET_2_VALUE") {
throw new Error("SECRET1 or SECRET2 is not defined");
}
return new Response("OK");
}
return Response.json({
...request,
headers: Object.fromEntries(request.headers),
});
},
};

View file

@ -1,18 +0,0 @@
#!/usr/bin/env node
"use strict";
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)
------------------------------------------`);
process.exit(0);
case "action-test":
console.log("Test successful.");
process.exit(0);
default:
console.error("Invalid command");
process.exit(1);
}

View file

@ -1,7 +0,0 @@
{
"private": true,
"name": "wrangler",
"version": "1.1.1",
"main": "index.js",
"bin": "index.js"
}

View file

@ -1,30 +0,0 @@
{
"name": "wrangler-action-pre-installed-wrangler-test",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "wrangler-action-pre-installed-wrangler-test",
"license": "MIT",
"devDependencies": {
"wrangler": "file:mock_packages/wrangler"
}
},
"mock_packages/wrangler": {
"version": "1.1.1",
"dev": true,
"bin": {
"wrangler": "index.js"
}
},
"node_modules/wrangler": {
"resolved": "mock_packages/wrangler",
"link": true
}
},
"dependencies": {
"wrangler": {
"version": "file:mock_packages/wrangler"
}
}
}

View file

@ -1,8 +0,0 @@
{
"name": "wrangler-action-pre-installed-wrangler-test",
"license": "MIT",
"private": true,
"devDependencies": {
"wrangler": "file:mock_packages/wrangler"
}
}

View file

@ -1,25 +0,0 @@
type Env = {
SECRET1?: string;
SECRET2?: string;
};
export default {
fetch(request: Request, env: Env) {
const url = new URL(request.url);
if (url.pathname === "/secret-health-check") {
const { SECRET1, SECRET2 } = env;
if (SECRET1 !== "SECRET_1_VALUE" || SECRET2 !== "SECRET_2_VALUE") {
throw new Error("SECRET1 or SECRET2 is not defined");
}
return new Response("OK");
}
return Response.json({
...request,
headers: Object.fromEntries(request.headers),
});
},
};

View file

@ -1,10 +0,0 @@
{
"name": "wrangler-action-test",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "wrangler-action-test"
}
}
}

View file

@ -1,5 +0,0 @@
{
"name": "wrangler-action-test",
"license": "MIT",
"private": true
}

View file

@ -1,4 +0,0 @@
name = "wrangler-action-test-secrets-default"
main = "./index.ts"
compatibility_date = "2023-07-07"
workers_dev = true

View file

@ -1,25 +0,0 @@
type Env = {
SECRET1?: string;
SECRET2?: string;
};
export default {
fetch(request: Request, env: Env) {
const url = new URL(request.url);
if (url.pathname === "/secret-health-check") {
const { SECRET1, SECRET2 } = env;
if (SECRET1 !== "SECRET_1_VALUE" || SECRET2 !== "SECRET_2_VALUE") {
throw new Error("SECRET1 or SECRET2 is not defined");
}
return new Response("OK");
}
return Response.json({
...request,
headers: Object.fromEntries(request.headers),
});
},
};

View file

@ -1,10 +0,0 @@
{
"name": "wrangler-action-test",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "wrangler-action-test"
}
}
}

View file

@ -1,5 +0,0 @@
{
"name": "wrangler-action-test",
"license": "MIT",
"private": true
}

View file

@ -1,4 +0,0 @@
name = "wrangler-action-test-specify-package-manager"
main = "./index.ts"
compatibility_date = "2023-07-07"
workers_dev = true

View file

@ -1 +0,0 @@
export default {};

View file

@ -1,5 +0,0 @@
{
"name": "wrangler-action-detect-package-manager-test",
"license": "MIT",
"private": true
}

View file

@ -1,4 +0,0 @@
name = "wrangler-action-test-unspecified-package-manager"
main = "./index.ts"
compatibility_date = "2023-07-07"
workers_dev = true

View file

@ -17,6 +17,7 @@ export default {
return new Response("OK"); return new Response("OK");
} }
// @ts-expect-error
return Response.json({ return Response.json({
...request, ...request,
headers: Object.fromEntries(request.headers), headers: Object.fromEntries(request.headers),