mirror of
https://github.com/cloudflare/wrangler-action.git
synced 2024-11-25 03:14:46 +01:00
(feat): Use existing wrangler installation when appropriate (#235)
* (feat): Check for existing wrangler installation * Add test for pre-installed wrangler * Add changeset * Address CR comments - check for an exact wrangler version match * Tweak the fixture test for the pre-installed-wrangler test * Simplify if/else logic for checking wrangler versions as per review notes * fix(test): Fix execution for fake wrangler installation * fixup! fix(test): Fix execution for fake wrangler installation * Setup new CI test convention for wrangler-action * Remove unncessary ts-expect-error comments --------- Co-authored-by: Peter Bacon Darwin <pbacondarwin@cloudflare.com>
This commit is contained in:
parent
ea5754c9ad
commit
0545ad285a
36 changed files with 333 additions and 32 deletions
5
.changeset/tiny-planes-change.md
Normal file
5
.changeset/tiny-planes-change.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
"wrangler-action": minor
|
||||||
|
---
|
||||||
|
|
||||||
|
wrangler-action will now re-use existing wrangler installations when available
|
43
.github/workflows/deploy.yml
vendored
43
.github/workflows/deploy.yml
vendored
|
@ -29,7 +29,7 @@ jobs:
|
||||||
- name: Only build app
|
- name: Only build app
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
workingDirectory: "./test/base"
|
workingDirectory: "./test/only-build"
|
||||||
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,12 +38,11 @@ jobs:
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
quiet: true
|
quiet: true
|
||||||
workingDirectory: "./test/base"
|
workingDirectory: "./test/build-quiet"
|
||||||
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:
|
||||||
|
@ -52,6 +51,7 @@ 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,21 +59,12 @@ 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/base"
|
workingDirectory: "./test/secrets-v2"
|
||||||
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||||||
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
||||||
secrets: |
|
secrets: |
|
||||||
|
@ -84,13 +75,13 @@ jobs:
|
||||||
SECRET2: ${{ secrets.SECRET2 }}
|
SECRET2: ${{ secrets.SECRET2 }}
|
||||||
|
|
||||||
- name: Health Check Deployed Worker
|
- name: Health Check Deployed Worker
|
||||||
run: node .github/workflows/workerHealthCheck.cjs
|
run: node .github/workflows/workerHealthCheck.cjs wrangler-action-test-secrets-v2
|
||||||
shell: bash
|
shell: bash
|
||||||
|
|
||||||
- name: Deploy app secrets w/ default version
|
- name: Deploy app secrets w/ default version
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
workingDirectory: "./test/base"
|
workingDirectory: "./test/secrets-default"
|
||||||
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||||||
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
||||||
secrets: |
|
secrets: |
|
||||||
|
@ -101,22 +92,23 @@ jobs:
|
||||||
SECRET2: ${{ secrets.SECRET2 }}
|
SECRET2: ${{ secrets.SECRET2 }}
|
||||||
|
|
||||||
- name: Health Check Deployed Worker
|
- name: Health Check Deployed Worker
|
||||||
run: node .github/workflows/workerHealthCheck.cjs
|
run: node .github/workflows/workerHealthCheck.cjs wrangler-action-test-secrets-default
|
||||||
shell: bash
|
shell: bash
|
||||||
|
|
||||||
- name: Clean Up Deployed Workers
|
- name: Clean Up Deployed Workers
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
workingDirectory: "./test/base"
|
workingDirectory: "./test/secrets-default"
|
||||||
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 --force
|
command: delete --name wrangler-action-test-secrets-v2 --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/empty"
|
workingDirectory: "./test/specify-package-manager"
|
||||||
packageManager: "npm"
|
packageManager: "npm"
|
||||||
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||||||
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
||||||
|
@ -125,7 +117,7 @@ jobs:
|
||||||
- name: Support unspecified packageManager with no lockfile
|
- name: Support unspecified packageManager with no lockfile
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
workingDirectory: "./test/empty"
|
workingDirectory: "./test/unspecified-package-manager"
|
||||||
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
|
||||||
|
@ -159,3 +151,14 @@ 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
|
||||||
|
|
16
.github/workflows/workerHealthCheck.cjs
vendored
16
.github/workflows/workerHealthCheck.cjs
vendored
|
@ -1,8 +1,7 @@
|
||||||
const { execSync } = require("child_process");
|
const { execSync } = require("child_process");
|
||||||
|
|
||||||
function workerHealthCheck() {
|
function workerHealthCheck(workerName) {
|
||||||
const url =
|
const url = `https://${workerName}.devprod-testing7928.workers.dev/secret-health-check`;
|
||||||
"https://wrangler-action-test.devprod-testing7928.workers.dev/secret-health-check";
|
|
||||||
|
|
||||||
const buffer = execSync(`curl ${url}`);
|
const buffer = execSync(`curl ${url}`);
|
||||||
|
|
||||||
|
@ -17,4 +16,13 @@ function workerHealthCheck() {
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
workerHealthCheck();
|
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);
|
||||||
|
|
61
src/index.ts
61
src/index.ts
|
@ -10,6 +10,8 @@ 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";
|
||||||
|
@ -21,6 +23,7 @@ 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"),
|
||||||
|
@ -82,6 +85,64 @@ 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(
|
||||||
|
|
|
@ -17,7 +17,6 @@ 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),
|
4
test/build-quiet/wrangler.toml
Normal file
4
test/build-quiet/wrangler.toml
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
name = "wrangler-action-test-build-quiet"
|
||||||
|
main = "./index.ts"
|
||||||
|
compatibility_date = "2023-07-07"
|
||||||
|
workers_dev = true
|
|
@ -17,7 +17,6 @@ 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),
|
||||||
|
|
|
@ -12,7 +12,6 @@ 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),
|
||||||
|
|
|
@ -17,7 +17,6 @@ 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),
|
||||||
|
|
25
test/only-build/index.ts
Normal file
25
test/only-build/index.ts
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
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
Normal file
10
test/only-build/package-lock.json
generated
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
{
|
||||||
|
"name": "wrangler-action-test",
|
||||||
|
"lockfileVersion": 3,
|
||||||
|
"requires": true,
|
||||||
|
"packages": {
|
||||||
|
"": {
|
||||||
|
"name": "wrangler-action-test"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
5
test/only-build/package.json
Normal file
5
test/only-build/package.json
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
"name": "wrangler-action-test",
|
||||||
|
"license": "MIT",
|
||||||
|
"private": true
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
name = "wrangler-action-test"
|
name = "wrangler-action-test-only-build"
|
||||||
main = "./index.ts"
|
main = "./index.ts"
|
||||||
compatibility_date = "2023-07-07"
|
compatibility_date = "2023-07-07"
|
||||||
workers_dev = true
|
workers_dev = true
|
|
@ -17,7 +17,6 @@ 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),
|
||||||
|
|
25
test/pre-installed-wrangler/index.ts
Normal file
25
test/pre-installed-wrangler/index.ts
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
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),
|
||||||
|
});
|
||||||
|
},
|
||||||
|
};
|
18
test/pre-installed-wrangler/mock_packages/wrangler/index.js
Executable file
18
test/pre-installed-wrangler/mock_packages/wrangler/index.js
Executable file
|
@ -0,0 +1,18 @@
|
||||||
|
#!/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);
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
{
|
||||||
|
"private": true,
|
||||||
|
"name": "wrangler",
|
||||||
|
"version": "1.1.1",
|
||||||
|
"main": "index.js",
|
||||||
|
"bin": "index.js"
|
||||||
|
}
|
30
test/pre-installed-wrangler/package-lock.json
generated
Normal file
30
test/pre-installed-wrangler/package-lock.json
generated
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
{
|
||||||
|
"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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
8
test/pre-installed-wrangler/package.json
Normal file
8
test/pre-installed-wrangler/package.json
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
{
|
||||||
|
"name": "wrangler-action-pre-installed-wrangler-test",
|
||||||
|
"license": "MIT",
|
||||||
|
"private": true,
|
||||||
|
"devDependencies": {
|
||||||
|
"wrangler": "file:mock_packages/wrangler"
|
||||||
|
}
|
||||||
|
}
|
25
test/secrets-default/index.ts
Normal file
25
test/secrets-default/index.ts
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
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
Normal file
10
test/secrets-default/package-lock.json
generated
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
{
|
||||||
|
"name": "wrangler-action-test",
|
||||||
|
"lockfileVersion": 3,
|
||||||
|
"requires": true,
|
||||||
|
"packages": {
|
||||||
|
"": {
|
||||||
|
"name": "wrangler-action-test"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
5
test/secrets-default/package.json
Normal file
5
test/secrets-default/package.json
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
"name": "wrangler-action-test",
|
||||||
|
"license": "MIT",
|
||||||
|
"private": true
|
||||||
|
}
|
4
test/secrets-default/wrangler.toml
Normal file
4
test/secrets-default/wrangler.toml
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
name = "wrangler-action-test-secrets-default"
|
||||||
|
main = "./index.ts"
|
||||||
|
compatibility_date = "2023-07-07"
|
||||||
|
workers_dev = true
|
25
test/secrets-v2/index.ts
Normal file
25
test/secrets-v2/index.ts
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
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
Normal file
10
test/secrets-v2/package-lock.json
generated
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
{
|
||||||
|
"name": "wrangler-action-test",
|
||||||
|
"lockfileVersion": 3,
|
||||||
|
"requires": true,
|
||||||
|
"packages": {
|
||||||
|
"": {
|
||||||
|
"name": "wrangler-action-test"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
5
test/secrets-v2/package.json
Normal file
5
test/secrets-v2/package.json
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
"name": "wrangler-action-test",
|
||||||
|
"license": "MIT",
|
||||||
|
"private": true
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
name = "wrangler-action-test"
|
name = "wrangler-action-test-secrets-v2"
|
||||||
main = "./index.ts"
|
main = "./index.ts"
|
||||||
compatibility_date = "2023-07-07"
|
compatibility_date = "2023-07-07"
|
||||||
workers_dev = true
|
workers_dev = true
|
4
test/specify-package-manager/wrangler.toml
Normal file
4
test/specify-package-manager/wrangler.toml
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
name = "wrangler-action-test-specify-package-manager"
|
||||||
|
main = "./index.ts"
|
||||||
|
compatibility_date = "2023-07-07"
|
||||||
|
workers_dev = true
|
1
test/unspecified-package-manager/index.ts
Normal file
1
test/unspecified-package-manager/index.ts
Normal file
|
@ -0,0 +1 @@
|
||||||
|
export default {};
|
5
test/unspecified-package-manager/package.json
Normal file
5
test/unspecified-package-manager/package.json
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
"name": "wrangler-action-detect-package-manager-test",
|
||||||
|
"license": "MIT",
|
||||||
|
"private": true
|
||||||
|
}
|
4
test/unspecified-package-manager/wrangler.toml
Normal file
4
test/unspecified-package-manager/wrangler.toml
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
name = "wrangler-action-test-unspecified-package-manager"
|
||||||
|
main = "./index.ts"
|
||||||
|
compatibility_date = "2023-07-07"
|
||||||
|
workers_dev = true
|
|
@ -17,7 +17,6 @@ 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),
|
||||||
|
|
Loading…
Reference in a new issue