diff --git a/.changeset/friendly-ways-hammer.md b/.changeset/friendly-ways-hammer.md new file mode 100644 index 0000000..ff88f72 --- /dev/null +++ b/.changeset/friendly-ways-hammer.md @@ -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 diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index a68b5a9..a23b5e4 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -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 diff --git a/.github/workflows/workerHealthCheck.cjs b/.github/workflows/workerHealthCheck.cjs index 9cbbab1..da61a96 100644 --- a/.github/workflows/workerHealthCheck.cjs +++ b/.github/workflows/workerHealthCheck.cjs @@ -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(); diff --git a/src/index.ts b/src/index.ts index e864fff..405aa3b 100755 --- a/src/index.ts +++ b/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( diff --git a/test/build-quiet/index.ts b/test/base/index.ts similarity index 95% rename from test/build-quiet/index.ts rename to test/base/index.ts index 306e73a..a330557 100644 --- a/test/build-quiet/index.ts +++ b/test/base/index.ts @@ -17,6 +17,7 @@ export default { return new Response("OK"); } + // @ts-expect-error return Response.json({ ...request, headers: Object.fromEntries(request.headers), diff --git a/test/build-quiet/package-lock.json b/test/base/package-lock.json similarity index 100% rename from test/build-quiet/package-lock.json rename to test/base/package-lock.json diff --git a/test/build-quiet/package.json b/test/base/package.json similarity index 100% rename from test/build-quiet/package.json rename to test/base/package.json diff --git a/test/only-build/wrangler.toml b/test/base/wrangler.toml similarity index 64% rename from test/only-build/wrangler.toml rename to test/base/wrangler.toml index ac83261..4c09785 100644 --- a/test/only-build/wrangler.toml +++ b/test/base/wrangler.toml @@ -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 diff --git a/test/build-quiet/wrangler.toml b/test/build-quiet/wrangler.toml deleted file mode 100644 index 157d056..0000000 --- a/test/build-quiet/wrangler.toml +++ /dev/null @@ -1,4 +0,0 @@ -name = "wrangler-action-test-build-quiet" -main = "./index.ts" -compatibility_date = "2023-07-07" -workers_dev = true diff --git a/test/bun/index.ts b/test/bun/index.ts index 306e73a..a330557 100644 --- a/test/bun/index.ts +++ b/test/bun/index.ts @@ -17,6 +17,7 @@ export default { return new Response("OK"); } + // @ts-expect-error return Response.json({ ...request, headers: Object.fromEntries(request.headers), diff --git a/test/specify-package-manager/index.ts b/test/empty/index.ts similarity index 100% rename from test/specify-package-manager/index.ts rename to test/empty/index.ts diff --git a/test/specify-package-manager/package.json b/test/empty/package.json similarity index 100% rename from test/specify-package-manager/package.json rename to test/empty/package.json diff --git a/test/secrets-v2/wrangler.toml b/test/empty/wrangler.toml similarity index 64% rename from test/secrets-v2/wrangler.toml rename to test/empty/wrangler.toml index e5e03e7..4c09785 100644 --- a/test/secrets-v2/wrangler.toml +++ b/test/empty/wrangler.toml @@ -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 diff --git a/test/environment/index.ts b/test/environment/index.ts index 23d5f1f..5379904 100644 --- a/test/environment/index.ts +++ b/test/environment/index.ts @@ -12,6 +12,7 @@ export default { return new Response(`${SECRET1} ${SECRET2}`); } + // @ts-expect-error return Response.json({ ...request, headers: Object.fromEntries(request.headers), diff --git a/test/npm/index.ts b/test/npm/index.ts index 306e73a..a330557 100644 --- a/test/npm/index.ts +++ b/test/npm/index.ts @@ -17,6 +17,7 @@ export default { return new Response("OK"); } + // @ts-expect-error return Response.json({ ...request, headers: Object.fromEntries(request.headers), diff --git a/test/only-build/index.ts b/test/only-build/index.ts deleted file mode 100644 index 306e73a..0000000 --- a/test/only-build/index.ts +++ /dev/null @@ -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), - }); - }, -}; diff --git a/test/only-build/package-lock.json b/test/only-build/package-lock.json deleted file mode 100644 index 5a28ad0..0000000 --- a/test/only-build/package-lock.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "name": "wrangler-action-test", - "lockfileVersion": 3, - "requires": true, - "packages": { - "": { - "name": "wrangler-action-test" - } - } -} diff --git a/test/only-build/package.json b/test/only-build/package.json deleted file mode 100644 index a773c48..0000000 --- a/test/only-build/package.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "wrangler-action-test", - "license": "MIT", - "private": true -} diff --git a/test/pnpm/index.ts b/test/pnpm/index.ts index 306e73a..a330557 100644 --- a/test/pnpm/index.ts +++ b/test/pnpm/index.ts @@ -17,6 +17,7 @@ export default { return new Response("OK"); } + // @ts-expect-error return Response.json({ ...request, headers: Object.fromEntries(request.headers), diff --git a/test/pre-installed-wrangler/index.ts b/test/pre-installed-wrangler/index.ts deleted file mode 100644 index 306e73a..0000000 --- a/test/pre-installed-wrangler/index.ts +++ /dev/null @@ -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), - }); - }, -}; diff --git a/test/pre-installed-wrangler/mock_packages/wrangler/index.js b/test/pre-installed-wrangler/mock_packages/wrangler/index.js deleted file mode 100755 index b5d136d..0000000 --- a/test/pre-installed-wrangler/mock_packages/wrangler/index.js +++ /dev/null @@ -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); -} diff --git a/test/pre-installed-wrangler/mock_packages/wrangler/package.json b/test/pre-installed-wrangler/mock_packages/wrangler/package.json deleted file mode 100644 index 3a2cfde..0000000 --- a/test/pre-installed-wrangler/mock_packages/wrangler/package.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "private": true, - "name": "wrangler", - "version": "1.1.1", - "main": "index.js", - "bin": "index.js" -} diff --git a/test/pre-installed-wrangler/package-lock.json b/test/pre-installed-wrangler/package-lock.json deleted file mode 100644 index 8bca760..0000000 --- a/test/pre-installed-wrangler/package-lock.json +++ /dev/null @@ -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" - } - } -} diff --git a/test/pre-installed-wrangler/package.json b/test/pre-installed-wrangler/package.json deleted file mode 100644 index dec93e3..0000000 --- a/test/pre-installed-wrangler/package.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "name": "wrangler-action-pre-installed-wrangler-test", - "license": "MIT", - "private": true, - "devDependencies": { - "wrangler": "file:mock_packages/wrangler" - } -} diff --git a/test/secrets-default/index.ts b/test/secrets-default/index.ts deleted file mode 100644 index 306e73a..0000000 --- a/test/secrets-default/index.ts +++ /dev/null @@ -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), - }); - }, -}; diff --git a/test/secrets-default/package-lock.json b/test/secrets-default/package-lock.json deleted file mode 100644 index 5a28ad0..0000000 --- a/test/secrets-default/package-lock.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "name": "wrangler-action-test", - "lockfileVersion": 3, - "requires": true, - "packages": { - "": { - "name": "wrangler-action-test" - } - } -} diff --git a/test/secrets-default/package.json b/test/secrets-default/package.json deleted file mode 100644 index a773c48..0000000 --- a/test/secrets-default/package.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "wrangler-action-test", - "license": "MIT", - "private": true -} diff --git a/test/secrets-default/wrangler.toml b/test/secrets-default/wrangler.toml deleted file mode 100644 index 1d53c69..0000000 --- a/test/secrets-default/wrangler.toml +++ /dev/null @@ -1,4 +0,0 @@ -name = "wrangler-action-test-secrets-default" -main = "./index.ts" -compatibility_date = "2023-07-07" -workers_dev = true diff --git a/test/secrets-v2/index.ts b/test/secrets-v2/index.ts deleted file mode 100644 index 306e73a..0000000 --- a/test/secrets-v2/index.ts +++ /dev/null @@ -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), - }); - }, -}; diff --git a/test/secrets-v2/package-lock.json b/test/secrets-v2/package-lock.json deleted file mode 100644 index 5a28ad0..0000000 --- a/test/secrets-v2/package-lock.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "name": "wrangler-action-test", - "lockfileVersion": 3, - "requires": true, - "packages": { - "": { - "name": "wrangler-action-test" - } - } -} diff --git a/test/secrets-v2/package.json b/test/secrets-v2/package.json deleted file mode 100644 index a773c48..0000000 --- a/test/secrets-v2/package.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "wrangler-action-test", - "license": "MIT", - "private": true -} diff --git a/test/specify-package-manager/wrangler.toml b/test/specify-package-manager/wrangler.toml deleted file mode 100644 index 08c11a2..0000000 --- a/test/specify-package-manager/wrangler.toml +++ /dev/null @@ -1,4 +0,0 @@ -name = "wrangler-action-test-specify-package-manager" -main = "./index.ts" -compatibility_date = "2023-07-07" -workers_dev = true diff --git a/test/unspecified-package-manager/index.ts b/test/unspecified-package-manager/index.ts deleted file mode 100644 index ff8b4c5..0000000 --- a/test/unspecified-package-manager/index.ts +++ /dev/null @@ -1 +0,0 @@ -export default {}; diff --git a/test/unspecified-package-manager/package.json b/test/unspecified-package-manager/package.json deleted file mode 100644 index 844af4e..0000000 --- a/test/unspecified-package-manager/package.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "wrangler-action-detect-package-manager-test", - "license": "MIT", - "private": true -} diff --git a/test/unspecified-package-manager/wrangler.toml b/test/unspecified-package-manager/wrangler.toml deleted file mode 100644 index e0d0f96..0000000 --- a/test/unspecified-package-manager/wrangler.toml +++ /dev/null @@ -1,4 +0,0 @@ -name = "wrangler-action-test-unspecified-package-manager" -main = "./index.ts" -compatibility_date = "2023-07-07" -workers_dev = true diff --git a/test/yarn/index.ts b/test/yarn/index.ts index 306e73a..a330557 100644 --- a/test/yarn/index.ts +++ b/test/yarn/index.ts @@ -17,6 +17,7 @@ export default { return new Response("OK"); } + // @ts-expect-error return Response.json({ ...request, headers: Object.fromEntries(request.headers),