Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
859 changes: 0 additions & 859 deletions .github/actions/show-changed-files/package-lock.json

This file was deleted.

13 changes: 0 additions & 13 deletions .github/actions/show-changed-files/package.json

This file was deleted.

21 changes: 0 additions & 21 deletions .github/actions/show-changed-files/tsconfig.json

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/publish-preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
name: Build
env:
NODE_OPTIONS: --max-old-space-size=4096
- run: npx wrangler versions upload -c ./wrangler-workers.toml
- run: npx wrangler versions upload
name: Deploy to Cloudflare Workers
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
name: Build
env:
NODE_OPTIONS: --max-old-space-size=4096
- run: npx wrangler deploy -c ./wrangler-workers.toml
- run: npx wrangler deploy
name: Deploy to Cloudflare Workers
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/show-changed-files.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,15 @@ on:
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**')
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
- run: cd ./.github/actions/show-changed-files
- uses: actions/setup-node@v4
with:
node-version: 22
cache: "npm"
- run: npm ci
- run: npx tsx index.ts
- run: npx tsx bin/show-changed-files/index.ts
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1 change: 0 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@ dist
public/_redirects
public/analytics/static/downloads/main.css
src/content/workers-ai-models/*.json
tests/fixtures/openapi.json
5 changes: 5 additions & 0 deletions bin/show-changed-files/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +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;
52 changes: 52 additions & 0 deletions bin/show-changed-files/index.node.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { describe, expect, test } from "vitest";
import { DOCS_BASE_URL, PREVIEW_URL_REGEX } from "./constants";
import { filenameToPath } 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);

expect(matches).toBeDefined();
expect(matches![1]).toEqual(
"https://ac148943-cloudflare-docs.cloudflare-docs.workers.dev",
);
});

describe("filenameToPath", () => {
test("index", () => {
expect(filenameToPath("src/content/docs/workers/index.mdx")).toEqual(
"workers/",
);
});

test("index base", () => {
expect(
`${DOCS_BASE_URL}/${filenameToPath("src/content/docs/workers/index.mdx")}`,
).toEqual("https://developers.cloudflare.com/workers/");
});

test("folder", () => {
expect(
filenameToPath("src/content/docs/workers/get-started/cli.mdx"),
).toEqual("workers/get-started/cli/");
});

test("1.1.1.1", () => {
expect(filenameToPath("src/content/docs/1111/index.mdx")).toEqual(
"1.1.1.1/",
);
});

test("changelog", () => {
expect(
filenameToPath("src/content/changelogs-next/2025-02-05-title.mdx"),
).toEqual("changelog/2025-02-05-title/");
});

test("changelog base", () => {
expect(
`${DOCS_BASE_URL}/${filenameToPath("src/content/changelogs-next/2025-02-05-title.mdx")}`,
).toEqual("https://developers.cloudflare.com/changelog/2025-02-05-title/");
});
});
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
import * as core from "@actions/core";
import * as github from "@actions/github";

import { slug } from "github-slugger";
import {
CONTENT_BASE_PATH,
DOCS_BASE_URL,
EXISTING_COMMENT_SUBSTRING,
GITHUB_ACTIONS_BOT_ID,
PREVIEW_URL_REGEX,
} from "./constants";

const GITHUB_ACTIONS_BOT_ID = 41898282;
const DOCS_BASE_URL = "https://developers.cloudflare.com";
const CONTENT_BASE_PATH = "src/content/docs/";
import { filenameToPath } from "./util";

async function run(): Promise<void> {
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`);
process.exit();
}

const issue = ctx.payload.issue.number;

const files = await octokit.paginate(octokit.rest.pulls.listFiles, {
Expand All @@ -30,63 +40,44 @@ async function run(): Promise<void> {

const existingComment = comments.find(
(comment) =>
comment.user.id === GITHUB_ACTIONS_BOT_ID &&
comment.body.includes("| Original Link | Updated Link |"),
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 &&
comment.body.includes("**Preview URL:**"),
comment.user?.id === GITHUB_ACTIONS_BOT_ID &&
PREVIEW_URL_REGEX.test(comment.body ?? ""),
);

let previewUrl: string;

if (urlComment) {
if (!urlComment.body) {
core.setFailed(`${urlComment.id} has no body`);
process.exit();
}

const match = urlComment.body.match(/^\*\*Preview URL:\*\* (.*)$/m)[1];
if (!urlComment || !urlComment.body) {
core.setFailed(
`Could not find a comment from ${GITHUB_ACTIONS_BOT_ID} on ${issue}`,
);
process.exit();
}

if (!match) {
core.setFailed(`Could not extract URL from ${urlComment.body}`);
process.exit();
}
const match = urlComment.body.match(PREVIEW_URL_REGEX);

previewUrl = match;
if (!match) {
core.setFailed(`Could not extract URL from ${urlComment.body}`);
process.exit();
}

const previewUrl = match[1];

core.debug(previewUrl);

const changedFiles = files
.filter(
(file) =>
file.filename.endsWith(".mdx") &&
file.filename.startsWith(CONTENT_BASE_PATH),
(file.filename.startsWith(`${CONTENT_BASE_PATH}/docs/`) ||
file.filename.startsWith(`${CONTENT_BASE_PATH}/changelogs-next/`)),
)
.sort((a, b) => b.changes - a.changes)
.slice(0, 15) // Limit to 15 entries
.map(({ filename }) => {
const filenameToPath = (filename: string) => {
return filename
.replace(".mdx", "")
.split("/")
.map((segment, idx) => {
const slugified = slug(segment);

if (idx === 0 && slugified === "1111") {
return "1.1.1.1";
}

return slugified;
})
.join("/")
.replace(/\/index$/, "")
.concat("/");
};

const original = `${DOCS_BASE_URL}/${filenameToPath(filename)}`;
const preview = `${previewUrl}/${filenameToPath(filename)}`;

Expand Down Expand Up @@ -122,7 +113,9 @@ async function run(): Promise<void> {
});
}
} catch (error) {
core.setFailed(error.message);
if (error instanceof Error) {
core.setFailed(error.message);
}
process.exit();
}
}
Expand Down
31 changes: 31 additions & 0 deletions bin/show-changed-files/util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { slug } from "github-slugger";

import { CONTENT_BASE_PATH } from "./constants";

export const filenameToPath = (filename: string) => {
return filename
.replace(CONTENT_BASE_PATH, "")
.replace(".mdx", "")
.split("/")
.filter(Boolean)
.flatMap((segment) => {
if (segment === "docs") {
return [];
}

if (segment === "changelogs-next") {
segment = "changelog";
}

const slugified = slug(segment);

if (slugified === "1111") {
return "1.1.1.1";
}

return slugified;
})
.join("/")
.replace(/\/index$/, "")
.concat("/");
};
Loading
Loading