Skip to content

Commit 5cfedac

Browse files
authored
Merge pull request #26311 from github/repo-sync
Repo sync
2 parents 7007554 + a391eb1 commit 5cfedac

File tree

5 files changed

+150
-39
lines changed

5 files changed

+150
-39
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,13 @@ jobs:
4343
{ name: 'automated-pipelines', path: 'src/automated-pipelines/tests', },
4444
{ name: 'content', path: 'tests/content', },
4545
// { name: 'content-linter', path: 'src/content-linter/tests', },
46+
{ name: 'content-render', path: 'src/content-render/tests', },
4647
{ name: 'events', path: 'src/events/tests', },
4748
{ name: 'ghes-releases', path: 'src/ghes-releases/tests', },
4849
{ name: 'github-apps', path: 'src/github-apps/tests', },
4950
{ name: 'graphql', path: 'src/graphql/tests', },
5051
{ name: 'landings', path: 'src/landings/tests', },
52+
// { name: 'learning-track', path: 'src/learning-track/tests', },
5153
{ name: 'linting', path: 'src/content-linter/tests', },
5254
{ name: 'observability', path: 'src/observability/tests' },
5355
{ name: 'pageinfo', path: 'src/pageinfo/tests', },

package-lock.json

Lines changed: 114 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@
193193
"markdownlint": "^0.28.2",
194194
"markdownlint-rule-helpers": "^0.19.0",
195195
"mdast-util-gfm-table": "^1.0.7",
196-
"micromark-extension-gfm-table": "^1.0.5",
196+
"micromark-extension-gfm-table": "^2.0.0",
197197
"mkdirp": "^3.0.0",
198198
"mockdate": "^3.0.5",
199199
"nock": "^13.2.7",
@@ -213,8 +213,7 @@
213213
"website-scraper": "^5.3.1"
214214
},
215215
"optionalDependencies": {
216-
"esm": "^3.2.25",
217-
"website-scraper": "^5.3.1"
216+
"esm": "^3.2.25"
218217
},
219218
"engines": {
220219
"node": "^16 || ^18"

src/content-render/tests/data.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
1-
import { fileURLToPath } from 'url'
2-
import path from 'path'
3-
41
import { afterAll, beforeAll, expect, describe, it } from '@jest/globals'
52

63
import Page from '../../../lib/page.js'
74
import languages from '../../../lib/languages.js'
85
import nonEnterpriseDefaultVersion from '../../../lib/non-enterprise-default-version.js'
96
import { DataDirectory } from '../../../tests/helpers/data-directory.js'
107

11-
const __dirname = path.dirname(fileURLToPath(import.meta.url))
12-
138
describe('data tag', () => {
149
let dd
1510
const enDirBefore = languages.en.dir
@@ -35,7 +30,7 @@ describe('data tag', () => {
3530
it('should render fine if data is found', async () => {
3631
const page = await Page.init({
3732
relativePath: 'liquid-tags/good-data-variable.md',
38-
basePath: path.join(__dirname, '../../fixtures'),
33+
basePath: './tests/fixtures',
3934
languageCode: 'en',
4035
})
4136
const context = {
@@ -52,7 +47,7 @@ describe('data tag', () => {
5247
it('should throw if the data tag is used with something unrecognized', async () => {
5348
const page = await Page.init({
5449
relativePath: 'liquid-tags/bad-data-variable.md',
55-
basePath: path.join(__dirname, '../../fixtures'),
50+
basePath: './tests/fixtures',
5651
languageCode: 'en',
5752
})
5853
const context = {

src/ghes-releases/scripts/archive-version.js

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
import path from 'path'
1212
import fs from 'fs'
13-
import { execSync } from 'child_process'
1413
import scrape from 'website-scraper'
1514
import { program } from 'commander'
1615
import { rimraf } from 'rimraf'
@@ -35,6 +34,7 @@ program
3534
'-o, --output <PATH>',
3635
`output directory to place scraped HTML files and redirects. By default, this temp directory is named 'tmpArchivalDir_<VERSION_TO_DEPRECATE>'`
3736
)
37+
.option('-l, --local-dev', 'Do not rewrite asset paths to enable testing scraped content locally')
3838
.option('-d, --dry-run', 'only scrape the first 10 pages for testing purposes')
3939
.option(
4040
'-p, --page <PATH>',
@@ -45,6 +45,7 @@ program
4545
const output = program.opts().output
4646
const dryRun = program.opts().dryRun
4747
const singlePage = program.opts().page
48+
const localDev = program.opts().localDev
4849
const tmpArchivalDirectory = output
4950
? path.join(process.cwd(), output)
5051
: path.join(process.cwd(), `tmpArchivalDir_${version}`)
@@ -67,19 +68,30 @@ class RewriteAssetPathsPlugin {
6768

6869
// Get the text contents of the resource
6970
const text = resource.getText()
70-
let newBody = ''
71+
let newBody = text
7172

7273
// Rewrite HTML asset paths. Example:
7374
// ../assets/images/foo/bar.png ->
7475
// https://githubdocs.azureedge.net/github-images/enterprise/2.17/assets/images/foo/bar.png
76+
7577
if (resource.isHtml()) {
76-
newBody = text.replace(
77-
/(?<attribute>src|href)="(?:\.\.\/|\/)*(?<basepath>_next\/static|javascripts|stylesheets|assets\/fonts|assets\/cb-\d+\/images|node_modules)/g,
78-
(match, attribute, basepath) => {
79-
const replaced = `${REMOTE_ENTERPRISE_STORAGE_URL}/${this.version}/${basepath}`
80-
return `${attribute}="${replaced}`
81-
}
78+
// Remove nextjs scripts and manifest.json link
79+
newBody = newBody.replace(
80+
/<script\ssrc="(\.\.\/)*_next\/static\/[\w]+\/(_buildManifest|_ssgManifest).js?".*?><\/script>/g,
81+
''
8282
)
83+
newBody = newBody.replace(/<link href=".*manifest.json".*?>/g, '')
84+
85+
if (!localDev) {
86+
// Rewrite asset paths
87+
newBody = newBody.replace(
88+
/(?<attribute>src|href)="(?:\.\.\/|\/)*(?<basepath>_next\/static|javascripts|stylesheets|assets\/fonts|assets\/cb-\d+\/images|node_modules)/g,
89+
(match, attribute, basepath) => {
90+
const replaced = `${REMOTE_ENTERPRISE_STORAGE_URL}/${this.version}/${basepath}`
91+
return `${attribute}="${replaced}`
92+
}
93+
)
94+
}
8395
}
8496

8597
// Rewrite CSS asset paths. Example
@@ -88,25 +100,25 @@ class RewriteAssetPathsPlugin {
88100
// url(../../../assets/cb-303/images/octicons/search-24.svg) ->
89101
// url(https://githubdocs.azureedge.net/github-images/enterprise/2.20/assets/cb-303/images/octicons/search-24.svg)
90102
if (resource.isCss()) {
91-
newBody = text.replace(
92-
/(?<attribute>url)(?<paren>\("|\()(?:\.\.\/)*(?<basepath>_next\/static|assets\/fonts|assets\/images|assets\/cb-\d+\/images)/g,
93-
(match, attribute, paren, basepath) => {
94-
const replaced = `${REMOTE_ENTERPRISE_STORAGE_URL}/${this.version}/${basepath}`
95-
return `${attribute}${paren}${replaced}`
96-
}
97-
)
103+
if (!localDev) {
104+
newBody = newBody.replace(
105+
/(?<attribute>url)(?<paren>\("|\()(?:\.\.\/)*(?<basepath>_next\/static|assets\/fonts|assets\/images|assets\/cb-\d+\/images)/g,
106+
(match, attribute, paren, basepath) => {
107+
const replaced = `${REMOTE_ENTERPRISE_STORAGE_URL}/${this.version}/${basepath}`
108+
return `${attribute}${paren}${replaced}`
109+
}
110+
)
111+
}
98112
}
99113

100114
const filePath = path.join(this.tempDirectory, resource.getFilename())
101-
await fs.promises.writeFile(filePath, newBody, 'binary')
115+
await fs.promises.writeFile(filePath, newBody, resource.encoding)
102116
})
103117
}
104118
}
105119

106120
async function main() {
107121
// Build the production assets, to simulate a production deployment
108-
console.log('Running `npm run build` for production assets')
109-
execSync('npm run build', { stdio: 'inherit' })
110122
console.log('Finish building production assets')
111123
if (dryRun) {
112124
console.log(

0 commit comments

Comments
 (0)