From 2f9d1ba99d020ecee13958beed8210c151046d23 Mon Sep 17 00:00:00 2001 From: katiegoines Date: Mon, 18 Mar 2024 11:38:50 -0700 Subject: [PATCH 01/12] check console errors --- .../workflows/check_for_console_errors.yml | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 .github/workflows/check_for_console_errors.yml diff --git a/.github/workflows/check_for_console_errors.yml b/.github/workflows/check_for_console_errors.yml new file mode 100644 index 00000000000..3ac44fcf706 --- /dev/null +++ b/.github/workflows/check_for_console_errors.yml @@ -0,0 +1,39 @@ +name: CheckConsoleErrors +on: + pull_request: + branches: [main] + types: [opened, synchronize] +permissions: + contents: read + id-token: write +jobs: + CheckConsoleErrors: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0 https://github.com/actions/checkout/commit/f43a0e5ff2bd294095638e18286ca9a3d1956744 + - name: Setup Node.js 16.x + uses: actions/setup-node@e33196f7422957bea03ed53f6fbb155025ffc7b8 # v3.7.0 https://github.com/actions/setup-node/commit/e33196f7422957bea03ed53f6fbb155025ffc7b8 + with: + node-version: 16.x + - name: Install Dependencies + run: yarn + - name: Run Build + run: yarn build + env: + NODE_OPTIONS: --max_old_space_size=4096 + - name: Run Server + run: | + node ./node_modules/.bin/serve client/www/next-build --no-request-logging & + sleep 5 + - name: Run Console Errors + id: consoleErrors + uses: actions/github-script@d7906e4ad0b1822421a7e6a35d5ca353c962f410 # v6.4.1 https://github.com/actions/github-script/commit/d7906e4ad0b1822421a7e6a35d5ca353c962f410 + with: + result-encoding: string + script: | + const { consoleErrors } = require('./tasks/console-errors.js'); + return await consoleErrors(); + - name: Fail if console errors have been found + if: ${{ steps.consoleErrors.outputs.result }} + run: exit 1 From 7b5f5366aeeeb828193ad65ff017df15b82e627d Mon Sep 17 00:00:00 2001 From: katiegoines Date: Mon, 18 Mar 2024 11:41:19 -0700 Subject: [PATCH 02/12] upgrade node --- .github/workflows/check_for_console_errors.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/check_for_console_errors.yml b/.github/workflows/check_for_console_errors.yml index 3ac44fcf706..87e4ad31a99 100644 --- a/.github/workflows/check_for_console_errors.yml +++ b/.github/workflows/check_for_console_errors.yml @@ -12,10 +12,10 @@ jobs: steps: - name: Checkout repository uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0 https://github.com/actions/checkout/commit/f43a0e5ff2bd294095638e18286ca9a3d1956744 - - name: Setup Node.js 16.x + - name: Setup Node.js 20.x uses: actions/setup-node@e33196f7422957bea03ed53f6fbb155025ffc7b8 # v3.7.0 https://github.com/actions/setup-node/commit/e33196f7422957bea03ed53f6fbb155025ffc7b8 with: - node-version: 16.x + node-version: 20.x - name: Install Dependencies run: yarn - name: Run Build From 8b69a08465e34fe8099d9ea302bf9c89c21fd467 Mon Sep 17 00:00:00 2001 From: katiegoines Date: Mon, 18 Mar 2024 11:49:20 -0700 Subject: [PATCH 03/12] upgrade github-script --- .github/workflows/check_for_console_errors.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check_for_console_errors.yml b/.github/workflows/check_for_console_errors.yml index 87e4ad31a99..1a9c4a7a4ff 100644 --- a/.github/workflows/check_for_console_errors.yml +++ b/.github/workflows/check_for_console_errors.yml @@ -28,7 +28,7 @@ jobs: sleep 5 - name: Run Console Errors id: consoleErrors - uses: actions/github-script@d7906e4ad0b1822421a7e6a35d5ca353c962f410 # v6.4.1 https://github.com/actions/github-script/commit/d7906e4ad0b1822421a7e6a35d5ca353c962f410 + uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 https://github.com/actions/github-script/commit/60a0d83039c74a4aee543508d2ffcb1c3799cdea with: result-encoding: string script: | From ce5c996f6a893bafb4693ef6f16d3c1d0177ad81 Mon Sep 17 00:00:00 2001 From: katiegoines Date: Mon, 18 Mar 2024 11:57:41 -0700 Subject: [PATCH 04/12] update --- tasks/console-errors.js | 83 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 tasks/console-errors.js diff --git a/tasks/console-errors.js b/tasks/console-errors.js new file mode 100644 index 00000000000..04d6bf559bc --- /dev/null +++ b/tasks/console-errors.js @@ -0,0 +1,83 @@ +import { launch } from 'puppeteer'; +import { getSitemapUrls } from './get-sitemap-links'; + +const excludedErrors = [ + { + type: 'Shortbread', + errorText: + "Shortbread failed to set user's cookie preference because the domain name that was passed" + } +]; + +const excludedScripts = [ + 'prod.assets.shortbread.aws', + 'prod.tools.shortbread.aws', + 'aa0.awsstatic.com' +]; + +const checkPage = async (url) => { + const errorsFound = []; + let browser = await launch({ headless: 'new' }); + + const page = await browser.newPage(); + + page + .on('pageerror', (message) => { + let errorText = message.message; + const excluded = excludedErrors.some((excludedError) => { + return errorText.includes(excludedError.errorText); + }); + + if (!excluded) { + errorsFound.push({ + page: url, + message: errorText + }); + } + }) + .on('console', (message) => { + if (message.type().toLowerCase() === 'error') { + let errorText = message.text(); + let callingScript = message.location().url; + const excludedFromError = excludedErrors.some((excludedError) => { + return errorText.includes(excludedError.errorText); + }); + const excludedFromScript = excludedScripts.some((excludedScript) => { + return callingScript.includes(excludedScript); + }); + const excluded = excludedFromError || excludedFromScript; + + if (!excluded) { + errorsFound.push({ + page: url, + message: errorText + }); + } + } + }); + + await page.goto(url, { waitUntil: 'domcontentloaded' }); + + await browser.close(); + + return errorsFound; +}; + +const consoleErrors = async (domain) => { + let pagesToCheck = await getSitemapUrls(domain); + let errorMessage = ''; + for (let i = 0; i < pagesToCheck.length; i++) { + let url = pagesToCheck[i]; + console.log(`checking page ${url}`); + let errorsFound = await checkPage(url); + errorsFound.forEach((error) => { + errorMessage += `${error.message} found on ${error.page}\n`; + }); + } + console.log(errorMessage); + return errorMessage; +}; + +export async function consoleErrors(domain = 'http://localhost:3000') { + return await consoleErrors(domain); +} From f95d8ef5a5058d6bd589943f9d48ff0ab2f80341 Mon Sep 17 00:00:00 2001 From: katiegoines Date: Mon, 18 Mar 2024 12:04:42 -0700 Subject: [PATCH 05/12] change filetype to .mjs --- tasks/{console-errors.js => console-errors.mjs} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tasks/{console-errors.js => console-errors.mjs} (100%) diff --git a/tasks/console-errors.js b/tasks/console-errors.mjs similarity index 100% rename from tasks/console-errors.js rename to tasks/console-errors.mjs From 8462d68387dacf5a983a48b9f9bfd7d5a3ee6619 Mon Sep 17 00:00:00 2001 From: katiegoines Date: Mon, 18 Mar 2024 12:11:05 -0700 Subject: [PATCH 06/12] fix reference --- .github/workflows/check_for_console_errors.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check_for_console_errors.yml b/.github/workflows/check_for_console_errors.yml index 1a9c4a7a4ff..fc343c7f34c 100644 --- a/.github/workflows/check_for_console_errors.yml +++ b/.github/workflows/check_for_console_errors.yml @@ -32,7 +32,7 @@ jobs: with: result-encoding: string script: | - const { consoleErrors } = require('./tasks/console-errors.js'); + const { consoleErrors } = require('./tasks/console-errors.mjs'); return await consoleErrors(); - name: Fail if console errors have been found if: ${{ steps.consoleErrors.outputs.result }} From ac39c681734adf7bb6db993694ced62ca1c1513d Mon Sep 17 00:00:00 2001 From: katiegoines Date: Mon, 18 Mar 2024 12:21:14 -0700 Subject: [PATCH 07/12] . --- .github/CODEOWNERS | 1 + .github/workflows/check_for_console_errors.yml | 2 +- tasks/{console-errors.mjs => console-errors.js} | 6 ++++-- 3 files changed, 6 insertions(+), 3 deletions(-) rename tasks/{console-errors.mjs => console-errors.js} (89%) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 6983aafa2f8..176c38a7465 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -104,6 +104,7 @@ /src/themes @aws-amplify/documentation-team /src/utils @aws-amplify/documentation-team /tasks @aws-amplify/documentation-team +.github @aws-amplify/documentation-team #Protected Content /src/protected @reesscot @srquinn21 @Milan-Shah @swaminator diff --git a/.github/workflows/check_for_console_errors.yml b/.github/workflows/check_for_console_errors.yml index fc343c7f34c..1a9c4a7a4ff 100644 --- a/.github/workflows/check_for_console_errors.yml +++ b/.github/workflows/check_for_console_errors.yml @@ -32,7 +32,7 @@ jobs: with: result-encoding: string script: | - const { consoleErrors } = require('./tasks/console-errors.mjs'); + const { consoleErrors } = require('./tasks/console-errors.js'); return await consoleErrors(); - name: Fail if console errors have been found if: ${{ steps.consoleErrors.outputs.result }} diff --git a/tasks/console-errors.mjs b/tasks/console-errors.js similarity index 89% rename from tasks/console-errors.mjs rename to tasks/console-errors.js index 04d6bf559bc..8c9d36c0496 100644 --- a/tasks/console-errors.mjs +++ b/tasks/console-errors.js @@ -1,5 +1,7 @@ -import { launch } from 'puppeteer'; -import { getSitemapUrls } from './get-sitemap-links'; +// eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-var-requires +const puppeteer = require('puppeteer'); +// eslint-disable-next-line @typescript-eslint/no-var-requires +const { getSitemapUrls } = require('./get-sitemap-links'); const excludedErrors = [ { From ca6f708d7ace821f940b9780ed24b5106c1c8ce5 Mon Sep 17 00:00:00 2001 From: katiegoines Date: Mon, 18 Mar 2024 12:31:44 -0700 Subject: [PATCH 08/12] working --- .github/workflows/check_for_console_errors.yml | 2 +- tasks/{console-errors.js => console-errors.mjs} | 8 +++----- 2 files changed, 4 insertions(+), 6 deletions(-) rename tasks/{console-errors.js => console-errors.mjs} (87%) diff --git a/.github/workflows/check_for_console_errors.yml b/.github/workflows/check_for_console_errors.yml index 1a9c4a7a4ff..fc343c7f34c 100644 --- a/.github/workflows/check_for_console_errors.yml +++ b/.github/workflows/check_for_console_errors.yml @@ -32,7 +32,7 @@ jobs: with: result-encoding: string script: | - const { consoleErrors } = require('./tasks/console-errors.js'); + const { consoleErrors } = require('./tasks/console-errors.mjs'); return await consoleErrors(); - name: Fail if console errors have been found if: ${{ steps.consoleErrors.outputs.result }} diff --git a/tasks/console-errors.js b/tasks/console-errors.mjs similarity index 87% rename from tasks/console-errors.js rename to tasks/console-errors.mjs index 8c9d36c0496..99eb6fa81eb 100644 --- a/tasks/console-errors.js +++ b/tasks/console-errors.mjs @@ -1,7 +1,5 @@ -// eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-var-requires -const puppeteer = require('puppeteer'); -// eslint-disable-next-line @typescript-eslint/no-var-requires -const { getSitemapUrls } = require('./get-sitemap-links'); +const puppeteer = require('puppeteer'); // eslint-disable-line +const { getSitemapUrls } = require('./get-sitemap-links'); // eslint-disable-line const excludedErrors = [ { @@ -19,7 +17,7 @@ const excludedScripts = [ const checkPage = async (url) => { const errorsFound = []; - let browser = await launch({ headless: 'new' }); + let browser = await puppeteer.launch({ headless: 'new' }); const page = await browser.newPage(); From fe5a0eac9556bb74cfa37f9a131eba7c6c26ab21 Mon Sep 17 00:00:00 2001 From: katiegoines Date: Mon, 18 Mar 2024 12:42:18 -0700 Subject: [PATCH 09/12] . --- .github/workflows/check_for_console_errors.yml | 2 +- tasks/console-errors.mjs | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/.github/workflows/check_for_console_errors.yml b/.github/workflows/check_for_console_errors.yml index fc343c7f34c..1a9c4a7a4ff 100644 --- a/.github/workflows/check_for_console_errors.yml +++ b/.github/workflows/check_for_console_errors.yml @@ -32,7 +32,7 @@ jobs: with: result-encoding: string script: | - const { consoleErrors } = require('./tasks/console-errors.mjs'); + const { consoleErrors } = require('./tasks/console-errors.js'); return await consoleErrors(); - name: Fail if console errors have been found if: ${{ steps.consoleErrors.outputs.result }} diff --git a/tasks/console-errors.mjs b/tasks/console-errors.mjs index 99eb6fa81eb..4db30f40de4 100644 --- a/tasks/console-errors.mjs +++ b/tasks/console-errors.mjs @@ -78,6 +78,8 @@ const consoleErrors = async (domain) => { return errorMessage; }; -export async function consoleErrors(domain = 'http://localhost:3000') { - return await consoleErrors(domain); -} +module.exports = { + consoleErrors: async (domain = 'http://localhost:3000') => { + return await consoleErrors(domain); + } +}; From b1b93faa6d0fe85e5be9c94cbdec599ab817ef5d Mon Sep 17 00:00:00 2001 From: katiegoines Date: Mon, 18 Mar 2024 12:49:49 -0700 Subject: [PATCH 10/12] back to js --- tasks/{console-errors.mjs => console-errors.js} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tasks/{console-errors.mjs => console-errors.js} (100%) diff --git a/tasks/console-errors.mjs b/tasks/console-errors.js similarity index 100% rename from tasks/console-errors.mjs rename to tasks/console-errors.js From 99a9fe0bd8adeed5fa9fdb1097d667151890f3ad Mon Sep 17 00:00:00 2001 From: katiegoines Date: Mon, 18 Mar 2024 13:03:32 -0700 Subject: [PATCH 11/12] . --- tasks/get-sitemap-links.js | 42 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 tasks/get-sitemap-links.js diff --git a/tasks/get-sitemap-links.js b/tasks/get-sitemap-links.js new file mode 100644 index 00000000000..8e40ac783a2 --- /dev/null +++ b/tasks/get-sitemap-links.js @@ -0,0 +1,42 @@ +const puppeteer = require('puppeteer'); // eslint-disable-line + +const DOMAIN = 'https://docs.amplify.aws'; +const SITEMAP_URL = 'https://docs.amplify.aws/sitemap.xml'; + +const getSitemapUrls = async (localDomain) => { + let browser = await puppeteer.launch({ headless: 'new' }); + + const page = await browser.newPage(); + + let siteMap = localDomain ? `${localDomain}/sitemap.xml` : SITEMAP_URL; + let response = await page.goto(siteMap); + + const siteMapUrls = []; + + if (response && response.status() && response.status() === 200) { + const urlTags = await page.evaluateHandle(() => { + return document.getElementsByTagName('loc'); + }); + const numOfLinks = await page.evaluate((e) => e.length, urlTags); + for (let i = 0; i < numOfLinks; i++) { + let url = await page.evaluate( + (urlTags, i) => urlTags[i].innerHTML, + urlTags, + i + ); + if (localDomain) { + // Currently the sitemap is always generated with the prod docs domain so we need to replace this with localhost + url = url.replace(DOMAIN, localDomain); + } + siteMapUrls.push(url); + } + } + browser.close(); + return siteMapUrls; +}; + +module.exports = { + getSitemapUrls: async (domain) => { + return await getSitemapUrls(domain); + } +}; From 995664cf2cf9fbfd0633335a1ca2cb47b39cd142 Mon Sep 17 00:00:00 2001 From: katiegoines Date: Mon, 18 Mar 2024 13:19:27 -0700 Subject: [PATCH 12/12] catch error --- tasks/console-errors.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/tasks/console-errors.js b/tasks/console-errors.js index 4db30f40de4..f2310bf0453 100644 --- a/tasks/console-errors.js +++ b/tasks/console-errors.js @@ -67,12 +67,16 @@ const consoleErrors = async (domain) => { let pagesToCheck = await getSitemapUrls(domain); let errorMessage = ''; for (let i = 0; i < pagesToCheck.length; i++) { - let url = pagesToCheck[i]; - console.log(`checking page ${url}`); - let errorsFound = await checkPage(url); - errorsFound.forEach((error) => { - errorMessage += `${error.message} found on ${error.page}\n`; - }); + try { + let url = pagesToCheck[i]; + console.log(`checking page ${url}`); + let errorsFound = await checkPage(url); + errorsFound.forEach((error) => { + errorMessage += `${error.message} found on ${error.page}\n`; + }); + } catch (error) { + console.log(error); + } } console.log(errorMessage); return errorMessage;