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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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 @@ -249,7 +249,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.

24 changes: 0 additions & 24 deletions tool/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,11 @@
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,7 +174,7 @@
logger: Logger;
}

interface BuildRobotsTxtActionParameters extends ActionParameters {

Check warning on line 177 in tool/cli.ts

View workflow job for this annotation

GitHub Actions / lint

'BuildRobotsTxtActionParameters' is defined but never used
options: {
outfile: string;
maxUris: number;
Expand Down Expand Up @@ -869,28 +867,6 @@
})
)

.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