diff --git a/.github/actions-scripts/enterprise-server-issue-templates/release-issue.md b/.github/actions-scripts/enterprise-server-issue-templates/release-issue.md index df5acec636..5b34e587fa 100644 --- a/.github/actions-scripts/enterprise-server-issue-templates/release-issue.md +++ b/.github/actions-scripts/enterprise-server-issue-templates/release-issue.md @@ -47,13 +47,7 @@ If you aren't comfortable going through the steps alone, sync up with a docs eng ``` **Note:** All of the content in this file will be updated when the release notes are created in the megabranch including the filename `PLACEHOLDER.yml`. You can update the date or leave it as-is and wait to update it when the release notes are finalized. -- [ ] Create the search indices for the new release: - ``` - npm run sync-search-ghes-release - ``` - - Check in the updated `lib/search/cached-index-names.json`. - [ ] (Optional) Add a Release Candidate banner: ``` diff --git a/contributing/search.md b/contributing/search.md index 78af4c7f8a..59e98a0d6e 100644 --- a/contributing/search.md +++ b/contributing/search.md @@ -51,23 +51,9 @@ You can locally generate search indexes, but please do not check them into your To locally generate the English version of the Dotcom search index locally, run `LANGUAGE=en VERSION=free-pro-team@latest npm run sync-search`. See [Build and sync](#build-and-sync) below for more details. To revert those files run `git checkout lib/search/indexes`. -### Build without sync (dry run) - -To build all the indices without uploading them (this takes about an hour): -``` -npm run sync-search-dry-run -``` -To build indices for a specific language and/or version (this is much faster): -``` -VERSION= LANGUAGE= npm run sync-search-dry-run -``` -You can set `VERSION` and `LANGUAGE` individually, too. - -Substitute a currently supported version for `` and a currently supported two-letter language code for ``. - ### Build and sync -To build all the indices and sync them (this also takes about an hour): +To build all the indices (this takes about an hour): ``` npm run sync-search ``` diff --git a/lib/search/cached-index-names.json b/lib/search/cached-index-names.json deleted file mode 100644 index 46705b5d80..0000000000 --- a/lib/search/cached-index-names.json +++ /dev/null @@ -1,41 +0,0 @@ -[ - "github-docs-2.20-cn", - "github-docs-2.20-en", - "github-docs-2.20-ja", - "github-docs-2.21-cn", - "github-docs-2.21-de", - "github-docs-2.21-en", - "github-docs-2.21-es", - "github-docs-2.21-ja", - "github-docs-2.21-pt", - "github-docs-2.22-cn", - "github-docs-2.22-de", - "github-docs-2.22-en", - "github-docs-2.22-es", - "github-docs-2.22-ja", - "github-docs-2.22-pt", - "github-docs-3.0-cn", - "github-docs-3.0-de", - "github-docs-3.0-en", - "github-docs-3.0-es", - "github-docs-3.0-ja", - "github-docs-3.0-pt", - "github-docs-3.1-cn", - "github-docs-3.1-de", - "github-docs-3.1-en", - "github-docs-3.1-es", - "github-docs-3.1-ja", - "github-docs-3.1-pt", - "github-docs-dotcom-cn", - "github-docs-dotcom-de", - "github-docs-dotcom-en", - "github-docs-dotcom-es", - "github-docs-dotcom-ja", - "github-docs-dotcom-pt", - "github-docs-ghae-cn", - "github-docs-ghae-de", - "github-docs-ghae-en", - "github-docs-ghae-es", - "github-docs-ghae-ja", - "github-docs-ghae-pt" -] \ No newline at end of file diff --git a/package.json b/package.json index dfbf421051..5325fd35a0 100644 --- a/package.json +++ b/package.json @@ -209,7 +209,6 @@ "start": "cross-env NODE_ENV=development ENABLED_LANGUAGES='en,ja' nodemon server.mjs", "start-all-languages": "cross-env NODE_ENV=development nodemon server.mjs", "sync-search": "start-server-and-test sync-search-server 4002 sync-search-indices", - "sync-search-dry-run": "cross-env DRY_RUN=1 npm run sync-search", "sync-search-ghes-release": "cross-env GHES_RELEASE=1 start-server-and-test sync-search-server 4002 sync-search-indices", "sync-search-indices": "script/sync-search-indices.js", "sync-search-server": "cross-env NODE_ENV=production WEB_CONCURRENCY=1 PORT=4002 node server.mjs", diff --git a/script/search/lunr-get-index-names.js b/script/search/lunr-get-index-names.js index b0d383b4b8..2933073530 100644 --- a/script/search/lunr-get-index-names.js +++ b/script/search/lunr-get-index-names.js @@ -4,10 +4,9 @@ import path from 'path' import fs from 'fs/promises' const __dirname = path.dirname(fileURLToPath(import.meta.url)) -export default async function getIndexNames() { +async function getIndexNames() { const indexList = await fs.readdir(path.join(__dirname, '../../lib/search/indexes')) - return indexList - .sort() - .filter((index) => !index.includes('records')) - .map((index) => index.replace('.json.br', '')) + return indexList.sort().map((index) => index.replace('.json.br', '')) } + +export default await getIndexNames() diff --git a/script/search/sync.js b/script/search/sync.js index 5919464651..bc9feb38a0 100644 --- a/script/search/sync.js +++ b/script/search/sync.js @@ -1,34 +1,16 @@ #!/usr/bin/env node -import { fileURLToPath } from 'url' -import path from 'path' -import fs from 'fs' -import mkdirp from 'mkdirp' -import rimraf from 'rimraf' -import chalk from 'chalk' import languages from '../../lib/languages.js' import buildRecords from './build-records.js' import findIndexablePages from './find-indexable-pages.js' import { allVersions } from '../../lib/all-versions.js' import { namePrefix } from '../../lib/search/config.js' import LunrIndex from './lunr-search-index.js' -import getLunrIndexNames from './lunr-get-index-names.js' - -const __dirname = path.dirname(fileURLToPath(import.meta.url)) -const cacheDir = path.join(process.cwd(), './.search-cache') // Lunr // Build a search data file for every combination of product version and language // e.g. `github-docs-dotcom-en.json` and `github-docs-2.14-ja.json` export default async function syncSearchIndexes(opts = {}) { - if (opts.dryRun) { - console.log( - 'This is a dry run! The script will build the indices locally but not upload anything.\n' - ) - rimraf.sync(cacheDir) - await mkdirp(cacheDir) - } - if (opts.language) { if (!Object.keys(languages).includes(opts.language)) { console.log( @@ -84,29 +66,10 @@ export default async function syncSearchIndexes(opts = {}) { const records = await buildRecords(indexName, indexablePages, pageVersion, languageCode) const index = new LunrIndex(indexName, records) - if (opts.dryRun) { - const cacheFile = path.join(cacheDir, `${indexName}.json`) - fs.writeFileSync(cacheFile, JSON.stringify(index, null, 2)) - console.log('wrote dry-run index to disk: ', cacheFile) - } else { - await index.write() - console.log('wrote index to file: ', indexName) - } + await index.write() + console.log('wrote index to file: ', indexName) } } - // Fetch a list of index names and cache it for tests - // to ensure that an index exists for every language and GHE version - const remoteIndexNames = await getLunrIndexNames() - const cachedIndexNamesFile = path.join(__dirname, '../../lib/search/cached-index-names.json') - fs.writeFileSync(cachedIndexNamesFile, JSON.stringify(remoteIndexNames, null, 2)) - - if (!process.env.CI) { - console.log( - chalk.green(`\nCached index names in ${path.relative(process.cwd(), cachedIndexNamesFile)}`) - ) - console.log(chalk.green('(If this file has any changes, please commit them)')) - } - console.log('\nDone!') } diff --git a/tests/content/search.js b/tests/content/search.js index b1fe079de3..be73a5a585 100644 --- a/tests/content/search.js +++ b/tests/content/search.js @@ -1,41 +1,30 @@ -import { dates, supported } from '../../lib/enterprise-server-releases.js' +import { supported } from '../../lib/enterprise-server-releases.js' import libLanguages from '../../lib/languages.js' import { namePrefix } from '../../lib/search/config.js' -import remoteIndexNames from '../../lib/search/cached-index-names.json' +import { expect } from '@jest/globals' +import lunrIndexNames from '../../script/search/lunr-get-index-names.js' const languageCodes = Object.keys(libLanguages) describe('search', () => { - test('has remote indexNames in every language for every supported GHE version', () => { + test('has Lunr index for every language for every supported GHE version', () => { expect(supported.length).toBeGreaterThan(1) supported.forEach((version) => { languageCodes.forEach((languageCode) => { const indexName = `${namePrefix}-${version}-${languageCode}` - - // workaround for GHES release branches not in production yet - if (!remoteIndexNames.includes(indexName)) { - const today = getDate() - const releaseDate = getDate(dates[version].releaseDate) - // if the release date is in the future or today, ignore this version; - // this means if the new index is not uploaded at the time of the release, - // the test will not fail until the following day. - if (releaseDate >= today) return - } - - expect(remoteIndexNames.includes(indexName)).toBe(true) + const indexRecordName = `${indexName}-records` + expect(lunrIndexNames.includes(indexName)).toBe(true) + expect(lunrIndexNames.includes(indexRecordName)).toBe(true) }) }) }) - test('has remote indexNames in every language for dotcom', async () => { + test('has Lunr index for every language for dotcom', async () => { expect(languageCodes.length).toBeGreaterThan(0) languageCodes.forEach((languageCode) => { const indexName = `${namePrefix}-dotcom-${languageCode}` - expect(remoteIndexNames.includes(indexName)).toBe(true) + const indexRecordName = `${indexName}-records` + expect(lunrIndexNames.includes(indexName)).toBe(true) + expect(lunrIndexNames.includes(indexRecordName)).toBe(true) }) }) }) - -function getDate(date) { - const dateObj = date ? new Date(date) : new Date() - return dateObj.toISOString().slice(0, 10) -}