From 0c490d9cc3b9f35d4c5f6a2f3ed91eab3f73fab5 Mon Sep 17 00:00:00 2001 From: Kevin Heis Date: Wed, 28 Jun 2023 09:05:08 -0700 Subject: [PATCH 1/3] Src content render tests (#38701) --- .github/workflows/test.yml | 2 ++ src/content-render/tests/data.js | 9 ++------- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 19c0f562b1..9f5ac29c59 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -43,11 +43,13 @@ jobs: { name: 'automated-pipelines', path: 'src/automated-pipelines/tests', }, { name: 'content', path: 'tests/content', }, // { name: 'content-linter', path: 'src/content-linter/tests', }, + { name: 'content-render', path: 'src/content-render/tests', }, { name: 'events', path: 'src/events/tests', }, { name: 'ghes-releases', path: 'src/ghes-releases/tests', }, { name: 'github-apps', path: 'src/github-apps/tests', }, { name: 'graphql', path: 'src/graphql/tests', }, { name: 'landings', path: 'src/landings/tests', }, + // { name: 'learning-track', path: 'src/learning-track/tests', }, { name: 'linting', path: 'src/content-linter/tests', }, { name: 'observability', path: 'src/observability/tests' }, { name: 'pageinfo', path: 'src/pageinfo/tests', }, diff --git a/src/content-render/tests/data.js b/src/content-render/tests/data.js index 3e0634445e..5fe8042b08 100644 --- a/src/content-render/tests/data.js +++ b/src/content-render/tests/data.js @@ -1,6 +1,3 @@ -import { fileURLToPath } from 'url' -import path from 'path' - import { afterAll, beforeAll, expect, describe, it } from '@jest/globals' import Page from '../../../lib/page.js' @@ -8,8 +5,6 @@ import languages from '../../../lib/languages.js' import nonEnterpriseDefaultVersion from '../../../lib/non-enterprise-default-version.js' import { DataDirectory } from '../../../tests/helpers/data-directory.js' -const __dirname = path.dirname(fileURLToPath(import.meta.url)) - describe('data tag', () => { let dd const enDirBefore = languages.en.dir @@ -35,7 +30,7 @@ describe('data tag', () => { it('should render fine if data is found', async () => { const page = await Page.init({ relativePath: 'liquid-tags/good-data-variable.md', - basePath: path.join(__dirname, '../../fixtures'), + basePath: './tests/fixtures', languageCode: 'en', }) const context = { @@ -52,7 +47,7 @@ describe('data tag', () => { it('should throw if the data tag is used with something unrecognized', async () => { const page = await Page.init({ relativePath: 'liquid-tags/bad-data-variable.md', - basePath: path.join(__dirname, '../../fixtures'), + basePath: './tests/fixtures', languageCode: 'en', }) const context = { From 14f8f76137763cd21ea04eac76014698e9a97d6b Mon Sep 17 00:00:00 2001 From: Rachael Sewell Date: Wed, 28 Jun 2023 09:08:40 -0700 Subject: [PATCH 2/3] update archive version script (#38268) --- package-lock.json | 6 +-- package.json | 3 +- src/ghes-releases/scripts/archive-version.js | 48 ++++++++++++-------- 3 files changed, 34 insertions(+), 23 deletions(-) diff --git a/package-lock.json b/package-lock.json index a54bd80a9f..dc16e4979b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -169,8 +169,7 @@ "node": "^16 || ^18" }, "optionalDependencies": { - "esm": "^3.2.25", - "website-scraper": "^5.3.1" + "esm": "^3.2.25" } }, "node_modules/@actions/core": { @@ -18472,8 +18471,9 @@ }, "node_modules/website-scraper": { "version": "5.3.1", + "resolved": "https://registry.npmjs.org/website-scraper/-/website-scraper-5.3.1.tgz", + "integrity": "sha512-gogqPXD2gVsxoyd2yRiympw3rA5GuEpD1CaDEJ/J8zzanx7hkbTtneoO1SGs436PpLbWVcUge+6APGLhzsuZPA==", "dev": true, - "license": "MIT", "dependencies": { "cheerio": "1.0.0-rc.12", "css-url-parser": "^1.0.0", diff --git a/package.json b/package.json index 8ed3d0eb40..34fbbcd44c 100644 --- a/package.json +++ b/package.json @@ -213,8 +213,7 @@ "website-scraper": "^5.3.1" }, "optionalDependencies": { - "esm": "^3.2.25", - "website-scraper": "^5.3.1" + "esm": "^3.2.25" }, "engines": { "node": "^16 || ^18" diff --git a/src/ghes-releases/scripts/archive-version.js b/src/ghes-releases/scripts/archive-version.js index 939cc2db65..a2084a7151 100755 --- a/src/ghes-releases/scripts/archive-version.js +++ b/src/ghes-releases/scripts/archive-version.js @@ -10,7 +10,6 @@ import path from 'path' import fs from 'fs' -import { execSync } from 'child_process' import scrape from 'website-scraper' import { program } from 'commander' import { rimraf } from 'rimraf' @@ -35,6 +34,7 @@ program '-o, --output ', `output directory to place scraped HTML files and redirects. By default, this temp directory is named 'tmpArchivalDir_'` ) + .option('-l, --local-dev', 'Do not rewrite asset paths to enable testing scraped content locally') .option('-d, --dry-run', 'only scrape the first 10 pages for testing purposes') .option( '-p, --page ', @@ -45,6 +45,7 @@ program const output = program.opts().output const dryRun = program.opts().dryRun const singlePage = program.opts().page +const localDev = program.opts().localDev const tmpArchivalDirectory = output ? path.join(process.cwd(), output) : path.join(process.cwd(), `tmpArchivalDir_${version}`) @@ -67,19 +68,30 @@ class RewriteAssetPathsPlugin { // Get the text contents of the resource const text = resource.getText() - let newBody = '' + let newBody = text // Rewrite HTML asset paths. Example: // ../assets/images/foo/bar.png -> // https://githubdocs.azureedge.net/github-images/enterprise/2.17/assets/images/foo/bar.png + if (resource.isHtml()) { - newBody = text.replace( - /(?src|href)="(?:\.\.\/|\/)*(?_next\/static|javascripts|stylesheets|assets\/fonts|assets\/cb-\d+\/images|node_modules)/g, - (match, attribute, basepath) => { - const replaced = `${REMOTE_ENTERPRISE_STORAGE_URL}/${this.version}/${basepath}` - return `${attribute}="${replaced}` - } + // Remove nextjs scripts and manifest.json link + newBody = newBody.replace( + /<\/script>/g, + '' ) + newBody = newBody.replace(//g, '') + + if (!localDev) { + // Rewrite asset paths + newBody = newBody.replace( + /(?src|href)="(?:\.\.\/|\/)*(?_next\/static|javascripts|stylesheets|assets\/fonts|assets\/cb-\d+\/images|node_modules)/g, + (match, attribute, basepath) => { + const replaced = `${REMOTE_ENTERPRISE_STORAGE_URL}/${this.version}/${basepath}` + return `${attribute}="${replaced}` + } + ) + } } // Rewrite CSS asset paths. Example @@ -88,25 +100,25 @@ class RewriteAssetPathsPlugin { // url(../../../assets/cb-303/images/octicons/search-24.svg) -> // url(https://githubdocs.azureedge.net/github-images/enterprise/2.20/assets/cb-303/images/octicons/search-24.svg) if (resource.isCss()) { - newBody = text.replace( - /(?url)(?\("|\()(?:\.\.\/)*(?_next\/static|assets\/fonts|assets\/images|assets\/cb-\d+\/images)/g, - (match, attribute, paren, basepath) => { - const replaced = `${REMOTE_ENTERPRISE_STORAGE_URL}/${this.version}/${basepath}` - return `${attribute}${paren}${replaced}` - } - ) + if (!localDev) { + newBody = newBody.replace( + /(?url)(?\("|\()(?:\.\.\/)*(?_next\/static|assets\/fonts|assets\/images|assets\/cb-\d+\/images)/g, + (match, attribute, paren, basepath) => { + const replaced = `${REMOTE_ENTERPRISE_STORAGE_URL}/${this.version}/${basepath}` + return `${attribute}${paren}${replaced}` + } + ) + } } const filePath = path.join(this.tempDirectory, resource.getFilename()) - await fs.promises.writeFile(filePath, newBody, 'binary') + await fs.promises.writeFile(filePath, newBody, resource.encoding) }) } } async function main() { // Build the production assets, to simulate a production deployment - console.log('Running `npm run build` for production assets') - execSync('npm run build', { stdio: 'inherit' }) console.log('Finish building production assets') if (dryRun) { console.log( From a391eb166258d48ba32e6b4f4cdd953fcb4577f5 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 28 Jun 2023 11:20:26 -0500 Subject: [PATCH 3/3] Bump micromark-extension-gfm-table from 1.0.5 to 2.0.0 (#38660) Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Robert Sese <734194+rsese@users.noreply.github.com> --- package-lock.json | 119 ++++++++++++++++++++++++++++++++++++++++++---- package.json | 2 +- 2 files changed, 112 insertions(+), 9 deletions(-) diff --git a/package-lock.json b/package-lock.json index dc16e4979b..7679db2cf7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -146,7 +146,7 @@ "markdownlint": "^0.28.2", "markdownlint-rule-helpers": "^0.19.0", "mdast-util-gfm-table": "^1.0.7", - "micromark-extension-gfm-table": "^1.0.5", + "micromark-extension-gfm-table": "^2.0.0", "mkdirp": "^3.0.0", "mockdate": "^3.0.5", "nock": "^13.2.7", @@ -7400,6 +7400,19 @@ "node": ">=8" } }, + "node_modules/devlop": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/devlop/-/devlop-1.0.0.tgz", + "integrity": "sha512-DNY7Ok32YUNiFjTw9sNVqUET5c2/cqbOdDxnsI6MkfQOvMcAULqPVqABm/An9IGVRP4ulHEvpo3/w2Potw3cfQ==", + "dev": true, + "dependencies": { + "dequal": "^2.0.0" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/wooorm" + } + }, "node_modules/diff": { "version": "5.0.0", "license": "BSD-3-Clause", @@ -13827,20 +13840,94 @@ } }, "node_modules/micromark-extension-gfm-table": { - "version": "1.0.5", - "license": "MIT", + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/micromark-extension-gfm-table/-/micromark-extension-gfm-table-2.0.0.tgz", + "integrity": "sha512-PoHlhypg1ItIucOaHmKE8fbin3vTLpDOUg8KAr8gRCF1MOZI9Nquq2i/44wFvviM4WuxJzc3demT8Y3dkfvYrw==", + "dev": true, "dependencies": { - "micromark-factory-space": "^1.0.0", - "micromark-util-character": "^1.0.0", - "micromark-util-symbol": "^1.0.0", - "micromark-util-types": "^1.0.0", - "uvu": "^0.5.0" + "devlop": "^1.0.0", + "micromark-factory-space": "^2.0.0", + "micromark-util-character": "^2.0.0", + "micromark-util-symbol": "^2.0.0", + "micromark-util-types": "^2.0.0" }, "funding": { "type": "opencollective", "url": "https://opencollective.com/unified" } }, + "node_modules/micromark-extension-gfm-table/node_modules/micromark-factory-space": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/micromark-factory-space/-/micromark-factory-space-2.0.0.tgz", + "integrity": "sha512-TKr+LIDX2pkBJXFLzpyPyljzYK3MtmllMUMODTQJIUfDGncESaqB90db9IAUcz4AZAJFdd8U9zOp9ty1458rxg==", + "dev": true, + "funding": [ + { + "type": "GitHub Sponsors", + "url": "https://github.com/sponsors/unifiedjs" + }, + { + "type": "OpenCollective", + "url": "https://opencollective.com/unified" + } + ], + "dependencies": { + "micromark-util-character": "^2.0.0", + "micromark-util-types": "^2.0.0" + } + }, + "node_modules/micromark-extension-gfm-table/node_modules/micromark-util-character": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/micromark-util-character/-/micromark-util-character-2.0.1.tgz", + "integrity": "sha512-3wgnrmEAJ4T+mGXAUfMvMAbxU9RDG43XmGce4j6CwPtVxB3vfwXSZ6KhFwDzZ3mZHhmPimMAXg71veiBGzeAZw==", + "dev": true, + "funding": [ + { + "type": "GitHub Sponsors", + "url": "https://github.com/sponsors/unifiedjs" + }, + { + "type": "OpenCollective", + "url": "https://opencollective.com/unified" + } + ], + "dependencies": { + "micromark-util-symbol": "^2.0.0", + "micromark-util-types": "^2.0.0" + } + }, + "node_modules/micromark-extension-gfm-table/node_modules/micromark-util-symbol": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/micromark-util-symbol/-/micromark-util-symbol-2.0.0.tgz", + "integrity": "sha512-8JZt9ElZ5kyTnO94muPxIGS8oyElRJaiJO8EzV6ZSyGQ1Is8xwl4Q45qU5UOg+bGH4AikWziz0iN4sFLWs8PGw==", + "dev": true, + "funding": [ + { + "type": "GitHub Sponsors", + "url": "https://github.com/sponsors/unifiedjs" + }, + { + "type": "OpenCollective", + "url": "https://opencollective.com/unified" + } + ] + }, + "node_modules/micromark-extension-gfm-table/node_modules/micromark-util-types": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/micromark-util-types/-/micromark-util-types-2.0.0.tgz", + "integrity": "sha512-oNh6S2WMHWRZrmutsRmDDfkzKtxF+bc2VxLC9dvtrDIRFln627VsFP6fLMgTryGDljgLPjkrzQSDcPrjPyDJ5w==", + "dev": true, + "funding": [ + { + "type": "GitHub Sponsors", + "url": "https://github.com/sponsors/unifiedjs" + }, + { + "type": "OpenCollective", + "url": "https://opencollective.com/unified" + } + ] + }, "node_modules/micromark-extension-gfm-tagfilter": { "version": "1.0.0", "license": "MIT", @@ -13867,6 +13954,22 @@ "url": "https://opencollective.com/unified" } }, + "node_modules/micromark-extension-gfm/node_modules/micromark-extension-gfm-table": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/micromark-extension-gfm-table/-/micromark-extension-gfm-table-1.0.7.tgz", + "integrity": "sha512-3ZORTHtcSnMQEKtAOsBQ9/oHp9096pI/UvdPtN7ehKvrmZZ2+bbWhi0ln+I9drmwXMt5boocn6OlwQzNXeVeqw==", + "dependencies": { + "micromark-factory-space": "^1.0.0", + "micromark-util-character": "^1.0.0", + "micromark-util-symbol": "^1.0.0", + "micromark-util-types": "^1.0.0", + "uvu": "^0.5.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + } + }, "node_modules/micromark-factory-destination": { "version": "1.0.0", "funding": [ diff --git a/package.json b/package.json index 34fbbcd44c..b23db49e64 100644 --- a/package.json +++ b/package.json @@ -193,7 +193,7 @@ "markdownlint": "^0.28.2", "markdownlint-rule-helpers": "^0.19.0", "mdast-util-gfm-table": "^1.0.7", - "micromark-extension-gfm-table": "^1.0.5", + "micromark-extension-gfm-table": "^2.0.0", "mkdirp": "^3.0.0", "mockdate": "^3.0.5", "nock": "^13.2.7",