Skip to content

Commit

Permalink
Revert "(feat): Use existing wrangler installation when appropriate (c…
Browse files Browse the repository at this point in the history
…loudflare#235)"

This reverts commit 0545ad2.
  • Loading branch information
Maximo-Guk committed May 24, 2024
1 parent 8ef515f commit 2d275a8
Show file tree
Hide file tree
Showing 36 changed files with 37 additions and 328 deletions.
5 changes: 5 additions & 0 deletions .changeset/friendly-ways-hammer.md
Original file line number Diff line number Diff line change
@@ -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 changes: 20 additions & 23 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -51,20 +52,28 @@ 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
env:
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: |
Expand All @@ -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: |
Expand All @@ -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 }}
Expand All @@ -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
Expand Down Expand Up @@ -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 changes: 4 additions & 12 deletions .github/workflows/workerHealthCheck.cjs
Original file line number Diff line number Diff line change
@@ -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}`);

Expand All @@ -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 changes: 0 additions & 61 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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"),
Expand Down Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions test/build-quiet/index.ts → test/base/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export default {
return new Response("OK");
}

// @ts-expect-error
return Response.json({
...request,
headers: Object.fromEntries(request.headers),
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion test/only-build/wrangler.toml → test/base/wrangler.toml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 0 additions & 4 deletions test/build-quiet/wrangler.toml

This file was deleted.

1 change: 1 addition & 0 deletions test/bun/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export default {
return new Response("OK");
}

// @ts-expect-error
return Response.json({
...request,
headers: Object.fromEntries(request.headers),
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion test/secrets-v2/wrangler.toml → test/empty/wrangler.toml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions test/environment/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export default {
return new Response(`${SECRET1} ${SECRET2}`);
}

// @ts-expect-error
return Response.json({
...request,
headers: Object.fromEntries(request.headers),
Expand Down
1 change: 1 addition & 0 deletions test/npm/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export default {
return new Response("OK");
}

// @ts-expect-error
return Response.json({
...request,
headers: Object.fromEntries(request.headers),
Expand Down
25 changes: 0 additions & 25 deletions test/only-build/index.ts

This file was deleted.

10 changes: 0 additions & 10 deletions test/only-build/package-lock.json

This file was deleted.

5 changes: 0 additions & 5 deletions test/only-build/package.json

This file was deleted.

1 change: 1 addition & 0 deletions test/pnpm/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export default {
return new Response("OK");
}

// @ts-expect-error
return Response.json({
...request,
headers: Object.fromEntries(request.headers),
Expand Down
25 changes: 0 additions & 25 deletions test/pre-installed-wrangler/index.ts

This file was deleted.

18 changes: 0 additions & 18 deletions test/pre-installed-wrangler/mock_packages/wrangler/index.js

This file was deleted.

This file was deleted.

Loading

0 comments on commit 2d275a8

Please sign in to comment.