Setup new CI test convention for wrangler-action

This commit is contained in:
Adishwar Rishi 2024-05-10 12:23:33 +10:00
parent 109508e12c
commit fcb0eb9753
No known key found for this signature in database
24 changed files with 168 additions and 27 deletions

View file

@ -29,7 +29,7 @@ jobs:
- name: Only build app
uses: ./
with:
workingDirectory: "./test/base"
workingDirectory: "./test/only-build"
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
command: deploy --dry-run
@ -38,12 +38,11 @@ jobs:
uses: ./
with:
quiet: true
workingDirectory: "./test/base"
workingDirectory: "./test/build-quiet"
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:
@ -52,6 +51,7 @@ 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,21 +59,12 @@ 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/base"
workingDirectory: "./test/secrets-v2"
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
secrets: |
@ -84,13 +75,13 @@ jobs:
SECRET2: ${{ secrets.SECRET2 }}
- name: Health Check Deployed Worker
run: node .github/workflows/workerHealthCheck.cjs
run: node .github/workflows/workerHealthCheck.cjs wrangler-action-test-secrets-v2
shell: bash
- name: Deploy app secrets w/ default version
uses: ./
with:
workingDirectory: "./test/base"
workingDirectory: "./test/secrets-default"
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
secrets: |
@ -101,22 +92,23 @@ jobs:
SECRET2: ${{ secrets.SECRET2 }}
- name: Health Check Deployed Worker
run: node .github/workflows/workerHealthCheck.cjs
run: node .github/workflows/workerHealthCheck.cjs wrangler-action-test-secrets-default
shell: bash
- name: Clean Up Deployed Workers
uses: ./
with:
workingDirectory: "./test/base"
workingDirectory: "./test/secrets-default"
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
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
- name: Support packageManager variable
uses: ./
with:
workingDirectory: "./test/empty"
workingDirectory: "./test/specify-package-manager"
packageManager: "npm"
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
@ -125,7 +117,7 @@ jobs:
- name: Support unspecified packageManager with no lockfile
uses: ./
with:
workingDirectory: "./test/empty"
workingDirectory: "./test/unspecified-package-manager"
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
command: deploy --dry-run

View file

@ -1,8 +1,7 @@
const { execSync } = require("child_process");
function workerHealthCheck() {
const url =
"https://wrangler-action-test.devprod-testing7928.workers.dev/secret-health-check";
function workerHealthCheck(workerName) {
const url = `https://${workerName}.devprod-testing7928.workers.dev/secret-health-check`;
const buffer = execSync(`curl ${url}`);
@ -17,4 +16,13 @@ function workerHealthCheck() {
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);

View file

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

View file

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

25
test/only-build/index.ts Normal file
View 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
View file

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

View file

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

View file

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

View 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
View file

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

View file

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

View 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
View 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
View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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