diff --git a/.github/workflows/api-links-crawl.yml b/.github/workflows/api-links-crawl.yml deleted file mode 100644 index f15f048411dd81b..000000000000000 --- a/.github/workflows/api-links-crawl.yml +++ /dev/null @@ -1,53 +0,0 @@ -name: Crawl API docs links - -# **What it does**: Regularly audits API links in our documentation. -# **Why we have it**: It's too burdensome to check on every commit like we do for internal links. -# **Who does it impact**: PCX team - -on: - schedule: - - cron: "0 0 * * 0" # Run at 00:00 UTC every Sunday - workflow_dispatch: - -jobs: - compile: - name: Compiles - runs-on: ubuntu-22.04 - steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 1 - - uses: actions/setup-node@v4 - with: - node-version: 20 - - - name: Get npm cache directory - id: npm-cache-dir - shell: bash - run: echo "dir=$(npm config get cache)" >> ${GITHUB_OUTPUT} - - - uses: actions/cache@v4 - id: npm-cache - with: - path: ${{ steps.npm-cache-dir.outputs.dir }} - key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} - restore-keys: | - ${{ runner.os }}-node- - - - name: Install dependencies - run: npm install @actions/core@1 puppeteer@22 - - - name: Run API docs link checker - id: check-api-links - run: npm run crawl-api-links - - - name: Create issue - env: - EXPORTED_VARIABLE: ${{ steps.check-api-links.outputs.brokenLinks }} - if: env.EXPORTED_VARIABLE - run: | - # Create the issue and reference the exported variable - curl --silent -X POST -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ - -H "Accept: application/vnd.github+json" \ - "https://api.github.com/repos/cloudflare/cloudflare-docs/issues" \ - -d "{\"title\": \"Broken API docs links\", \"body\": \"The following API doc links are broken: ${EXPORTED_VARIABLE}\", \"assignees\": [\"haleycode\"]}" diff --git a/bin/crawl-api-links.js b/bin/crawl-api-links.js deleted file mode 100644 index 09c2885e094e0d6..000000000000000 --- a/bin/crawl-api-links.js +++ /dev/null @@ -1,111 +0,0 @@ -import puppeteer from "puppeteer"; -import core from "@actions/core"; - -const navigationTimeout = 120000; // Set the navigation timeout to 120 seconds (120,000 milliseconds) - -function arrayToHTMLList(array) { - let html = ""; - - return html; -} - -async function checkLinks() { - const browser = await puppeteer.launch({ - headless: "new", - }); - const page = await browser.newPage(); - - // skip image requests - await page.setRequestInterception(true); - page.on("request", (request) => { - if (request.resourceType() === "image") request.abort(); - else request.continue(); - }); - - const sitemapUrl = "https://developers.cloudflare.com/sitemap-0.xml"; - await page.goto(sitemapUrl, { timeout: navigationTimeout }); - - const sitemapLinks = await page.$$eval("url loc", (elements) => - elements.map((el) => el.textContent), - ); - - const visitedLinks = []; - const brokenLinks = []; - - for (const link of sitemapLinks) { - if (!link) { - continue; // Skip if the link is empty - } - - try { - await page.goto(link, { - waitUntil: "networkidle0", - timeout: navigationTimeout, - }); - } catch (e) { - console.log( - ` WARNING: Error loading Dev Docs page: ${e.message}... Skipping.`, - ); - continue; - } - - const pageLinks = await page.$$eval("a", (elements) => - elements.map((el) => el.href), - ); - - for (const pageLink of pageLinks) { - if (!pageLink || visitedLinks.includes(pageLink)) { - continue; // Skip if the pageLink is empty or has already been visited - } - - if ( - pageLink.includes("developers.cloudflare.com/api/resources/") || - pageLink.startsWith("/api/resources/") - ) { - console.log(`Evaluating link: ${pageLink}`); - - let response = null; - - try { - response = await page.goto(pageLink, { - waitUntil: "networkidle0", - timeout: navigationTimeout, - }); - visitedLinks.push(pageLink); - } catch (e) { - console.log( - ` WARNING: Error loading API page: ${e.message}... Skipping.`, - ); - continue; - } - - if (response) { - if (response.status() === 404) { - brokenLinks.push(pageLink); - } - } else { - console.log(" WARNING: Didn't receive a response... skipping."); - } - } - } - } - - await browser.close(); - console.log("Broken links:"); - console.log(brokenLinks); - if (brokenLinks.length > 0) { - core.setOutput("brokenLinks", arrayToHTMLList(brokenLinks)); - } - process.exit(0); -} - -checkLinks().catch((error) => { - console.error(error); - process.exit(1); -}); diff --git a/package.json b/package.json index 391b328fe13dded..53080d424a941d9 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,6 @@ "check": "npm run check:astro && npm run check:worker", "check:astro": "npm run sync && astro check", "check:worker": "npm run build:worker && npx tsc --noEmit -p ./worker/tsconfig.json", - "crawl-api-links": "node bin/crawl-api-links.js", "dev": "npx astro dev", "format": "npm run format:core && npm run format:data", "format:core": "npx prettier --write \"**/*.{js,jsx,ts,tsx,mjs,css}\"",