From 3583b255b08dce9c01d9ebf511b01b5a994b6d58 Mon Sep 17 00:00:00 2001 From: James Date: Wed, 30 Apr 2025 19:41:31 +0100 Subject: [PATCH 1/2] run e2es on windows --- .changeset/olive-lemons-dance.md | 5 ++++ .github/actions/setup-playwright/action.yml | 27 +++++++++++++++++++ .github/workflows/playwright.yml | 10 ++++--- examples/common/config-e2e.ts | 2 +- .../build/patches/plugins/instrumentation.ts | 4 ++- .../patches/plugins/wrangler-external.ts | 4 ++- .../src/cli/commands/populate-cache.ts | 11 +++++--- 7 files changed, 54 insertions(+), 9 deletions(-) create mode 100644 .changeset/olive-lemons-dance.md create mode 100644 .github/actions/setup-playwright/action.yml diff --git a/.changeset/olive-lemons-dance.md b/.changeset/olive-lemons-dance.md new file mode 100644 index 00000000..4318d8a8 --- /dev/null +++ b/.changeset/olive-lemons-dance.md @@ -0,0 +1,5 @@ +--- +"@opennextjs/cloudflare": patch +--- + +Fix multiple Windows path issues. diff --git a/.github/actions/setup-playwright/action.yml b/.github/actions/setup-playwright/action.yml new file mode 100644 index 00000000..161da717 --- /dev/null +++ b/.github/actions/setup-playwright/action.yml @@ -0,0 +1,27 @@ +name: "Setup Playwright" +description: "Setup Playwright with caching" + +runs: + using: "composite" + steps: + - name: Put $HOME in env + if: runner.os == 'windows' + shell: pwsh + run: echo "HOME=$HOME" | Out-File -FilePath $env:GITHUB_ENV -Append + + - name: Cache Playwright + id: playwright-cache + uses: actions/cache@v4 + with: + path: ${{ runner.os == 'Windows' && format('{0}{1}', env.HOME, '\AppData\Local\ms-playwright') || runner.os == 'Linux' && '~/.cache/ms-playwright' || '~/Library/Caches/ms-playwright' }} + key: playwright-${{ runner.os }}-${{ hashFiles('pnpm-lock.yaml') }} + + - name: Install Playwright with dependencies + if: steps.playwright-cache.outputs.cache-hit != 'true' + shell: bash + run: pnpm playwright install --with-deps + + - name: Install Playwright's dependencies + if: steps.playwright-cache.outputs.cache-hit == 'true' + shell: bash + run: pnpm playwright install-deps diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml index 487f826e..b15d6fbf 100644 --- a/.github/workflows/playwright.yml +++ b/.github/workflows/playwright.yml @@ -8,7 +8,11 @@ on: jobs: test: timeout-minutes: 30 - runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, windows-latest] + runs-on: ${{ matrix.os }} steps: - name: Check out code uses: actions/checkout@v4 @@ -17,7 +21,7 @@ jobs: uses: ./.github/actions/install-dependencies - name: Install Playwright - run: pnpm run install-playwright + uses: ./.github/actions/setup-playwright - name: Build the tool run: pnpm build @@ -34,6 +38,6 @@ jobs: - uses: actions/upload-artifact@v4 if: always() with: - name: playwright-report + name: playwright-report-${{ matrix.os }} path: ./**/playwright-report retention-days: 1 diff --git a/examples/common/config-e2e.ts b/examples/common/config-e2e.ts index eac3d98a..5b97b5bb 100644 --- a/examples/common/config-e2e.ts +++ b/examples/common/config-e2e.ts @@ -27,7 +27,7 @@ export function configurePlaywright( if (isCI) { // Do not build on CI - there is a preceding build step command = `pnpm preview:worker -- --port ${port} --inspector-port ${inspectorPort} ${env}`; - timeout = 100_000; + timeout = 250_000; } else { timeout = 500_000; command = `pnpm preview -- --port ${port} --inspector-port ${inspectorPort} ${env}`; diff --git a/packages/cloudflare/src/cli/build/patches/plugins/instrumentation.ts b/packages/cloudflare/src/cli/build/patches/plugins/instrumentation.ts index c8335a1a..37f03865 100644 --- a/packages/cloudflare/src/cli/build/patches/plugins/instrumentation.ts +++ b/packages/cloudflare/src/cli/build/patches/plugins/instrumentation.ts @@ -5,6 +5,8 @@ import { type BuildOptions, getPackagePath } from "@opennextjs/aws/build/helper. import { patchCode } from "@opennextjs/aws/build/patch/astCodePatcher.js"; import type { ContentUpdater, Plugin } from "@opennextjs/aws/plugins/content-updater.js"; +import { normalizePath } from "../../utils/normalize-path.js"; + export function patchInstrumentation(updater: ContentUpdater, buildOpts: BuildOptions): Plugin { const builtInstrumentationPath = getBuiltInstrumentationPath(buildOpts); @@ -84,7 +86,7 @@ function getBuiltInstrumentationPath(buildOpts: BuildOptions): string | null { getPackagePath(buildOpts), `.next/server/${INSTRUMENTATION_HOOK_FILENAME}.js` ); - return existsSync(maybeBuiltInstrumentationPath) ? maybeBuiltInstrumentationPath : null; + return existsSync(maybeBuiltInstrumentationPath) ? normalizePath(maybeBuiltInstrumentationPath) : null; } /** diff --git a/packages/cloudflare/src/cli/build/patches/plugins/wrangler-external.ts b/packages/cloudflare/src/cli/build/patches/plugins/wrangler-external.ts index 48b795b5..ba26caab 100644 --- a/packages/cloudflare/src/cli/build/patches/plugins/wrangler-external.ts +++ b/packages/cloudflare/src/cli/build/patches/plugins/wrangler-external.ts @@ -18,6 +18,8 @@ import { dirname, resolve } from "node:path"; import type { PluginBuild } from "esbuild"; +import { normalizePath } from "../../utils/normalize-path.js"; + export function setWranglerExternal() { return { name: "wrangler-externals", @@ -27,7 +29,7 @@ export function setWranglerExternal() { build.onResolve({ filter: /(\.bin|\.wasm\?module)$/ }, ({ path, importer }) => { return { - path: resolve(dirname(importer), path), + path: normalizePath(resolve(dirname(importer), path)), namespace, external: true, }; diff --git a/packages/cloudflare/src/cli/commands/populate-cache.ts b/packages/cloudflare/src/cli/commands/populate-cache.ts index dc48ad80..30958f1c 100644 --- a/packages/cloudflare/src/cli/commands/populate-cache.ts +++ b/packages/cloudflare/src/cli/commands/populate-cache.ts @@ -33,6 +33,7 @@ import { BINDING_NAME as D1_TAG_BINDING_NAME, NAME as D1_TAG_NAME, } from "../../api/overrides/tag-cache/d1-next-tag-cache.js"; +import { normalizePath } from "../build/utils/normalize-path.js"; import type { WranglerTarget } from "../utils/run-wrangler.js"; import { runWrangler } from "../utils/run-wrangler.js"; @@ -57,8 +58,8 @@ export function getCacheAssets(opts: BuildOptions): CacheAsset[] { const assets: CacheAsset[] = []; for (const file of allFiles) { - const fullPath = file.fullpathPosix(); - const relativePath = path.relative(path.join(opts.outputDir, "cache"), fullPath); + const fullPath = file.fullpath(); + const relativePath = normalizePath(path.relative(path.join(opts.outputDir, "cache"), fullPath)); if (relativePath.startsWith("__fetch")) { const [__fetch, buildId, ...keyParts] = relativePath.split("/"); @@ -121,7 +122,11 @@ function populateR2IncrementalCache( runWrangler( options, - ["r2 object put", JSON.stringify(path.join(bucket, cacheKey)), `--file ${JSON.stringify(fullPath)}`], + [ + "r2 object put", + JSON.stringify(normalizePath(path.join(bucket, cacheKey))), + `--file ${JSON.stringify(fullPath)}`, + ], // NOTE: R2 does not support the environment flag and results in the following error: // Incorrect type for the 'cacheExpiry' field on 'HttpMetadata': the provided value is not of type 'date'. { target: populateCacheOptions.target, excludeRemoteFlag: true, logging: "error" } From 3227d369e2ae267c9b618ba7fdc5376d7c4119f8 Mon Sep 17 00:00:00 2001 From: James Date: Wed, 30 Apr 2025 19:42:38 +0100 Subject: [PATCH 2/2] remove e2e change --- .github/workflows/playwright.yml | 8 ++------ examples/common/config-e2e.ts | 2 +- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml index b15d6fbf..b64c8f1f 100644 --- a/.github/workflows/playwright.yml +++ b/.github/workflows/playwright.yml @@ -8,11 +8,7 @@ on: jobs: test: timeout-minutes: 30 - strategy: - fail-fast: false - matrix: - os: [ubuntu-latest, windows-latest] - runs-on: ${{ matrix.os }} + runs-on: ubuntu-latest steps: - name: Check out code uses: actions/checkout@v4 @@ -38,6 +34,6 @@ jobs: - uses: actions/upload-artifact@v4 if: always() with: - name: playwright-report-${{ matrix.os }} + name: playwright-report path: ./**/playwright-report retention-days: 1 diff --git a/examples/common/config-e2e.ts b/examples/common/config-e2e.ts index 5b97b5bb..eac3d98a 100644 --- a/examples/common/config-e2e.ts +++ b/examples/common/config-e2e.ts @@ -27,7 +27,7 @@ export function configurePlaywright( if (isCI) { // Do not build on CI - there is a preceding build step command = `pnpm preview:worker -- --port ${port} --inspector-port ${inspectorPort} ${env}`; - timeout = 250_000; + timeout = 100_000; } else { timeout = 500_000; command = `pnpm preview -- --port ${port} --inspector-port ${inspectorPort} ${env}`;