Skip to content

Commit 0db8ee5

Browse files
Merge branch 'production' of https://github.com/cloudflare/cloudflare-docs into production
2 parents d073e02 + 2fe7819 commit 0db8ee5

File tree

176 files changed

+4564
-32093
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

176 files changed

+4564
-32093
lines changed

.github/workflows/ci.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,10 @@ jobs:
5757

5858
- name: Tests
5959
run: npm run test
60+
61+
- name: Post PR CI failure comment
62+
if: always()
63+
continue-on-error: true
64+
env:
65+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
66+
run: npx tsx bin/post-pr-ci-failure-comment/index.ts

.github/workflows/publish-preview.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ concurrency:
99

1010
jobs:
1111
publish:
12+
if: github.repository == 'cloudflare/cloudflare-docs'
1213
runs-on: ubuntu-22.04
1314
permissions:
1415
contents: read

astro.config.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,21 @@ async function autogenSections() {
3737
});
3838
}
3939

40+
async function autogenStyles() {
41+
const styles = (
42+
await readdir("./src/styles/", {
43+
withFileTypes: true,
44+
recursive: true,
45+
})
46+
)
47+
.filter((x) => x.isFile())
48+
.map((x) => x.parentPath + x.name);
49+
50+
return styles;
51+
}
52+
4053
const sidebar = await autogenSections();
54+
const customCss = await autogenStyles();
4155

4256
const runLinkCheck = process.env.RUN_LINK_CHECK || false;
4357

@@ -97,18 +111,7 @@ export default defineConfig({
97111
TableOfContents: "./src/components/overrides/TableOfContents.astro",
98112
},
99113
sidebar,
100-
customCss: [
101-
"./src/asides.css",
102-
"./src/badges.css",
103-
"./src/code.css",
104-
"./src/footnotes.css",
105-
"./src/headings.css",
106-
"./src/input.css",
107-
"./src/mermaid.css",
108-
"./src/table.css",
109-
"./src/tailwind.css",
110-
"./src/title.css",
111-
],
114+
customCss,
112115
pagination: false,
113116
plugins: [
114117
...(runLinkCheck
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export const GITHUB_ACTIONS_BOT_ID = 41898282;
2+
export const DOCS_BASE_URL = "https://developers.cloudflare.com";
3+
export const CONTENT_BASE_PATH = "src/content";
4+
export const PREVIEW_URL_REGEX = /^\*\*Preview URL:\*\* (.*)$/m;
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
import * as core from "@actions/core";
2+
import * as github from "@actions/github";
3+
import type { PullRequestEvent } from "@octokit/webhooks-types";
4+
5+
import { GITHUB_ACTIONS_BOT_ID } from "./constants";
6+
7+
async function run(): Promise<void> {
8+
try {
9+
if (!process.env.GITHUB_TOKEN) {
10+
core.setFailed(`Could not find GITHUB_TOKEN in env`);
11+
process.exit();
12+
}
13+
14+
const octokit = github.getOctokit(process.env.GITHUB_TOKEN);
15+
const payload = github.context.payload as PullRequestEvent;
16+
17+
const { owner, repo } = github.context.repo;
18+
const pullRequestNumber = payload.number;
19+
const runId = github.context.runId;
20+
21+
const { data: run } = await octokit.rest.actions.listJobsForWorkflowRun({
22+
owner,
23+
repo,
24+
run_id: runId,
25+
});
26+
27+
const job = run.jobs.findLast((job) => job.name === "Compiles");
28+
29+
if (!job) {
30+
core.setFailed(`Could not find a job called 'Compiles'`);
31+
process.exit();
32+
}
33+
34+
const failedStep = job.steps?.find((step) => step.conclusion === "failure");
35+
36+
if (failedStep) {
37+
core.info(`Found failed step ${failedStep.name}`);
38+
}
39+
40+
const conclusion = failedStep ? "failure" : "success";
41+
42+
const { data: comments } = await octokit.rest.issues.listComments({
43+
owner,
44+
repo,
45+
issue_number: pullRequestNumber,
46+
per_page: 100,
47+
});
48+
49+
const existingComment = comments.find(
50+
(comment) =>
51+
comment.user?.id === GITHUB_ACTIONS_BOT_ID &&
52+
comment.body?.includes("**CI run failed:**"),
53+
);
54+
55+
if (existingComment) {
56+
core.info(`Found existing comment with ID ${existingComment.id}`);
57+
} else {
58+
core.info(`No existing comment found`);
59+
}
60+
61+
const url = `https://github.com/${owner}/${repo}/actions/runs/${runId}/job/${job.id}`;
62+
const comment = `**CI run failed:** [build logs](${url})`;
63+
64+
if (conclusion === "failure") {
65+
if (existingComment) {
66+
core.info(
67+
`Updating ${existingComment.id} with ${JSON.stringify(comment)}`,
68+
);
69+
await octokit.rest.issues.updateComment({
70+
owner,
71+
repo,
72+
comment_id: existingComment.id,
73+
body: comment,
74+
});
75+
} else {
76+
core.info(`Creating new comment with ${JSON.stringify(comment)}`);
77+
await octokit.rest.issues.createComment({
78+
owner,
79+
repo,
80+
issue_number: pullRequestNumber,
81+
body: comment,
82+
});
83+
}
84+
} else if (conclusion === "success" && existingComment) {
85+
core.info(`Removing ${existingComment.id}`);
86+
await octokit.rest.issues.deleteComment({
87+
owner,
88+
repo,
89+
issue_number: pullRequestNumber,
90+
comment_id: existingComment.id,
91+
});
92+
}
93+
} catch (error) {
94+
if (error instanceof Error) {
95+
core.setFailed(error.message);
96+
}
97+
process.exit();
98+
}
99+
}
100+
101+
run();

0 commit comments

Comments
 (0)