Skip to content

Commit 911fd8d

Browse files
ci: ensure existing-script-test-do-not-delete worker exists before C3 E2E tests (#10272)
* ci: ensure existing-script-test-do-not-delete worker exists before C3 E2E tests Add deployment step to create-cloudflare E2E workflow that deploys the existing-script-test-do-not-delete worker before tests run. This ensures the worker exists with the correct configuration (FOO=bar variable and Hello World response) that the --existing-script test relies on. Co-Authored-By: [email protected] <[email protected]> * Address PR feedback: use wrangler.jsonc, handle fork PRs, check worker existence - Convert wrangler.toml to wrangler.jsonc format as requested - Add condition to skip deployment if TEST_CLOUDFLARE_ACCOUNT_ID is not set (handles fork PRs) - Check if worker exists before deploying to avoid unnecessary deployments Addresses feedback from @petebacondarwin in PR comments. Co-Authored-By: [email protected] <[email protected]> * Fix worker URL in curl existence check Use the correct worker URL https://existing-script-test-do-not-delete.devprod-testing7928.workers.dev as specified by @petebacondarwin in PR comment feedback. Co-Authored-By: [email protected] <[email protected]> * Update condition to check for API token instead of account ID Change from env.TEST_CLOUDFLARE_ACCOUNT_ID to secrets.TEST_CLOUDFLARE_API_TOKEN as suggested by @petebacondarwin in PR comment feedback. Co-Authored-By: [email protected] <[email protected]> * Trigger CI to pick up no-changeset-required label This empty commit forces CI to re-run with the no-changeset-required label that was added to the PR after the last commit. Co-Authored-By: [email protected] <[email protected]> * Fix GitHub Actions YAML syntax error in worker deployment condition Replace invalid secrets.TEST_CLOUDFLARE_API_TOKEN check with proper fork detection pattern used elsewhere in the repository. Co-Authored-By: [email protected] <[email protected]> * Refactor CI to use permanent test worker files from tools/test-workers/ - Move worker definition from inline CI creation to tools/test-workers/existing-script-test-do-not-delete/ - Update C3 E2E workflow to reference permanent worker files instead of creating temporary ones - Add documentation for test workers in tools/README.md - Create deploy-all.sh script for future extensibility - Add .eslintignore to exclude test worker files from strict TypeScript linting - Maintain same deployment logic with existence check and fork PR handling Co-Authored-By: [email protected] <[email protected]> * Address PR feedback: convert deployment script to TypeScript and use separate CI job - Convert tools/test-workers/deploy-all.sh to TypeScript using Node.js patterns - Move environment variable checks and fetch-based existence check into TypeScript script - Refactor CI workflow to use separate 'deploy-test-workers' job with needs: dependency - Use 'node -r esbuild-register' execution pattern following tools/package.json conventions - Remove trigger_ci.md file which was only for triggering CI - Maintain all existing functionality while improving maintainability Co-Authored-By: [email protected] <[email protected]> * Trigger fresh CI validation Co-Authored-By: [email protected] <[email protected]> * Remove temporary trigger file Co-Authored-By: [email protected] <[email protected]> * Fix linting issues: remove unused error variable and enable allowJs for test workers Co-Authored-By: [email protected] <[email protected]> * Add documentation for deploy-all script as requested in PR feedback Co-Authored-By: [email protected] <[email protected]> * Update README with deploy-all documentation Co-Authored-By: [email protected] <[email protected]> * Fix unused @ts-expect-error directive in changeset-version.test.ts The directive was no longer needed after enabling allowJs in TypeScript config, causing a compilation error in CI checks. Co-Authored-By: [email protected] <[email protected]> * use `pnpx` rather than `npx` --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: [email protected] <[email protected]>
1 parent 56427e3 commit 911fd8d

File tree

8 files changed

+167
-3
lines changed

8 files changed

+167
-3
lines changed

.github/workflows/c3-e2e.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,43 @@ env:
1111
NODE_VERSION: 22
1212

1313
jobs:
14+
deploy-test-workers:
15+
name: Deploy Test Workers
16+
runs-on: ubuntu-latest
17+
if: github.event.pull_request.head.repo.owner.login == 'cloudflare' || github.event_name == 'merge_group'
18+
steps:
19+
- name: Checkout Repo
20+
uses: actions/checkout@v4
21+
with:
22+
fetch-depth: 0
23+
24+
- uses: dorny/paths-filter@v3
25+
id: changes
26+
with:
27+
filters: |
28+
everything_but_markdown:
29+
- '!**/*.md'
30+
31+
- name: Install Dependencies
32+
if: steps.changes.outputs.everything_but_markdown == 'true'
33+
uses: ./.github/actions/install-dependencies
34+
with:
35+
node-version: ${{ env.NODE_VERSION }}
36+
turbo-api: ${{ secrets.TURBO_API }}
37+
turbo-team: ${{ secrets.TURBO_TEAM }}
38+
turbo-token: ${{ secrets.TURBO_TOKEN }}
39+
turbo-signature: ${{ secrets.TURBO_REMOTE_CACHE_SIGNATURE_KEY }}
40+
41+
- name: Deploy test workers
42+
if: steps.changes.outputs.everything_but_markdown == 'true'
43+
shell: bash
44+
run: node -r esbuild-register tools/test-workers/deploy-all.ts
45+
env:
46+
CLOUDFLARE_API_TOKEN: ${{ secrets.TEST_CLOUDFLARE_API_TOKEN }}
47+
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.TEST_CLOUDFLARE_ACCOUNT_ID }}
48+
1449
e2e:
50+
needs: deploy-test-workers
1551
# Runs the non-frameworks C3 E2E tests on all supported operating systems and package managers.
1652
timeout-minutes: 45
1753
concurrency:

tools/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,5 @@ Tools for helping with CI
1919
- `e2e/runIndividualE2EFiles.ts` - Used to shard the e2e tests into separately cache-able Turbo runs, which helps with flakey tests.
2020

2121
- `test/run-test-file.ts` - Used by in VS Code configuration to launch a debug session to run a single test file.
22+
23+
- `test-workers/` - Contains worker definitions used by CI tests. Each worker has its own subdirectory with `index.js` and `wrangler.jsonc` files. See `test-workers/README.md` for details.

tools/deployments/__tests__/changeset-version.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { expect, it } from "vitest";
2-
// @ts-expect-error This is a JS file
32
import { getNextMiniflareVersion } from "../../../.github/changeset-version";
43

54
// prettier-ignore

tools/test-workers/README.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Test Workers
2+
3+
This directory contains worker definitions used by CI tests. Each worker has its own subdirectory containing:
4+
5+
- `index.js` - The worker script
6+
- `wrangler.jsonc` - The worker configuration
7+
8+
## Workers
9+
10+
### existing-script-test-do-not-delete
11+
12+
Used by the C3 E2E tests for the `--existing-script` functionality. This worker:
13+
14+
- Has a variable `FOO` set to `"bar"`
15+
- Returns "Hello World!" for all requests
16+
- Is deployed to the DevProd Testing account before E2E tests run
17+
18+
## Local Testing
19+
20+
To test a worker locally:
21+
22+
```bash
23+
cd tools/test-workers/existing-script-test-do-not-delete
24+
npx wrangler@latest dev
25+
```
26+
27+
To deploy a worker:
28+
29+
```bash
30+
cd tools/test-workers/existing-script-test-do-not-delete
31+
npx wrangler@latest deploy
32+
```
33+
34+
## Deploying All Test Workers
35+
36+
To deploy all test workers at once (used by CI):
37+
38+
```bash
39+
# From the repository root
40+
node -r esbuild-register tools/test-workers/deploy-all.ts
41+
42+
# Or from the tools directory
43+
cd tools
44+
node -r esbuild-register test-workers/deploy-all.ts
45+
```
46+
47+
The `deploy-all.ts` script:
48+
49+
- Checks for required environment variables (`CLOUDFLARE_API_TOKEN`, `CLOUDFLARE_ACCOUNT_ID`)
50+
- Verifies if workers already exist by checking their URLs
51+
- Only deploys workers that don't exist or aren't responding
52+
- Skips deployment gracefully if credentials are missing (useful for fork PRs)

tools/test-workers/deploy-all.ts

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import { execSync } from "node:child_process";
2+
import { resolve } from "node:path";
3+
4+
/**
5+
* Deploy all test workers for CI
6+
*/
7+
async function deployTestWorkers() {
8+
console.log("Deploying test workers...");
9+
10+
// Check if we have the required environment variables
11+
if (!process.env.CLOUDFLARE_API_TOKEN) {
12+
console.log("CLOUDFLARE_API_TOKEN not set, skipping worker deployment");
13+
return;
14+
}
15+
16+
if (!process.env.CLOUDFLARE_ACCOUNT_ID) {
17+
console.log("CLOUDFLARE_ACCOUNT_ID not set, skipping worker deployment");
18+
return;
19+
}
20+
21+
// Deploy existing-script-test-do-not-delete worker
22+
const workerDir = resolve(__dirname, "existing-script-test-do-not-delete");
23+
const workerUrl =
24+
"https://existing-script-test-do-not-delete.devprod-testing7928.workers.dev";
25+
26+
try {
27+
// Check if worker exists and deploy only if it doesn't
28+
const response = await fetch(workerUrl);
29+
if (response.ok) {
30+
console.log(
31+
"Worker 'existing-script-test-do-not-delete' already exists and is responding, skipping deployment"
32+
);
33+
} else {
34+
console.log(
35+
"Worker 'existing-script-test-do-not-delete' does not exist or is not responding, deploying..."
36+
);
37+
execSync("pnpx wrangler@latest deploy", {
38+
cwd: workerDir,
39+
env: process.env,
40+
stdio: "inherit",
41+
});
42+
}
43+
} catch {
44+
console.log(
45+
"Worker 'existing-script-test-do-not-delete' does not exist or is not responding, deploying..."
46+
);
47+
execSync("pnpx wrangler@latest deploy", {
48+
cwd: workerDir,
49+
env: process.env,
50+
stdio: "inherit",
51+
});
52+
}
53+
54+
console.log("Test worker deployment complete");
55+
}
56+
57+
if (require.main === module) {
58+
deployTestWorkers().catch((error) => {
59+
console.error("Failed to deploy test workers:", error);
60+
process.exit(1);
61+
});
62+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export default {
2+
async fetch(request, env, ctx) {
3+
return new Response("Hello World!");
4+
},
5+
};
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "existing-script-test-do-not-delete",
3+
"main": "index.js",
4+
"compatibility_date": "2023-05-18",
5+
"vars": {
6+
"FOO": "bar",
7+
},
8+
}

tools/tsconfig.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
22
"root": true,
33
"extends": "@cloudflare/workers-tsconfig/tsconfig.json",
4-
"include": ["**/*.ts"],
4+
"include": ["**/*.ts", "**/*.js"],
55
"exclude": ["node_modules"],
66
"compilerOptions": {
77
"module": "CommonJS",
8-
"allowJs": false,
8+
"allowJs": true,
99
"outDir": "dist",
1010
"types": ["node"],
1111
"resolveJsonModule": true

0 commit comments

Comments
 (0)