Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(workflows/build): use static robots.txt #12495

Merged
merged 5 commits into from
Feb 20, 2025
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
3 changes: 2 additions & 1 deletion .github/workflows/prod-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,8 @@ jobs:
yarn build:sw
yarn build:client
yarn build:ssr
yarn tool:legacy build-robots-txt
cp assets/prod/robots.txt client/build/robots.txt
yarn rari content sync-translated-content
yarn rari git-history
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/stage-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,8 @@ jobs:
yarn build:sw
yarn build:client
yarn build:ssr
yarn tool:legacy build-robots-txt
cp assets/nonprod/robots.txt client/build/robots.txt
yarn rari content sync-translated-content
yarn rari git-history
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/test-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,8 @@ jobs:
yarn build:sw
yarn build:client
yarn build:ssr
yarn tool:legacy build-robots-txt

cp assets/nonprod/robots.txt client/build/robots.txt

yarn rari content sync-translated-content
yarn rari git-history
Expand Down
3 changes: 3 additions & 0 deletions assets/nonprod/robots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
User-Agent: *

Disallow: /
6 changes: 6 additions & 0 deletions assets/prod/robots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
User-agent: *
Sitemap: https://developer.mozilla.org/sitemap.xml

Disallow: /api/
Disallow: /*/files/
Disallow: /media
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
"build:legacy::curriculum": "cross-env NODE_ENV=production NODE_OPTIONS=\"--no-warnings=ExperimentalWarning --loader ts-node/esm\" node build/build-curriculum.ts",
"build:legacy::docs": "cross-env NODE_ENV=production NODE_OPTIONS=\"--no-warnings=ExperimentalWarning --loader ts-node/esm\" node build/cli.ts -n",
"build:legacy:blog": "cross-env NODE_ENV=production NODE_OPTIONS=\"--no-warnings=ExperimentalWarning --loader ts-node/esm\" node build/build-blog.ts",
"build:legacy:prepare": "yarn build:client && yarn build:ssr && yarn tool:legacy popularities && yarn tool:legacy spas && yarn tool:legacy gather-git-history && yarn tool:legacy build-robots-txt",
"build:prepare": "yarn build:client && yarn build:ssr && yarn tool:legacy build-robots-txt",
"build:legacy:prepare": "yarn build:client && yarn build:ssr && yarn tool:legacy popularities && yarn tool:legacy spas && yarn tool:legacy gather-git-history",
"build:prepare": "yarn build:client && yarn build:ssr",
"build:ssr": "cross-env NODE_ENV=production NODE_OPTIONS=\"--no-warnings=ExperimentalWarning --loader ts-node/esm\" node ssr/prepare.ts && webpack --mode=production --config=ssr/webpack.config.js",
"build:sw": "cd client/pwa && yarn && yarn build:prod",
"build:sw-dev": "cd client/pwa && yarn && yarn build",
Expand Down
11 changes: 0 additions & 11 deletions testing/tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1177,17 +1177,6 @@ test("built search-index.json (en-US)", () => {
expect(urlToTitle.get("/en-US/docs/Web/Foo")).toBe("<foo>: A test tag");
});

test("the robots.txt file was created", () => {
const filePath = path.join(buildRoot, "robots.txt");
const text = fs.readFileSync(filePath, "utf-8");
// The content of robots file when it's in production mode is
// to ONLY say `Disallow: /api/`.
// When the robots file is for disallowing everything it
// will ONLY say `Disallow: /`.
expect(text).toContain("Disallow: /api/");
expect(text).not.toContain("Disallow: /\n");
});

test("duplicate IDs are de-duplicated", () => {
const builtFolder = path.join(
buildRoot,
Expand Down
28 changes: 0 additions & 28 deletions tool/build-robots-txt.ts

This file was deleted.

33 changes: 0 additions & 33 deletions tool/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,11 @@ import { buildDocument, gatherGitHistory, buildSPAs } from "../build/index.js";
import { isValidLocale } from "../libs/locale-utils/index.js";
import type { Doc } from "../libs/types/document.js";
import {
ALWAYS_ALLOW_ROBOTS,
BUILD_OUT_ROOT,
CONTENT_ROOT,
CONTENT_TRANSLATED_ROOT,
} from "../libs/env/index.js";
import { runMakePopularitiesFile } from "./popularities.js";
import { runBuildRobotsTxt } from "./build-robots-txt.js";
import { syncAllTranslatedContent } from "./sync-translated-content.js";
import { macroUsageReport } from "./macro-usage-report.js";
import * as kumascript from "../kumascript/index.js";
Expand Down Expand Up @@ -176,15 +174,6 @@ interface PopularitiesActionParameters extends ActionParameters {
logger: Logger;
}

interface BuildRobotsTxtActionParameters extends ActionParameters {
options: {
outfile: string;
maxUris: number;
refresh: boolean;
};
logger: Logger;
}

interface MacrosActionParameters extends ActionParameters {
args: {
cmd: string;
Expand Down Expand Up @@ -869,28 +858,6 @@ program
})
)

.command(
"build-robots-txt",
"Generate a robots.txt in the build root depending ALWAYS_ALLOW_ROBOTS"
)
.option("--outfile <path>", "name of the generated file", {
default: path.join(BUILD_OUT_ROOT, "robots.txt"),
})
.action(
tryOrExit(async ({ options, logger }: BuildRobotsTxtActionParameters) => {
const { outfile } = options;
await runBuildRobotsTxt(outfile);
logger.info(
chalk.yellow(
`Generated ${path.relative(
".",
outfile
)} based on ALWAYS_ALLOW_ROBOTS=${ALWAYS_ALLOW_ROBOTS}`
)
);
})
)

.command("spas", "Build (SSR) all the skeleton apps for single page apps")
.action(
tryOrExit(async ({ options }) => {
Expand Down
Loading