From 5293c3a6f0888b1d040b5880071ad25542394a0f Mon Sep 17 00:00:00 2001 From: Kian Newman-Hazel Date: Fri, 7 Feb 2025 08:18:41 +0000 Subject: [PATCH 01/12] [Docs Site] Move show-changed-files to be part of publish-preview workflow --- .github/workflows/publish-preview.yml | 14 +--- .github/workflows/show-changed-files.yml | 27 ------- .../README.md | 0 .../constants.ts | 2 +- .../index.node.test.ts | 0 .../index.ts | 81 +++++++++---------- .../util.ts | 0 7 files changed, 43 insertions(+), 81 deletions(-) delete mode 100644 .github/workflows/show-changed-files.yml rename bin/{show-changed-files => post-preview-url-comment}/README.md (100%) rename bin/{show-changed-files => post-preview-url-comment}/constants.ts (74%) rename bin/{show-changed-files => post-preview-url-comment}/index.node.test.ts (100%) rename bin/{show-changed-files => post-preview-url-comment}/index.ts (61%) rename bin/{show-changed-files => post-preview-url-comment}/util.ts (100%) diff --git a/.github/workflows/publish-preview.yml b/.github/workflows/publish-preview.yml index 4ccabebde510ad2..eda7027aabcd812 100644 --- a/.github/workflows/publish-preview.yml +++ b/.github/workflows/publish-preview.yml @@ -36,21 +36,11 @@ jobs: name: Deploy to Cloudflare Workers env: CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} - WRANGLER_OUTPUT_FILE_PATH: wrangler-logs.json + WRANGLER_OUTPUT_FILE_PATH: wrangler-logs.ndjson - name: Post preview URL on PR env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - PR=$(gh pr list --head ${{ github.ref_name }} --limit 1 --json number --jq '.[].number') - - if [ -n "$PR" ]; then - URL=$(cat wrangler-logs.json | jq -r 'select(.type=="version-upload") | .preview_url') - - if [ -n "$URL" ]; then - BODY="**Preview URL:** $URL" - gh pr comment "$PR" --edit-last --body "$BODY" || gh pr comment "$PR" --body "$BODY" - fi - fi + run: npx tsx bin/post-preview-url-comment/index.ts - uses: actions/cache/save@v4 if: always() with: diff --git a/.github/workflows/show-changed-files.yml b/.github/workflows/show-changed-files.yml deleted file mode 100644 index 53b2d9b9b5b58a9..000000000000000 --- a/.github/workflows/show-changed-files.yml +++ /dev/null @@ -1,27 +0,0 @@ -name: Show Changed Files - -# **What it does**: Comments on a PR with before/after links for changes in the PR. -# **Why we have it**: Makes reviewing a PR much easier b/c you don't have to hunt for specific pages. -# **Who does it impact**: PCX team - -on: - issue_comment: - types: - - created - - edited - -jobs: - changed-files-links: - name: Show Changed Files - if: github.event.issue.pull_request && github.event.issue.state == 'open' && github.event.comment.user.id == 41898282 && contains(github.event.comment.body, '**Preview URL:**') - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-node@v4 - with: - node-version: 22 - cache: "npm" - - run: npm ci - - run: npx tsx bin/show-changed-files/index.ts - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/bin/show-changed-files/README.md b/bin/post-preview-url-comment/README.md similarity index 100% rename from bin/show-changed-files/README.md rename to bin/post-preview-url-comment/README.md diff --git a/bin/show-changed-files/constants.ts b/bin/post-preview-url-comment/constants.ts similarity index 74% rename from bin/show-changed-files/constants.ts rename to bin/post-preview-url-comment/constants.ts index b233dcb4799f174..323e423edc2cf49 100644 --- a/bin/show-changed-files/constants.ts +++ b/bin/post-preview-url-comment/constants.ts @@ -1,5 +1,5 @@ export const GITHUB_ACTIONS_BOT_ID = 41898282; export const DOCS_BASE_URL = "https://developers.cloudflare.com"; export const CONTENT_BASE_PATH = "src/content"; -export const EXISTING_COMMENT_SUBSTRING = "| Original Link | Updated Link |"; export const PREVIEW_URL_REGEX = /^\*\*Preview URL:\*\* (.*)$/m; +export const WRANGLER_LOGS_PATH = "wrangler-logs.ndjson"; diff --git a/bin/show-changed-files/index.node.test.ts b/bin/post-preview-url-comment/index.node.test.ts similarity index 100% rename from bin/show-changed-files/index.node.test.ts rename to bin/post-preview-url-comment/index.node.test.ts diff --git a/bin/show-changed-files/index.ts b/bin/post-preview-url-comment/index.ts similarity index 61% rename from bin/show-changed-files/index.ts rename to bin/post-preview-url-comment/index.ts index d708afc6b4d6ea7..8621daf7ffccd14 100644 --- a/bin/show-changed-files/index.ts +++ b/bin/post-preview-url-comment/index.ts @@ -1,12 +1,14 @@ import * as core from "@actions/core"; import * as github from "@actions/github"; +import { readFile } from "node:fs/promises"; + import { CONTENT_BASE_PATH, DOCS_BASE_URL, - EXISTING_COMMENT_SUBSTRING, GITHUB_ACTIONS_BOT_ID, PREVIEW_URL_REGEX, + WRANGLER_LOGS_PATH, } from "./constants"; import { filenameToPath } from "./util"; @@ -15,57 +17,53 @@ async function run(): Promise { try { const token = core.getInput("GITHUB_TOKEN", { required: true }); const octokit = github.getOctokit(token); - const ctx = github.context; - if (!ctx.payload.issue) { - core.setFailed(`Payload ${ctx.payload} is missing an 'issue' property`); + const { data: pulls } = await octokit.rest.pulls.list({ + ...ctx.repo, + head: ctx.ref, + }); + + const pull_number = pulls.at(0)?.number; + + if (!pull_number) { + core.setFailed(`Could not find pull requests for ${ctx.ref}`); process.exit(); } - const issue = ctx.payload.issue.number; - const files = await octokit.paginate(octokit.rest.pulls.listFiles, { ...ctx.repo, - pull_number: issue, + pull_number, per_page: 100, }); const { data: comments } = await octokit.rest.issues.listComments({ - owner: ctx.repo.owner, - repo: ctx.repo.repo, - issue_number: issue, + ...ctx.repo, + issue_number: pull_number, per_page: 100, }); const existingComment = comments.find( - (comment) => - comment.user?.id === GITHUB_ACTIONS_BOT_ID && - comment.body?.includes(EXISTING_COMMENT_SUBSTRING), - ); - - const urlComment = comments.find( (comment) => comment.user?.id === GITHUB_ACTIONS_BOT_ID && PREVIEW_URL_REGEX.test(comment.body ?? ""), ); - if (!urlComment || !urlComment.body) { - core.setFailed( - `Could not find a comment from ${GITHUB_ACTIONS_BOT_ID} on ${issue}`, - ); - process.exit(); - } - - const match = urlComment.body.match(PREVIEW_URL_REGEX); - - if (!match) { - core.setFailed(`Could not extract URL from ${urlComment.body}`); + const previewUrl: string = ( + await readFile(WRANGLER_LOGS_PATH, { encoding: "utf-8" }) + ) + .split("\n") + .filter(Boolean) + .map((json) => JSON.parse(json)) + .filter((json) => json.type === "version-upload") + .map((json) => json.preview_url) + .at(0); + + if (!previewUrl) { + core.setFailed(`Found no version-upload at ${WRANGLER_LOGS_PATH}`); process.exit(); } - const previewUrl = match[1]; - core.debug(previewUrl); const changedFiles = files @@ -86,30 +84,31 @@ async function run(): Promise { return { original, preview }; }); - if (changedFiles.length === 0) { - return; + let comment = `**Preview URL:** ${previewUrl}`; + if (changedFiles.length !== 0) { + comment = comment.concat( + `**Files with changes (up to 15)**\n\n| Original Link | Updated Link |\n| --- | --- |\n${changedFiles + .map( + (file) => + `| [${file.original}](${file.original}) | [${file.preview}](${file.preview}) |`, + ) + .join("\n")}`, + ); } - const commentBody = `**Files with changes (up to 15)**\n\n| Original Link | Updated Link |\n| --- | --- |\n${changedFiles - .map( - (file) => - `| [${file.original}](${file.original}) | [${file.preview}](${file.preview}) |`, - ) - .join("\n")}`; - if (existingComment) { await octokit.rest.issues.updateComment({ owner: ctx.repo.owner, repo: ctx.repo.repo, comment_id: existingComment.id, - body: commentBody, + body: comment, }); } else { await octokit.rest.issues.createComment({ owner: ctx.repo.owner, repo: ctx.repo.repo, - issue_number: issue, - body: commentBody, + issue_number: pull_number, + body: comment, }); } } catch (error) { diff --git a/bin/show-changed-files/util.ts b/bin/post-preview-url-comment/util.ts similarity index 100% rename from bin/show-changed-files/util.ts rename to bin/post-preview-url-comment/util.ts From 7cc755177768c36d88fd3c37eccc8331fa89d5c2 Mon Sep 17 00:00:00 2001 From: Kian Newman-Hazel Date: Fri, 7 Feb 2025 08:28:53 +0000 Subject: [PATCH 02/12] change env var name --- .github/workflows/publish-preview.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish-preview.yml b/.github/workflows/publish-preview.yml index eda7027aabcd812..d6f7d1bb7ec79d6 100644 --- a/.github/workflows/publish-preview.yml +++ b/.github/workflows/publish-preview.yml @@ -39,7 +39,7 @@ jobs: WRANGLER_OUTPUT_FILE_PATH: wrangler-logs.ndjson - name: Post preview URL on PR env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: npx tsx bin/post-preview-url-comment/index.ts - uses: actions/cache/save@v4 if: always() From a3758616102fd3a573522aaf21e1fd3ee2cd31df Mon Sep 17 00:00:00 2001 From: Kian Newman-Hazel Date: Fri, 7 Feb 2025 08:39:37 +0000 Subject: [PATCH 03/12] read from env var --- bin/post-preview-url-comment/index.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/bin/post-preview-url-comment/index.ts b/bin/post-preview-url-comment/index.ts index 8621daf7ffccd14..6fb1c18afa3f2e0 100644 --- a/bin/post-preview-url-comment/index.ts +++ b/bin/post-preview-url-comment/index.ts @@ -15,8 +15,12 @@ import { filenameToPath } from "./util"; async function run(): Promise { try { - const token = core.getInput("GITHUB_TOKEN", { required: true }); - const octokit = github.getOctokit(token); + if (!process.env.GITHUB_TOKEN) { + core.setFailed(`Could not find GITHUB_TOKEN in env`); + process.exit(); + } + + const octokit = github.getOctokit(process.env.GITHUB_TOKEN); const ctx = github.context; const { data: pulls } = await octokit.rest.pulls.list({ From 40ee558bb57073588e583ed22e37922c477e1bd4 Mon Sep 17 00:00:00 2001 From: Kian Newman-Hazel Date: Fri, 7 Feb 2025 09:25:39 +0000 Subject: [PATCH 04/12] Move to WFP for preview deployments --- .github/workflows/publish-preview.yml | 10 +- bin/post-preview-url-comment/constants.ts | 1 - bin/post-preview-url-comment/index.ts | 33 +- bin/post-preview-url-comment/util.ts | 2 + package-lock.json | 365 +++------------------- package.json | 4 +- 6 files changed, 60 insertions(+), 355 deletions(-) diff --git a/.github/workflows/publish-preview.yml b/.github/workflows/publish-preview.yml index d6f7d1bb7ec79d6..d1d4d303b031a02 100644 --- a/.github/workflows/publish-preview.yml +++ b/.github/workflows/publish-preview.yml @@ -32,11 +32,15 @@ jobs: name: Build env: NODE_OPTIONS: --max-old-space-size=4096 - - run: npx wrangler versions upload - name: Deploy to Cloudflare Workers + - name: Deploy to Cloudflare Workers env: CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} - WRANGLER_OUTPUT_FILE_PATH: wrangler-logs.ndjson + run: | + SHORT_SHA=$(git rev-parse --short=8 HEAD) + BRANCH_SLUG=$(git rev-parse --abbrev-ref HEAD | iconv -c -t ascii//TRANSLIT | sed -E 's/[~^]+//g' | sed -E 's/[^a-zA-Z0-9]+/-/g' | sed -E 's/^-+|-+$//g' | tr A-Z a-z) + + npx wrangler deploy --dispatch-namespace preview-deployments --name $SHORT_SHA + npx wrangler deploy --dispatch-namespace preview-deployments --name $BRANCH_SLUG - name: Post preview URL on PR env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/bin/post-preview-url-comment/constants.ts b/bin/post-preview-url-comment/constants.ts index 323e423edc2cf49..66bc4bbc2309479 100644 --- a/bin/post-preview-url-comment/constants.ts +++ b/bin/post-preview-url-comment/constants.ts @@ -2,4 +2,3 @@ export const GITHUB_ACTIONS_BOT_ID = 41898282; export const DOCS_BASE_URL = "https://developers.cloudflare.com"; export const CONTENT_BASE_PATH = "src/content"; export const PREVIEW_URL_REGEX = /^\*\*Preview URL:\*\* (.*)$/m; -export const WRANGLER_LOGS_PATH = "wrangler-logs.ndjson"; diff --git a/bin/post-preview-url-comment/index.ts b/bin/post-preview-url-comment/index.ts index 6fb1c18afa3f2e0..067aca666b331ff 100644 --- a/bin/post-preview-url-comment/index.ts +++ b/bin/post-preview-url-comment/index.ts @@ -1,22 +1,19 @@ import * as core from "@actions/core"; import * as github from "@actions/github"; -import { readFile } from "node:fs/promises"; - import { CONTENT_BASE_PATH, DOCS_BASE_URL, GITHUB_ACTIONS_BOT_ID, PREVIEW_URL_REGEX, - WRANGLER_LOGS_PATH, } from "./constants"; -import { filenameToPath } from "./util"; +import { filenameToPath, slug } from "./util"; async function run(): Promise { try { - if (!process.env.GITHUB_TOKEN) { - core.setFailed(`Could not find GITHUB_TOKEN in env`); + if (!process.env.GITHUB_TOKEN || !process.env.GITHUB_REF_NAME) { + core.setFailed(`Could not find GITHUB_TOKEN or GITHUB_REF_NAME in env`); process.exit(); } @@ -53,22 +50,12 @@ async function run(): Promise { PREVIEW_URL_REGEX.test(comment.body ?? ""), ); - const previewUrl: string = ( - await readFile(WRANGLER_LOGS_PATH, { encoding: "utf-8" }) - ) - .split("\n") - .filter(Boolean) - .map((json) => JSON.parse(json)) - .filter((json) => json.type === "version-upload") - .map((json) => json.preview_url) - .at(0); - - if (!previewUrl) { - core.setFailed(`Found no version-upload at ${WRANGLER_LOGS_PATH}`); - process.exit(); - } + const previewUrl = { + branch: `https://${slug(process.env.GITHUB_REF_NAME)}.preview.developers.cloudflare.com`, + commit: `https://${ctx.sha.slice(0, 8)}.preview.developers.cloudflare.com`, + }; - core.debug(previewUrl); + core.debug(JSON.stringify(previewUrl)); const changedFiles = files .filter( @@ -81,14 +68,14 @@ async function run(): Promise { .slice(0, 15) // Limit to 15 entries .map(({ filename }) => { const original = `${DOCS_BASE_URL}/${filenameToPath(filename)}`; - const preview = `${previewUrl}/${filenameToPath(filename)}`; + const preview = `${previewUrl.branch}/${filenameToPath(filename)}`; core.debug([filename, original, preview].toString()); return { original, preview }; }); - let comment = `**Preview URL:** ${previewUrl}`; + let comment = `**Preview URL:** ${previewUrl.branch}`; if (changedFiles.length !== 0) { comment = comment.concat( `**Files with changes (up to 15)**\n\n| Original Link | Updated Link |\n| --- | --- |\n${changedFiles diff --git a/bin/post-preview-url-comment/util.ts b/bin/post-preview-url-comment/util.ts index f783dc6123fd8bd..e63f5fe5a0929a3 100644 --- a/bin/post-preview-url-comment/util.ts +++ b/bin/post-preview-url-comment/util.ts @@ -29,3 +29,5 @@ export const filenameToPath = (filename: string) => { .replace(/\/index$/, "") .concat("/"); }; + +export { slug }; diff --git a/package-lock.json b/package-lock.json index 0ba37a113a11164..0c5119de2ee37eb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -18,7 +18,7 @@ "@astrojs/starlight-tailwind": "3.0.0", "@astrojs/tailwind": "5.1.5", "@cloudflare/vitest-pool-workers": "0.6.11", - "@cloudflare/workers-types": "4.20250121.0", + "@cloudflare/workers-types": "4.20250204.0", "@codingheads/sticky-header": "1.0.2", "@expressive-code/plugin-collapsible-sections": "0.40.1", "@iarna/toml": "2.2.5", @@ -90,7 +90,7 @@ "unist-util-visit": "5.0.0", "vite-tsconfig-paths": "5.1.4", "vitest": "2.1.6", - "wrangler": "3.103.2" + "wrangler": "3.107.3" }, "engines": { "node": ">=22" @@ -1157,135 +1157,6 @@ "vitest": "2.0.x - 2.1.x" } }, - "node_modules/@cloudflare/vitest-pool-workers/node_modules/@cloudflare/workerd-darwin-64": { - "version": "1.20250129.0", - "resolved": "https://registry.npmjs.org/@cloudflare/workerd-darwin-64/-/workerd-darwin-64-1.20250129.0.tgz", - "integrity": "sha512-M+xETVnl+xy2dfDDWmp0XXr2rttl70a6bljQygl0EmYmNswFTcYbQWCaBuNBo9kabU59rLKr4a/b3QZ07NoL/g==", - "cpu": [ - "x64" - ], - "dev": true, - "license": "Apache-2.0", - "optional": true, - "os": [ - "darwin" - ], - "engines": { - "node": ">=16" - } - }, - "node_modules/@cloudflare/vitest-pool-workers/node_modules/@cloudflare/workerd-darwin-arm64": { - "version": "1.20250129.0", - "resolved": "https://registry.npmjs.org/@cloudflare/workerd-darwin-arm64/-/workerd-darwin-arm64-1.20250129.0.tgz", - "integrity": "sha512-c4PQUyIMp+bCMxZkAMBzXgTHjRZxeYCujDbb3staestqgRbenzcfauXsMd6np35ng+EE1uBgHNPV4+7fC0ZBfg==", - "cpu": [ - "arm64" - ], - "dev": true, - "license": "Apache-2.0", - "optional": true, - "os": [ - "darwin" - ], - "engines": { - "node": ">=16" - } - }, - "node_modules/@cloudflare/vitest-pool-workers/node_modules/@cloudflare/workerd-linux-64": { - "version": "1.20250129.0", - "resolved": "https://registry.npmjs.org/@cloudflare/workerd-linux-64/-/workerd-linux-64-1.20250129.0.tgz", - "integrity": "sha512-xJx8LwWFxsm5U3DETJwRuOmT5RWBqm4FmA4itYXvcEICca9pWJDB641kT4PnpypwDNmYOebhU7A+JUrCRucG0w==", - "cpu": [ - "x64" - ], - "dev": true, - "license": "Apache-2.0", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=16" - } - }, - "node_modules/@cloudflare/vitest-pool-workers/node_modules/@cloudflare/workerd-linux-arm64": { - "version": "1.20250129.0", - "resolved": "https://registry.npmjs.org/@cloudflare/workerd-linux-arm64/-/workerd-linux-arm64-1.20250129.0.tgz", - "integrity": "sha512-dR//npbaX5p323huBVNIy5gaWubQx6CC3aiXeK0yX4aD5ar8AjxQFb2U/Sgjeo65Rkt53hJWqC7IwRpK/eOxrA==", - "cpu": [ - "arm64" - ], - "dev": true, - "license": "Apache-2.0", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=16" - } - }, - "node_modules/@cloudflare/vitest-pool-workers/node_modules/@cloudflare/workerd-windows-64": { - "version": "1.20250129.0", - "resolved": "https://registry.npmjs.org/@cloudflare/workerd-windows-64/-/workerd-windows-64-1.20250129.0.tgz", - "integrity": "sha512-OeO+1nPj/ocAE3adFar/tRFGRkbCrBnrOYXq0FUBSpyNHpDdA9/U3PAw5CN4zvjfTnqXZfTxTFeqoruqzRzbtg==", - "cpu": [ - "x64" - ], - "dev": true, - "license": "Apache-2.0", - "optional": true, - "os": [ - "win32" - ], - "engines": { - "node": ">=16" - } - }, - "node_modules/@cloudflare/vitest-pool-workers/node_modules/@cloudflare/workers-types": { - "version": "4.20250129.0", - "resolved": "https://registry.npmjs.org/@cloudflare/workers-types/-/workers-types-4.20250129.0.tgz", - "integrity": "sha512-H7g/sDB9GaV+fIPf3utNEYncFhryIvDThiBbfZtu0bZmVXcVd9ApP3OMqUYhNV8MShWQASvgWletKKBZGT9/oA==", - "dev": true, - "license": "MIT OR Apache-2.0", - "optional": true, - "peer": true - }, - "node_modules/@cloudflare/vitest-pool-workers/node_modules/unenv": { - "version": "2.0.0-rc.1", - "resolved": "https://registry.npmjs.org/unenv/-/unenv-2.0.0-rc.1.tgz", - "integrity": "sha512-PU5fb40H8X149s117aB4ytbORcCvlASdtF97tfls4BPIyj4PeVxvpSuy1jAptqYHqB0vb2w2sHvzM0XWcp2OKg==", - "dev": true, - "license": "MIT", - "dependencies": { - "defu": "^6.1.4", - "mlly": "^1.7.4", - "ohash": "^1.1.4", - "pathe": "^1.1.2", - "ufo": "^1.5.4" - } - }, - "node_modules/@cloudflare/vitest-pool-workers/node_modules/workerd": { - "version": "1.20250129.0", - "resolved": "https://registry.npmjs.org/workerd/-/workerd-1.20250129.0.tgz", - "integrity": "sha512-Rprz8rxKTF4l6q/nYYI07lBetJnR19mGipx+u/a27GZOPKMG5SLIzA2NciZlJaB2Qd5YY+4p/eHOeKqo5keVWA==", - "dev": true, - "hasInstallScript": true, - "license": "Apache-2.0", - "bin": { - "workerd": "bin/workerd" - }, - "engines": { - "node": ">=16" - }, - "optionalDependencies": { - "@cloudflare/workerd-darwin-64": "1.20250129.0", - "@cloudflare/workerd-darwin-arm64": "1.20250129.0", - "@cloudflare/workerd-linux-64": "1.20250129.0", - "@cloudflare/workerd-linux-arm64": "1.20250129.0", - "@cloudflare/workerd-windows-64": "1.20250129.0" - } - }, "node_modules/@cloudflare/vitest-pool-workers/node_modules/wrangler": { "version": "3.107.2", "resolved": "https://registry.npmjs.org/wrangler/-/wrangler-3.107.2.tgz", @@ -1323,9 +1194,9 @@ } }, "node_modules/@cloudflare/workerd-darwin-64": { - "version": "1.20241230.0", - "resolved": "https://registry.npmjs.org/@cloudflare/workerd-darwin-64/-/workerd-darwin-64-1.20241230.0.tgz", - "integrity": "sha512-BZHLg4bbhNQoaY1Uan81O3FV/zcmWueC55juhnaI7NAobiQth9RppadPNpxNAmS9fK2mR5z8xrwMQSQrHmztyQ==", + "version": "1.20250129.0", + "resolved": "https://registry.npmjs.org/@cloudflare/workerd-darwin-64/-/workerd-darwin-64-1.20250129.0.tgz", + "integrity": "sha512-M+xETVnl+xy2dfDDWmp0XXr2rttl70a6bljQygl0EmYmNswFTcYbQWCaBuNBo9kabU59rLKr4a/b3QZ07NoL/g==", "cpu": [ "x64" ], @@ -1340,9 +1211,9 @@ } }, "node_modules/@cloudflare/workerd-darwin-arm64": { - "version": "1.20241230.0", - "resolved": "https://registry.npmjs.org/@cloudflare/workerd-darwin-arm64/-/workerd-darwin-arm64-1.20241230.0.tgz", - "integrity": "sha512-lllxycj7EzYoJ0VOJh8M3palUgoonVrILnzGrgsworgWlIpgjfXGS7b41tEGCw6AxSxL9prmTIGtfSPUvn/rjg==", + "version": "1.20250129.0", + "resolved": "https://registry.npmjs.org/@cloudflare/workerd-darwin-arm64/-/workerd-darwin-arm64-1.20250129.0.tgz", + "integrity": "sha512-c4PQUyIMp+bCMxZkAMBzXgTHjRZxeYCujDbb3staestqgRbenzcfauXsMd6np35ng+EE1uBgHNPV4+7fC0ZBfg==", "cpu": [ "arm64" ], @@ -1357,9 +1228,9 @@ } }, "node_modules/@cloudflare/workerd-linux-64": { - "version": "1.20241230.0", - "resolved": "https://registry.npmjs.org/@cloudflare/workerd-linux-64/-/workerd-linux-64-1.20241230.0.tgz", - "integrity": "sha512-Y3mHcW0KghOmWdNZyHYpEOG4Ba/ga8tht5vj1a+WXfagEjMO8Y98XhZUlCaYa9yB7Wh5jVcK5LM2jlO/BLgqpA==", + "version": "1.20250129.0", + "resolved": "https://registry.npmjs.org/@cloudflare/workerd-linux-64/-/workerd-linux-64-1.20250129.0.tgz", + "integrity": "sha512-xJx8LwWFxsm5U3DETJwRuOmT5RWBqm4FmA4itYXvcEICca9pWJDB641kT4PnpypwDNmYOebhU7A+JUrCRucG0w==", "cpu": [ "x64" ], @@ -1374,9 +1245,9 @@ } }, "node_modules/@cloudflare/workerd-linux-arm64": { - "version": "1.20241230.0", - "resolved": "https://registry.npmjs.org/@cloudflare/workerd-linux-arm64/-/workerd-linux-arm64-1.20241230.0.tgz", - "integrity": "sha512-IAjhsWPlHzhhkJ6I49sDG6XfMnhPvv0szKGXxTWQK/IWMrbGdHm4RSfNKBSoLQm67jGMIzbmcrX9UIkms27Y1g==", + "version": "1.20250129.0", + "resolved": "https://registry.npmjs.org/@cloudflare/workerd-linux-arm64/-/workerd-linux-arm64-1.20250129.0.tgz", + "integrity": "sha512-dR//npbaX5p323huBVNIy5gaWubQx6CC3aiXeK0yX4aD5ar8AjxQFb2U/Sgjeo65Rkt53hJWqC7IwRpK/eOxrA==", "cpu": [ "arm64" ], @@ -1391,9 +1262,9 @@ } }, "node_modules/@cloudflare/workerd-windows-64": { - "version": "1.20241230.0", - "resolved": "https://registry.npmjs.org/@cloudflare/workerd-windows-64/-/workerd-windows-64-1.20241230.0.tgz", - "integrity": "sha512-y5SPIk9iOb2gz+yWtHxoeMnjPnkYQswiCJ480oHC6zexnJLlKTpcmBCjDH1nWCT4pQi8F25gaH8thgElf4NvXQ==", + "version": "1.20250129.0", + "resolved": "https://registry.npmjs.org/@cloudflare/workerd-windows-64/-/workerd-windows-64-1.20250129.0.tgz", + "integrity": "sha512-OeO+1nPj/ocAE3adFar/tRFGRkbCrBnrOYXq0FUBSpyNHpDdA9/U3PAw5CN4zvjfTnqXZfTxTFeqoruqzRzbtg==", "cpu": [ "x64" ], @@ -1408,9 +1279,9 @@ } }, "node_modules/@cloudflare/workers-types": { - "version": "4.20250121.0", - "resolved": "https://registry.npmjs.org/@cloudflare/workers-types/-/workers-types-4.20250121.0.tgz", - "integrity": "sha512-2bBosmudcwvUOKzuCL/Jum18LDh3QoU0QnTNMXIgcVwuq3LaNzyZnOW14bFXPhLU/84ZjNO3zO5R/U11Zgag2Q==", + "version": "4.20250204.0", + "resolved": "https://registry.npmjs.org/@cloudflare/workers-types/-/workers-types-4.20250204.0.tgz", + "integrity": "sha512-mWoQbYaP+nYztx9I7q9sgaiNlT54Cypszz0RfzMxYnT5W3NXDuwGcjGB+5B5H5VB8tEC2dYnBRpa70lX94ueaQ==", "dev": true, "license": "MIT OR Apache-2.0" }, @@ -6571,17 +6442,6 @@ ], "license": "CC-BY-4.0" }, - "node_modules/capnp-ts": { - "version": "0.7.0", - "resolved": "https://registry.npmjs.org/capnp-ts/-/capnp-ts-0.7.0.tgz", - "integrity": "sha512-XKxXAC3HVPv7r674zP0VC3RTXz+/JKhfyw94ljvF80yynK6VkTnqE3jMuN8b3dUVmmc43TjyxjW4KTsmB3c86g==", - "dev": true, - "license": "MIT", - "dependencies": { - "debug": "^4.3.1", - "tslib": "^2.2.0" - } - }, "node_modules/ccount": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/ccount/-/ccount-2.0.1.tgz", @@ -13273,91 +13133,6 @@ "node": ">=16.13" } }, - "node_modules/miniflare/node_modules/@cloudflare/workerd-darwin-64": { - "version": "1.20250129.0", - "resolved": "https://registry.npmjs.org/@cloudflare/workerd-darwin-64/-/workerd-darwin-64-1.20250129.0.tgz", - "integrity": "sha512-M+xETVnl+xy2dfDDWmp0XXr2rttl70a6bljQygl0EmYmNswFTcYbQWCaBuNBo9kabU59rLKr4a/b3QZ07NoL/g==", - "cpu": [ - "x64" - ], - "dev": true, - "license": "Apache-2.0", - "optional": true, - "os": [ - "darwin" - ], - "engines": { - "node": ">=16" - } - }, - "node_modules/miniflare/node_modules/@cloudflare/workerd-darwin-arm64": { - "version": "1.20250129.0", - "resolved": "https://registry.npmjs.org/@cloudflare/workerd-darwin-arm64/-/workerd-darwin-arm64-1.20250129.0.tgz", - "integrity": "sha512-c4PQUyIMp+bCMxZkAMBzXgTHjRZxeYCujDbb3staestqgRbenzcfauXsMd6np35ng+EE1uBgHNPV4+7fC0ZBfg==", - "cpu": [ - "arm64" - ], - "dev": true, - "license": "Apache-2.0", - "optional": true, - "os": [ - "darwin" - ], - "engines": { - "node": ">=16" - } - }, - "node_modules/miniflare/node_modules/@cloudflare/workerd-linux-64": { - "version": "1.20250129.0", - "resolved": "https://registry.npmjs.org/@cloudflare/workerd-linux-64/-/workerd-linux-64-1.20250129.0.tgz", - "integrity": "sha512-xJx8LwWFxsm5U3DETJwRuOmT5RWBqm4FmA4itYXvcEICca9pWJDB641kT4PnpypwDNmYOebhU7A+JUrCRucG0w==", - "cpu": [ - "x64" - ], - "dev": true, - "license": "Apache-2.0", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=16" - } - }, - "node_modules/miniflare/node_modules/@cloudflare/workerd-linux-arm64": { - "version": "1.20250129.0", - "resolved": "https://registry.npmjs.org/@cloudflare/workerd-linux-arm64/-/workerd-linux-arm64-1.20250129.0.tgz", - "integrity": "sha512-dR//npbaX5p323huBVNIy5gaWubQx6CC3aiXeK0yX4aD5ar8AjxQFb2U/Sgjeo65Rkt53hJWqC7IwRpK/eOxrA==", - "cpu": [ - "arm64" - ], - "dev": true, - "license": "Apache-2.0", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=16" - } - }, - "node_modules/miniflare/node_modules/@cloudflare/workerd-windows-64": { - "version": "1.20250129.0", - "resolved": "https://registry.npmjs.org/@cloudflare/workerd-windows-64/-/workerd-windows-64-1.20250129.0.tgz", - "integrity": "sha512-OeO+1nPj/ocAE3adFar/tRFGRkbCrBnrOYXq0FUBSpyNHpDdA9/U3PAw5CN4zvjfTnqXZfTxTFeqoruqzRzbtg==", - "cpu": [ - "x64" - ], - "dev": true, - "license": "Apache-2.0", - "optional": true, - "os": [ - "win32" - ], - "engines": { - "node": ">=16" - } - }, "node_modules/miniflare/node_modules/undici": { "version": "5.28.5", "resolved": "https://registry.npmjs.org/undici/-/undici-5.28.5.tgz", @@ -13371,27 +13146,6 @@ "node": ">=14.0" } }, - "node_modules/miniflare/node_modules/workerd": { - "version": "1.20250129.0", - "resolved": "https://registry.npmjs.org/workerd/-/workerd-1.20250129.0.tgz", - "integrity": "sha512-Rprz8rxKTF4l6q/nYYI07lBetJnR19mGipx+u/a27GZOPKMG5SLIzA2NciZlJaB2Qd5YY+4p/eHOeKqo5keVWA==", - "dev": true, - "hasInstallScript": true, - "license": "Apache-2.0", - "bin": { - "workerd": "bin/workerd" - }, - "engines": { - "node": ">=16" - }, - "optionalDependencies": { - "@cloudflare/workerd-darwin-64": "1.20250129.0", - "@cloudflare/workerd-darwin-arm64": "1.20250129.0", - "@cloudflare/workerd-linux-64": "1.20250129.0", - "@cloudflare/workerd-linux-arm64": "1.20250129.0", - "@cloudflare/workerd-windows-64": "1.20250129.0" - } - }, "node_modules/minimatch": { "version": "9.0.5", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.5.tgz", @@ -17769,15 +17523,14 @@ "license": "MIT" }, "node_modules/unenv": { - "name": "unenv-nightly", - "version": "2.0.0-20250109-100802-88ad671", - "resolved": "https://registry.npmjs.org/unenv-nightly/-/unenv-nightly-2.0.0-20250109-100802-88ad671.tgz", - "integrity": "sha512-Uij6gODNNNNsNBoDlnaMvZI99I6YlVJLRfYH8AOLMlbFrW7k2w872v9VLuIdch2vF8QBeSC4EftIh5sG4ibzdA==", + "version": "2.0.0-rc.1", + "resolved": "https://registry.npmjs.org/unenv/-/unenv-2.0.0-rc.1.tgz", + "integrity": "sha512-PU5fb40H8X149s117aB4ytbORcCvlASdtF97tfls4BPIyj4PeVxvpSuy1jAptqYHqB0vb2w2sHvzM0XWcp2OKg==", "dev": true, "license": "MIT", "dependencies": { "defu": "^6.1.4", - "mlly": "^1.7.3", + "mlly": "^1.7.4", "ohash": "^1.1.4", "pathe": "^1.1.2", "ufo": "^1.5.4" @@ -19277,9 +19030,9 @@ } }, "node_modules/workerd": { - "version": "1.20241230.0", - "resolved": "https://registry.npmjs.org/workerd/-/workerd-1.20241230.0.tgz", - "integrity": "sha512-EgixXP0JGXGq6J9lz17TKIZtfNDUvJNG+cl9paPMfZuYWT920fFpBx+K04YmnbQRLnglsivF1GT9pxh1yrlWhg==", + "version": "1.20250129.0", + "resolved": "https://registry.npmjs.org/workerd/-/workerd-1.20250129.0.tgz", + "integrity": "sha512-Rprz8rxKTF4l6q/nYYI07lBetJnR19mGipx+u/a27GZOPKMG5SLIzA2NciZlJaB2Qd5YY+4p/eHOeKqo5keVWA==", "dev": true, "hasInstallScript": true, "license": "Apache-2.0", @@ -19290,17 +19043,17 @@ "node": ">=16" }, "optionalDependencies": { - "@cloudflare/workerd-darwin-64": "1.20241230.0", - "@cloudflare/workerd-darwin-arm64": "1.20241230.0", - "@cloudflare/workerd-linux-64": "1.20241230.0", - "@cloudflare/workerd-linux-arm64": "1.20241230.0", - "@cloudflare/workerd-windows-64": "1.20241230.0" + "@cloudflare/workerd-darwin-64": "1.20250129.0", + "@cloudflare/workerd-darwin-arm64": "1.20250129.0", + "@cloudflare/workerd-linux-64": "1.20250129.0", + "@cloudflare/workerd-linux-arm64": "1.20250129.0", + "@cloudflare/workerd-windows-64": "1.20250129.0" } }, "node_modules/wrangler": { - "version": "3.103.2", - "resolved": "https://registry.npmjs.org/wrangler/-/wrangler-3.103.2.tgz", - "integrity": "sha512-eYcnubPhPBU1QMZYTam+vfCLpaQx+x1EWA6nFbLhid1eqNDAk1dNwNlbo+ZryrOHDEX3XlOxn2Z3Fx8vVv3hKw==", + "version": "3.107.3", + "resolved": "https://registry.npmjs.org/wrangler/-/wrangler-3.107.3.tgz", + "integrity": "sha512-N9ZMDHZ+DI5/B0yclr3bG57U/Zw7wSzGdpO2l7j6+3q8yUf+4Fk0Rvneo2t8rjLewKlvqgt9D9siFuo8MXJ55Q==", "dev": true, "license": "MIT OR Apache-2.0", "dependencies": { @@ -19309,10 +19062,10 @@ "@esbuild-plugins/node-modules-polyfill": "0.2.2", "blake3-wasm": "2.1.5", "esbuild": "0.17.19", - "miniflare": "3.20241230.2", + "miniflare": "3.20250129.0", "path-to-regexp": "6.3.0", - "unenv": "npm:unenv-nightly@2.0.0-20250109-100802-88ad671", - "workerd": "1.20241230.0" + "unenv": "2.0.0-rc.1", + "workerd": "1.20250129.0" }, "bin": { "wrangler": "bin/wrangler.js", @@ -19325,7 +19078,7 @@ "fsevents": "~2.3.2" }, "peerDependencies": { - "@cloudflare/workers-types": "^4.20241230.0" + "@cloudflare/workers-types": "^4.20250129.0" }, "peerDependenciesMeta": { "@cloudflare/workers-types": { @@ -19333,46 +19086,6 @@ } } }, - "node_modules/wrangler/node_modules/miniflare": { - "version": "3.20241230.2", - "resolved": "https://registry.npmjs.org/miniflare/-/miniflare-3.20241230.2.tgz", - "integrity": "sha512-gFC3IaUKrLGdtA6y6PLpC/QE5YAjB5ITCfBZHkosRyFZ9ApaCHKcHRvrEFMc/R19QxxtHD+G3tExEHp7MmtsYQ==", - "dev": true, - "license": "MIT", - "dependencies": { - "@cspotcode/source-map-support": "0.8.1", - "acorn": "^8.8.0", - "acorn-walk": "^8.2.0", - "capnp-ts": "^0.7.0", - "exit-hook": "^2.2.1", - "glob-to-regexp": "^0.4.1", - "stoppable": "^1.1.0", - "undici": "^5.28.4", - "workerd": "1.20241230.0", - "ws": "^8.18.0", - "youch": "^3.2.2", - "zod": "^3.22.3" - }, - "bin": { - "miniflare": "bootstrap.js" - }, - "engines": { - "node": ">=16.13" - } - }, - "node_modules/wrangler/node_modules/undici": { - "version": "5.28.5", - "resolved": "https://registry.npmjs.org/undici/-/undici-5.28.5.tgz", - "integrity": "sha512-zICwjrDrcrUE0pyyJc1I2QzBkLM8FINsgOrt6WjA+BgajVq9Nxu2PbFFXUrAggLfDXlZGZBVZYw7WNV5KiBiBA==", - "dev": true, - "license": "MIT", - "dependencies": { - "@fastify/busboy": "^2.0.0" - }, - "engines": { - "node": ">=14.0" - } - }, "node_modules/wrap-ansi": { "version": "9.0.0", "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-9.0.0.tgz", diff --git a/package.json b/package.json index 3177bf305b119e3..77efd553b8920ff 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,7 @@ "@astrojs/starlight-tailwind": "3.0.0", "@astrojs/tailwind": "5.1.5", "@cloudflare/vitest-pool-workers": "0.6.11", - "@cloudflare/workers-types": "4.20250121.0", + "@cloudflare/workers-types": "4.20250204.0", "@codingheads/sticky-header": "1.0.2", "@expressive-code/plugin-collapsible-sections": "0.40.1", "@iarna/toml": "2.2.5", @@ -107,7 +107,7 @@ "unist-util-visit": "5.0.0", "vite-tsconfig-paths": "5.1.4", "vitest": "2.1.6", - "wrangler": "3.103.2" + "wrangler": "3.107.3" }, "engines": { "node": ">=22" From 1d67dd0fb901e5c1c36c707ad0db329e28754d12 Mon Sep 17 00:00:00 2001 From: Kian Newman-Hazel Date: Fri, 7 Feb 2025 09:42:43 +0000 Subject: [PATCH 05/12] use same logic for creating subdomain --- bin/post-preview-url-comment/index.node.test.ts | 16 +++++++++++++++- bin/post-preview-url-comment/index.ts | 4 ++-- bin/post-preview-url-comment/util.ts | 9 +++++++-- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/bin/post-preview-url-comment/index.node.test.ts b/bin/post-preview-url-comment/index.node.test.ts index 1ca15174c15b9e4..c4c4e3469999aae 100644 --- a/bin/post-preview-url-comment/index.node.test.ts +++ b/bin/post-preview-url-comment/index.node.test.ts @@ -1,6 +1,6 @@ import { describe, expect, test } from "vitest"; import { DOCS_BASE_URL, PREVIEW_URL_REGEX } from "./constants"; -import { filenameToPath } from "./util"; +import { filenameToPath, branchToSubdomain } from "./util"; test("PREVIEW_URL_REGEX", () => { const comment = @@ -13,6 +13,20 @@ test("PREVIEW_URL_REGEX", () => { ); }); +describe("branchToSubdomain", () => { + test("slash", () => { + expect(branchToSubdomain("kian/pcx-15803")).toEqual("kian-pcx-15803"); + }); + + test("normal", () => { + expect(branchToSubdomain("pcx-15803")).toEqual("pcx-15803"); + }); + + test("capitalisation", () => { + expect(branchToSubdomain("PCX-15803")).toEqual("pcx-15803"); + }); +}); + describe("filenameToPath", () => { test("index", () => { expect(filenameToPath("src/content/docs/workers/index.mdx")).toEqual( diff --git a/bin/post-preview-url-comment/index.ts b/bin/post-preview-url-comment/index.ts index 067aca666b331ff..de97254772a5d3d 100644 --- a/bin/post-preview-url-comment/index.ts +++ b/bin/post-preview-url-comment/index.ts @@ -8,7 +8,7 @@ import { PREVIEW_URL_REGEX, } from "./constants"; -import { filenameToPath, slug } from "./util"; +import { filenameToPath, branchToSubdomain } from "./util"; async function run(): Promise { try { @@ -51,7 +51,7 @@ async function run(): Promise { ); const previewUrl = { - branch: `https://${slug(process.env.GITHUB_REF_NAME)}.preview.developers.cloudflare.com`, + branch: `https://${branchToSubdomain(process.env.GITHUB_REF_NAME)}.preview.developers.cloudflare.com`, commit: `https://${ctx.sha.slice(0, 8)}.preview.developers.cloudflare.com`, }; diff --git a/bin/post-preview-url-comment/util.ts b/bin/post-preview-url-comment/util.ts index e63f5fe5a0929a3..1640e482569c7ff 100644 --- a/bin/post-preview-url-comment/util.ts +++ b/bin/post-preview-url-comment/util.ts @@ -1,5 +1,5 @@ import { slug } from "github-slugger"; - +import { execSync } from "node:child_process"; import { CONTENT_BASE_PATH } from "./constants"; export const filenameToPath = (filename: string) => { @@ -30,4 +30,9 @@ export const filenameToPath = (filename: string) => { .concat("/"); }; -export { slug }; +export const branchToSubdomain = (branch: string) => { + return execSync( + `echo "${branch}" | iconv -c -t ascii//TRANSLIT | sed -E 's/[~^]+//g' | sed -E 's/[^a-zA-Z0-9]+/-/g' | sed -E 's/^-+|-+$//g' | tr A-Z a-z`, + { encoding: "utf-8" }, + ).trim(); +}; From c824f860c8a326984154eea4169dc3ae28c73592 Mon Sep 17 00:00:00 2001 From: Kian Newman-Hazel Date: Fri, 7 Feb 2025 09:56:12 +0000 Subject: [PATCH 06/12] change a file --- src/content/docs/workers/get-started/guide.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/docs/workers/get-started/guide.mdx b/src/content/docs/workers/get-started/guide.mdx index 0f27ef2688fe997..2fd2f8b69b74978 100644 --- a/src/content/docs/workers/get-started/guide.mdx +++ b/src/content/docs/workers/get-started/guide.mdx @@ -9,7 +9,7 @@ head: --- import { Details, Render, PackageManagers } from "~/components"; - +Test. Set up and deploy your first Worker with Wrangler, the Cloudflare Developer Platform CLI. This guide will instruct you through setting up and deploying your first Worker. From 9a3f38586bb928c4f9b2973e3c1cad5dd49bb62f Mon Sep 17 00:00:00 2001 From: Kian Newman-Hazel Date: Fri, 7 Feb 2025 10:02:48 +0000 Subject: [PATCH 07/12] change a file --- src/content/docs/workers/get-started/guide.mdx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/content/docs/workers/get-started/guide.mdx b/src/content/docs/workers/get-started/guide.mdx index 2fd2f8b69b74978..e4d16ec7065fd19 100644 --- a/src/content/docs/workers/get-started/guide.mdx +++ b/src/content/docs/workers/get-started/guide.mdx @@ -9,7 +9,9 @@ head: --- import { Details, Render, PackageManagers } from "~/components"; + Test. + Set up and deploy your first Worker with Wrangler, the Cloudflare Developer Platform CLI. This guide will instruct you through setting up and deploying your first Worker. From e9c79bc323aa29641e8e4f7ea177893be25fdac2 Mon Sep 17 00:00:00 2001 From: Kian Newman-Hazel Date: Fri, 7 Feb 2025 10:13:59 +0000 Subject: [PATCH 08/12] newlines --- bin/post-preview-url-comment/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/post-preview-url-comment/index.ts b/bin/post-preview-url-comment/index.ts index de97254772a5d3d..67dabe0824981ed 100644 --- a/bin/post-preview-url-comment/index.ts +++ b/bin/post-preview-url-comment/index.ts @@ -75,10 +75,10 @@ async function run(): Promise { return { original, preview }; }); - let comment = `**Preview URL:** ${previewUrl.branch}`; + let comment = `**Preview URL:** ${previewUrl.commit}\n**Preview Branch URL:** ${previewUrl.branch}`; if (changedFiles.length !== 0) { comment = comment.concat( - `**Files with changes (up to 15)**\n\n| Original Link | Updated Link |\n| --- | --- |\n${changedFiles + `\n\n**Files with changes (up to 15)**\n\n| Original Link | Updated Link |\n| --- | --- |\n${changedFiles .map( (file) => `| [${file.original}](${file.original}) | [${file.preview}](${file.preview}) |`, From 36d317b5a8a23d84c8b09bf4c219c9510e63e500 Mon Sep 17 00:00:00 2001 From: Kian Newman-Hazel Date: Fri, 7 Feb 2025 11:12:44 +0000 Subject: [PATCH 09/12] change a different file --- src/content/docs/workers/get-started/guide.mdx | 2 -- src/content/docs/workers/get-started/quickstarts.mdx | 2 ++ 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/content/docs/workers/get-started/guide.mdx b/src/content/docs/workers/get-started/guide.mdx index e4d16ec7065fd19..0f27ef2688fe997 100644 --- a/src/content/docs/workers/get-started/guide.mdx +++ b/src/content/docs/workers/get-started/guide.mdx @@ -10,8 +10,6 @@ head: import { Details, Render, PackageManagers } from "~/components"; -Test. - Set up and deploy your first Worker with Wrangler, the Cloudflare Developer Platform CLI. This guide will instruct you through setting up and deploying your first Worker. diff --git a/src/content/docs/workers/get-started/quickstarts.mdx b/src/content/docs/workers/get-started/quickstarts.mdx index 89edac9a9cecbb1..a603023e91ee98d 100644 --- a/src/content/docs/workers/get-started/quickstarts.mdx +++ b/src/content/docs/workers/get-started/quickstarts.mdx @@ -11,6 +11,8 @@ description: GitHub repositories that are designed to be a starting point for import { LinkButton, WorkerStarter } from "~/components"; +Test. + Quickstarts are GitHub repositories that are designed to be a starting point for building a new Cloudflare Workers project. To start any of the projects below, run: ```sh From 91535c960488b9aab7c62d1869f5ce5b50ac63e6 Mon Sep 17 00:00:00 2001 From: Kian Newman-Hazel Date: Fri, 7 Feb 2025 11:34:19 +0000 Subject: [PATCH 10/12] move debug logs to normal logs --- .../index.node.test.ts | 25 ++++++++++++------ bin/post-preview-url-comment/index.ts | 26 +++++++++++++++++-- 2 files changed, 41 insertions(+), 10 deletions(-) diff --git a/bin/post-preview-url-comment/index.node.test.ts b/bin/post-preview-url-comment/index.node.test.ts index c4c4e3469999aae..e2549d0e2f0a7ae 100644 --- a/bin/post-preview-url-comment/index.node.test.ts +++ b/bin/post-preview-url-comment/index.node.test.ts @@ -2,15 +2,24 @@ import { describe, expect, test } from "vitest"; import { DOCS_BASE_URL, PREVIEW_URL_REGEX } from "./constants"; import { filenameToPath, branchToSubdomain } from "./util"; -test("PREVIEW_URL_REGEX", () => { - const comment = - "**Preview URL:** https://ac148943-cloudflare-docs.cloudflare-docs.workers.dev"; - const matches = comment.match(PREVIEW_URL_REGEX); +describe("PREVIEW_URL_REGEX", () => { + test("no changed files", () => { + const comment = + "**Preview URL:** https://e9c79bc3.preview.developers.cloudflare.com\n**Preview Branch URL:** https://kian-pcx-15803.preview.developers.cloudflare.com"; - expect(matches).toBeDefined(); - expect(matches![1]).toEqual( - "https://ac148943-cloudflare-docs.cloudflare-docs.workers.dev", - ); + expect(PREVIEW_URL_REGEX.test(comment)).toBe(true); + }); + + test("changed files", () => { + const comment = + "**Preview URL:** https://e9c79bc3.preview.developers.cloudflare.com\n**Preview Branch URL:** https://kian-pcx-15803.preview.developers.cloudflare.com\n\n**Files with changes (up to 15)**\n\n| Original Link | Updated Link |\n| --- | --- |\n| [https://developers.cloudflare.com/workers/get-started/guide/](https://developers.cloudflare.com/workers/get-started/guide/) | [https://kian-pcx-15803.preview.developers.cloudflare.com/workers/get-started/guide/](https://kian-pcx-15803.preview.developers.cloudflare.com/workers/get-started/guide/) |"; + + expect(PREVIEW_URL_REGEX.test(comment)).toBe(true); + }); + + test("empty", () => { + expect(PREVIEW_URL_REGEX.test("")).toBe(false); + }); }); describe("branchToSubdomain", () => { diff --git a/bin/post-preview-url-comment/index.ts b/bin/post-preview-url-comment/index.ts index 67dabe0824981ed..f472df9c81beffb 100644 --- a/bin/post-preview-url-comment/index.ts +++ b/bin/post-preview-url-comment/index.ts @@ -20,6 +20,8 @@ async function run(): Promise { const octokit = github.getOctokit(process.env.GITHUB_TOKEN); const ctx = github.context; + core.info(`Finding pull requests for ${ctx.ref}`); + const { data: pulls } = await octokit.rest.pulls.list({ ...ctx.repo, head: ctx.ref, @@ -32,12 +34,16 @@ async function run(): Promise { process.exit(); } + core.info(`Found ${pull_number}`); + const files = await octokit.paginate(octokit.rest.pulls.listFiles, { ...ctx.repo, pull_number, per_page: 100, }); + core.info(`Found ${files.length} changed files for ${pull_number}`); + const { data: comments } = await octokit.rest.issues.listComments({ ...ctx.repo, issue_number: pull_number, @@ -50,12 +56,20 @@ async function run(): Promise { PREVIEW_URL_REGEX.test(comment.body ?? ""), ); + if (existingComment) { + core.info(`Found existing comment with ID ${existingComment.id}`); + } else { + core.info(`No existing comment found`); + } + const previewUrl = { branch: `https://${branchToSubdomain(process.env.GITHUB_REF_NAME)}.preview.developers.cloudflare.com`, commit: `https://${ctx.sha.slice(0, 8)}.preview.developers.cloudflare.com`, }; - core.debug(JSON.stringify(previewUrl)); + core.info( + `Commit URL: ${previewUrl.commit}\nBranch URL:${previewUrl.branch}`, + ); const changedFiles = files .filter( @@ -70,13 +84,17 @@ async function run(): Promise { const original = `${DOCS_BASE_URL}/${filenameToPath(filename)}`; const preview = `${previewUrl.branch}/${filenameToPath(filename)}`; - core.debug([filename, original, preview].toString()); + core.info( + `Filename: ${filename}\nOriginal: ${original}\nPreview: ${preview}`, + ); return { original, preview }; }); let comment = `**Preview URL:** ${previewUrl.commit}\n**Preview Branch URL:** ${previewUrl.branch}`; if (changedFiles.length !== 0) { + core.info(`Found ${changedFiles.length} after filtering paths`); + comment = comment.concat( `\n\n**Files with changes (up to 15)**\n\n| Original Link | Updated Link |\n| --- | --- |\n${changedFiles .map( @@ -88,6 +106,9 @@ async function run(): Promise { } if (existingComment) { + core.info( + `Updating ${existingComment.id} with ${JSON.stringify(comment)}`, + ); await octokit.rest.issues.updateComment({ owner: ctx.repo.owner, repo: ctx.repo.repo, @@ -95,6 +116,7 @@ async function run(): Promise { body: comment, }); } else { + core.info(`Creating new comment with ${JSON.stringify(comment)}`); await octokit.rest.issues.createComment({ owner: ctx.repo.owner, repo: ctx.repo.repo, From b60c0f389dbfbd12302cbd2e8da982fa892e8a4e Mon Sep 17 00:00:00 2001 From: Kian Newman-Hazel Date: Fri, 7 Feb 2025 12:42:17 +0000 Subject: [PATCH 11/12] fix pr list filter --- bin/post-preview-url-comment/index.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/bin/post-preview-url-comment/index.ts b/bin/post-preview-url-comment/index.ts index f472df9c81beffb..5430a0f762f8984 100644 --- a/bin/post-preview-url-comment/index.ts +++ b/bin/post-preview-url-comment/index.ts @@ -12,19 +12,20 @@ import { filenameToPath, branchToSubdomain } from "./util"; async function run(): Promise { try { - if (!process.env.GITHUB_TOKEN || !process.env.GITHUB_REF_NAME) { - core.setFailed(`Could not find GITHUB_TOKEN or GITHUB_REF_NAME in env`); + if (!process.env.GITHUB_TOKEN) { + core.setFailed(`Could not find GITHUB_TOKEN in env`); process.exit(); } const octokit = github.getOctokit(process.env.GITHUB_TOKEN); const ctx = github.context; + const branch = ctx.ref.replace("refs/heads/", ""); core.info(`Finding pull requests for ${ctx.ref}`); const { data: pulls } = await octokit.rest.pulls.list({ ...ctx.repo, - head: ctx.ref, + head: `${ctx.repo.owner}:${branch}`, }); const pull_number = pulls.at(0)?.number; @@ -63,12 +64,12 @@ async function run(): Promise { } const previewUrl = { - branch: `https://${branchToSubdomain(process.env.GITHUB_REF_NAME)}.preview.developers.cloudflare.com`, + branch: `https://${branchToSubdomain(branch)}.preview.developers.cloudflare.com`, commit: `https://${ctx.sha.slice(0, 8)}.preview.developers.cloudflare.com`, }; core.info( - `Commit URL: ${previewUrl.commit}\nBranch URL:${previewUrl.branch}`, + `Commit URL: ${previewUrl.commit}\nBranch URL: ${previewUrl.branch}`, ); const changedFiles = files From 86c5a59d68b967c9e46b263de40a19793361716e Mon Sep 17 00:00:00 2001 From: Kian Newman-Hazel Date: Fri, 7 Feb 2025 13:41:29 +0000 Subject: [PATCH 12/12] Remove test --- src/content/docs/workers/get-started/quickstarts.mdx | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/content/docs/workers/get-started/quickstarts.mdx b/src/content/docs/workers/get-started/quickstarts.mdx index a603023e91ee98d..89edac9a9cecbb1 100644 --- a/src/content/docs/workers/get-started/quickstarts.mdx +++ b/src/content/docs/workers/get-started/quickstarts.mdx @@ -11,8 +11,6 @@ description: GitHub repositories that are designed to be a starting point for import { LinkButton, WorkerStarter } from "~/components"; -Test. - Quickstarts are GitHub repositories that are designed to be a starting point for building a new Cloudflare Workers project. To start any of the projects below, run: ```sh