mirror of
https://github.com/cloudflare/wrangler-action.git
synced 2024-11-21 09:33:23 +01:00
Revert "(feat): Use existing wrangler installation when appropriate (#235)"
This reverts commit 0545ad285a
.
This commit is contained in:
parent
8ef515f899
commit
2d275a8f2d
36 changed files with 37 additions and 328 deletions
5
.changeset/friendly-ways-hammer.md
Normal file
5
.changeset/friendly-ways-hammer.md
Normal 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
|
43
.github/workflows/deploy.yml
vendored
43
.github/workflows/deploy.yml
vendored
|
@ -29,7 +29,7 @@ jobs:
|
|||
- name: Only build app
|
||||
uses: ./
|
||||
with:
|
||||
workingDirectory: "./test/only-build"
|
||||
workingDirectory: "./test/base"
|
||||
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||||
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
||||
command: deploy --dry-run
|
||||
|
@ -38,11 +38,12 @@ jobs:
|
|||
uses: ./
|
||||
with:
|
||||
quiet: true
|
||||
workingDirectory: "./test/build-quiet"
|
||||
workingDirectory: "./test/base"
|
||||
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||||
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
||||
command: deploy --dry-run
|
||||
|
||||
# START Setup and teardown of Worker Environment Tests
|
||||
- name: Environment support
|
||||
uses: ./
|
||||
with:
|
||||
|
@ -51,7 +52,6 @@ jobs:
|
|||
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
||||
environment: dev
|
||||
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: |
|
||||
SECRET1
|
||||
SECRET2
|
||||
|
@ -59,12 +59,21 @@ jobs:
|
|||
SECRET1: ${{ secrets.SECRET1 }}
|
||||
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
|
||||
- name: Deploy app secrets w/ hardcoded Wrangler v2
|
||||
uses: ./
|
||||
with:
|
||||
wranglerVersion: "2.20.0"
|
||||
workingDirectory: "./test/secrets-v2"
|
||||
workingDirectory: "./test/base"
|
||||
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||||
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
||||
secrets: |
|
||||
|
@ -75,13 +84,13 @@ jobs:
|
|||
SECRET2: ${{ secrets.SECRET2 }}
|
||||
|
||||
- name: Health Check Deployed Worker
|
||||
run: node .github/workflows/workerHealthCheck.cjs wrangler-action-test-secrets-v2
|
||||
run: node .github/workflows/workerHealthCheck.cjs
|
||||
shell: bash
|
||||
|
||||
- name: Deploy app secrets w/ default version
|
||||
uses: ./
|
||||
with:
|
||||
workingDirectory: "./test/secrets-default"
|
||||
workingDirectory: "./test/base"
|
||||
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||||
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
||||
secrets: |
|
||||
|
@ -92,23 +101,22 @@ jobs:
|
|||
SECRET2: ${{ secrets.SECRET2 }}
|
||||
|
||||
- name: Health Check Deployed Worker
|
||||
run: node .github/workflows/workerHealthCheck.cjs wrangler-action-test-secrets-default
|
||||
run: node .github/workflows/workerHealthCheck.cjs
|
||||
shell: bash
|
||||
|
||||
- name: Clean Up Deployed Workers
|
||||
uses: ./
|
||||
with:
|
||||
workingDirectory: "./test/secrets-default"
|
||||
workingDirectory: "./test/base"
|
||||
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||||
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
||||
command: delete --name wrangler-action-test-secrets-v2 --force
|
||||
postCommands: npx wrangler delete --name wrangler-action-test-secrets-default --force
|
||||
command: delete --name wrangler-action-test --force
|
||||
# END Setup and teardown of Workers w/ Secrets Tests
|
||||
|
||||
- name: Support packageManager variable
|
||||
uses: ./
|
||||
with:
|
||||
workingDirectory: "./test/specify-package-manager"
|
||||
workingDirectory: "./test/empty"
|
||||
packageManager: "npm"
|
||||
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||||
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
||||
|
@ -117,7 +125,7 @@ jobs:
|
|||
- name: Support unspecified packageManager with no lockfile
|
||||
uses: ./
|
||||
with:
|
||||
workingDirectory: "./test/unspecified-package-manager"
|
||||
workingDirectory: "./test/empty"
|
||||
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||||
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
||||
command: deploy --dry-run
|
||||
|
@ -151,14 +159,3 @@ jobs:
|
|||
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||||
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
||||
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
|
||||
|
|
16
.github/workflows/workerHealthCheck.cjs
vendored
16
.github/workflows/workerHealthCheck.cjs
vendored
|
@ -1,7 +1,8 @@
|
|||
const { execSync } = require("child_process");
|
||||
|
||||
function workerHealthCheck(workerName) {
|
||||
const url = `https://${workerName}.devprod-testing7928.workers.dev/secret-health-check`;
|
||||
function workerHealthCheck() {
|
||||
const url =
|
||||
"https://wrangler-action-test.devprod-testing7928.workers.dev/secret-health-check";
|
||||
|
||||
const buffer = execSync(`curl ${url}`);
|
||||
|
||||
|
@ -16,13 +17,4 @@ function workerHealthCheck(workerName) {
|
|||
return response;
|
||||
}
|
||||
|
||||
const args = Array.from(process.argv);
|
||||
const workerName = args.pop();
|
||||
|
||||
if (!workerName) {
|
||||
throw new Error(
|
||||
"Please provide the worker name as an argument when calling this program.",
|
||||
);
|
||||
}
|
||||
|
||||
workerHealthCheck(workerName);
|
||||
workerHealthCheck();
|
||||
|
|
61
src/index.ts
61
src/index.ts
|
@ -10,8 +10,6 @@ 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";
|
||||
|
@ -23,7 +21,6 @@ const DEFAULT_WRANGLER_VERSION = "3.13.2";
|
|||
*/
|
||||
const config = {
|
||||
WRANGLER_VERSION: getInput("wranglerVersion") || DEFAULT_WRANGLER_VERSION,
|
||||
didUserProvideWranglerVersion: Boolean(getInput("wranglerVersion")),
|
||||
secrets: getMultilineInput("secrets"),
|
||||
workingDirectory: checkWorkingDirectory(getInput("workingDirectory")),
|
||||
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");
|
||||
try {
|
||||
await exec(
|
||||
|
|
|
@ -17,6 +17,7 @@ export default {
|
|||
return new Response("OK");
|
||||
}
|
||||
|
||||
// @ts-expect-error
|
||||
return Response.json({
|
||||
...request,
|
||||
headers: Object.fromEntries(request.headers),
|
|
@ -1,4 +1,4 @@
|
|||
name = "wrangler-action-test-only-build"
|
||||
name = "wrangler-action-test"
|
||||
main = "./index.ts"
|
||||
compatibility_date = "2023-07-07"
|
||||
workers_dev = true
|
|
@ -1,4 +0,0 @@
|
|||
name = "wrangler-action-test-build-quiet"
|
||||
main = "./index.ts"
|
||||
compatibility_date = "2023-07-07"
|
||||
workers_dev = true
|
|
@ -17,6 +17,7 @@ export default {
|
|||
return new Response("OK");
|
||||
}
|
||||
|
||||
// @ts-expect-error
|
||||
return Response.json({
|
||||
...request,
|
||||
headers: Object.fromEntries(request.headers),
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
name = "wrangler-action-test-secrets-v2"
|
||||
name = "wrangler-action-test"
|
||||
main = "./index.ts"
|
||||
compatibility_date = "2023-07-07"
|
||||
workers_dev = true
|
|
@ -12,6 +12,7 @@ export default {
|
|||
return new Response(`${SECRET1} ${SECRET2}`);
|
||||
}
|
||||
|
||||
// @ts-expect-error
|
||||
return Response.json({
|
||||
...request,
|
||||
headers: Object.fromEntries(request.headers),
|
||||
|
|
|
@ -17,6 +17,7 @@ export default {
|
|||
return new Response("OK");
|
||||
}
|
||||
|
||||
// @ts-expect-error
|
||||
return Response.json({
|
||||
...request,
|
||||
headers: Object.fromEntries(request.headers),
|
||||
|
|
|
@ -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),
|
||||
});
|
||||
},
|
||||
};
|
10
test/only-build/package-lock.json
generated
10
test/only-build/package-lock.json
generated
|
@ -1,10 +0,0 @@
|
|||
{
|
||||
"name": "wrangler-action-test",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "wrangler-action-test"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
{
|
||||
"name": "wrangler-action-test",
|
||||
"license": "MIT",
|
||||
"private": true
|
||||
}
|
|
@ -17,6 +17,7 @@ export default {
|
|||
return new Response("OK");
|
||||
}
|
||||
|
||||
// @ts-expect-error
|
||||
return Response.json({
|
||||
...request,
|
||||
headers: Object.fromEntries(request.headers),
|
||||
|
|
|
@ -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),
|
||||
});
|
||||
},
|
||||
};
|
|
@ -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);
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
{
|
||||
"private": true,
|
||||
"name": "wrangler",
|
||||
"version": "1.1.1",
|
||||
"main": "index.js",
|
||||
"bin": "index.js"
|
||||
}
|
30
test/pre-installed-wrangler/package-lock.json
generated
30
test/pre-installed-wrangler/package-lock.json
generated
|
@ -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"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
{
|
||||
"name": "wrangler-action-pre-installed-wrangler-test",
|
||||
"license": "MIT",
|
||||
"private": true,
|
||||
"devDependencies": {
|
||||
"wrangler": "file:mock_packages/wrangler"
|
||||
}
|
||||
}
|
|
@ -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),
|
||||
});
|
||||
},
|
||||
};
|
10
test/secrets-default/package-lock.json
generated
10
test/secrets-default/package-lock.json
generated
|
@ -1,10 +0,0 @@
|
|||
{
|
||||
"name": "wrangler-action-test",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "wrangler-action-test"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
{
|
||||
"name": "wrangler-action-test",
|
||||
"license": "MIT",
|
||||
"private": true
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
name = "wrangler-action-test-secrets-default"
|
||||
main = "./index.ts"
|
||||
compatibility_date = "2023-07-07"
|
||||
workers_dev = true
|
|
@ -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),
|
||||
});
|
||||
},
|
||||
};
|
10
test/secrets-v2/package-lock.json
generated
10
test/secrets-v2/package-lock.json
generated
|
@ -1,10 +0,0 @@
|
|||
{
|
||||
"name": "wrangler-action-test",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "wrangler-action-test"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
{
|
||||
"name": "wrangler-action-test",
|
||||
"license": "MIT",
|
||||
"private": true
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
name = "wrangler-action-test-specify-package-manager"
|
||||
main = "./index.ts"
|
||||
compatibility_date = "2023-07-07"
|
||||
workers_dev = true
|
|
@ -1 +0,0 @@
|
|||
export default {};
|
|
@ -1,5 +0,0 @@
|
|||
{
|
||||
"name": "wrangler-action-detect-package-manager-test",
|
||||
"license": "MIT",
|
||||
"private": true
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
name = "wrangler-action-test-unspecified-package-manager"
|
||||
main = "./index.ts"
|
||||
compatibility_date = "2023-07-07"
|
||||
workers_dev = true
|
|
@ -17,6 +17,7 @@ export default {
|
|||
return new Response("OK");
|
||||
}
|
||||
|
||||
// @ts-expect-error
|
||||
return Response.json({
|
||||
...request,
|
||||
headers: Object.fromEntries(request.headers),
|
||||
|
|
Loading…
Reference in a new issue