From 2f18bd97408461462c1df52c4811a9d0e57b4513 Mon Sep 17 00:00:00 2001 From: My Name is Tito Date: Sat, 31 Oct 2026 20:59:01 +1300 Subject: [PATCH] fix: publish docs preview artifact from CI --- .github/preview-worker.js | 5 ++++ .../scripts/__tests__/preview-worker.test.js | 23 +++++++++++++++++++ .github/workflows/ci.yml | 15 ++++++++++++ .github/workflows/deploy-preview.yml | 4 ++++ 4 files changed, 47 insertions(+) create mode 100644 .github/preview-worker.js create mode 100644 .github/scripts/__tests__/preview-worker.test.js diff --git a/.github/preview-worker.js b/.github/preview-worker.js new file mode 100644 index 0000000..4ed6113 --- /dev/null +++ b/.github/preview-worker.js @@ -0,0 +1,5 @@ +export default { + fetch(request, env) { + return env.ASSETS.fetch(request); + }, +}; diff --git a/.github/scripts/__tests__/preview-worker.test.js b/.github/scripts/__tests__/preview-worker.test.js new file mode 100644 index 0000000..cd158ea --- /dev/null +++ b/.github/scripts/__tests__/preview-worker.test.js @@ -0,0 +1,23 @@ +import { describe, expect, it } from "vitest"; + +import worker from "../../preview-worker.js"; + +describe("documentation preview worker", () => { + it("forwards requests and responses to the static asset binding", async () => { + const request = new Request("https://example.com/docs"); + const response = new Response("missing", { status: 404 }); + + const result = await worker.fetch(request, { + ASSETS: { + fetch: (received) => { + expect(received).toBe(request); + + return response; + }, + }, + }); + + expect(result).toBe(response); + expect(result.status).toBe(404); + }); +}); diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 457befa..a1f0f38 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,6 +31,7 @@ jobs: - name: Checkout uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: + ref: ${{ matrix.task == 'build' && github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }} persist-credentials: false - name: Setup Bun uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0 @@ -46,6 +47,20 @@ jobs: run: bun install --frozen-lockfile - name: Run task run: bun run ${{ matrix.task }} + - name: Prepare documentation preview artifact + if: matrix.task == 'build' && github.event_name == 'pull_request' + run: | + test -f apps/web/dist/index.html + mkdir -p "$RUNNER_TEMP/alchemy-worker" + cp .github/preview-worker.js "$RUNNER_TEMP/alchemy-worker/index.js" + cp -R apps/web/dist "$RUNNER_TEMP/alchemy-worker/site" + - name: Upload documentation preview artifact + if: matrix.task == 'build' && github.event_name == 'pull_request' + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 + with: + name: alchemy-worker + path: ${{ runner.temp }}/alchemy-worker/ + if-no-files-found: error - name: Upload force-input coverage to Codecov if: matrix.task == 'test' && env.CODECOV_TOKEN_AVAILABLE == 'true' uses: codecov/codecov-action@303a32d7a59b442fa8d48b6a1cc6825c09c847a5 # v7.1.1 diff --git a/.github/workflows/deploy-preview.yml b/.github/workflows/deploy-preview.yml index 0bdeb13..ca278fe 100644 --- a/.github/workflows/deploy-preview.yml +++ b/.github/workflows/deploy-preview.yml @@ -105,6 +105,8 @@ jobs: production-stage: prod production-url: https://opencode-plugins.mynameistito.com use-adopt: false + preview-assets-directory: site + preview-assets-config: '{"htmlHandling":"drop-trailing-slash","notFoundHandling":"404-page"}' pull-request-number: ${{ needs.resolve.outputs.pull_request_number }} allow-fork-commits: true @@ -149,4 +151,6 @@ jobs: production-stage: prod production-url: https://opencode-plugins.mynameistito.com use-adopt: false + preview-assets-directory: site + preview-assets-config: '{"htmlHandling":"drop-trailing-slash","notFoundHandling":"404-page"}' pull-request-number: ${{ needs.resolve.outputs.pull_request_number }}