From 9a96a2699f7e118a57d3c1348140a64898941c30 Mon Sep 17 00:00:00 2001 From: Rachael Sewell Date: Wed, 18 Aug 2021 16:05:04 -0700 Subject: [PATCH] Deprecation workflow updates (#20962) --- .../deprecation-issue.md | 23 ++++++++++----- .../archive-version.js | 2 +- .../remove-static-files.js | 8 ++++++ script/helpers/remove-liquid-statements.js | 28 ++++++++++++++++--- 4 files changed, 49 insertions(+), 12 deletions(-) diff --git a/.github/actions-scripts/enterprise-server-issue-templates/deprecation-issue.md b/.github/actions-scripts/enterprise-server-issue-templates/deprecation-issue.md index 3b2300582845..aad15dee9825 100644 --- a/.github/actions-scripts/enterprise-server-issue-templates/deprecation-issue.md +++ b/.github/actions-scripts/enterprise-server-issue-templates/deprecation-issue.md @@ -36,16 +36,25 @@ The day after a GHES version's [deprecation date](https://github.com/github/docs In your `docs-internal` checkout: - [ ] Create a new branch: `git checkout -b deprecate-`. - [ ] Edit `lib/enterprise-server-releases.js` by moving the number to be deprecated into the `deprecated` array. -- [ ] Run `script/enterprise-server-deprecations/remove-static-files.js` and commit results. -- [ ] Run `script/enterprise-server-deprecations/remove-redirects.js` and commit results. - [ ] Open a new PR. Make sure to check the following: - [ ] Tests are passing. - - [ ] The deprecated version renders on staging as expected. - - [ ] The new oldest supported version renders on staging as expected. Also check the banner text. -- [ ] Remove the outdated Liquid markup and frontmatter. It's recommended to create a topic branch off of your `deprecate-` branch to isolate the changes for review. - - [ ] In your `docs-internal` checkout, from your `deprecate-` branch: `git checkout -b remove--markup` + - [ ] The deprecated version renders on staging as expected. You should be able to navigate to docs.github.com/enterprise/ to access the docs. You should also be able to navigate to a page that is available in the deprecated version and change the version in the URL to the deprecated version, to test redirects. + - [ ] The new oldest supported version renders on staging as expected. You should see a banner on the top of every page for the oldest supported version that notes when the version will be deprecated. + +## Step 5: Remove static files for the version + +- [ ] In your `docs-internal` checkout, from your `remove--static-files` branch: `git checkout -b remove--static-files` +- [ ] Run `script/enterprise-server-deprecations/remove-static-files.js` and commit results. +- [ ] Run `script/enterprise-server-deprecations/remove-redirects.js` and commit results. +- [ ] Open a new PR. +- [ ] Get a review from docs-engineering and merge. This step can be merged independently from step 6. The purpose of splitting up steps 5 and 6 is to focus the review on specific files. + +## Step 6: Remove the liquid conditionals and content for the version + +- [ ] In your `docs-internal` checkout, from your `remove--markup` branch: `git checkout -b remove--markup` +- [ ] Remove the outdated Liquid markup and frontmatter. - [ ] Run the script: `script/enterprise-server-deprecations/remove-version-markup.js --release `. - [ ] Spot check a few changes. Content, frontmatter, and data files should all have been updated. - [ ] Open a PR with the results. The diff may be large and complex, so make sure to get a review from `@github/docs-content`. - [ ] Debug any test failures or unexpected results. -- [ ] When the PR is approved, merge it in to complete the deprecation. \ No newline at end of file +- [ ] When the PR is approved, merge it in to complete the deprecation. This can be merged independently from step 5. diff --git a/script/enterprise-server-deprecations/archive-version.js b/script/enterprise-server-deprecations/archive-version.js index b9afefc49600..0b9998da3187 100755 --- a/script/enterprise-server-deprecations/archive-version.js +++ b/script/enterprise-server-deprecations/archive-version.js @@ -65,7 +65,7 @@ class RewriteAssetPathsPlugin { // 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\/images|node_modules)/g, + /(?src|href)="(?:\.\.\/|\/)*(?_next\/static|javascripts|stylesheets|assets\/fonts|assets\/images|node_modules)/g, (match, attribute, basepath) => { let replaced = path.join('/enterprise', this.version, basepath) if (basepath === 'assets/images') { diff --git a/script/enterprise-server-deprecations/remove-static-files.js b/script/enterprise-server-deprecations/remove-static-files.js index 6bacc5024e96..4ecd4dc6932d 100755 --- a/script/enterprise-server-deprecations/remove-static-files.js +++ b/script/enterprise-server-deprecations/remove-static-files.js @@ -16,6 +16,7 @@ const webhooksStaticDir = path.join(process.cwd(), 'lib/webhooks/static') const graphqlStaticDir = path.join(process.cwd(), 'lib/graphql/static') const restDecoratedDir = path.join(process.cwd(), 'lib/rest/static/decorated') const restDereferencedDir = path.join(process.cwd(), 'lib/rest/static/dereferenced') +const lunrIndexDir = path.join(process.cwd(), 'lib/search/indexes') const supportedEnterpriseVersions = Object.values(allVersions).filter( (v) => v.plan === 'enterprise-server' @@ -39,6 +40,13 @@ const openApiBaseName = supportedEnterpriseVersions.map((v) => v.openApiBaseName removeFiles(dir, openApiBaseName, supportedOpenApiVersions) }) +// Lunr +const lunrBaseName = 'github-docs-' +const supportedLunrVersions = Object.values(allVersions).map((v) => + v.miscVersionName.replace('ghes-', '') +) +removeFiles(lunrIndexDir, lunrBaseName, supportedLunrVersions) + function removeFiles(dir, baseName, supportedVersions) { fs.readdirSync(dir) .filter((file) => file.includes(baseName)) diff --git a/script/helpers/remove-liquid-statements.js b/script/helpers/remove-liquid-statements.js index 3be4980cbc44..4f7e6168d6fa 100644 --- a/script/helpers/remove-liquid-statements.js +++ b/script/helpers/remove-liquid-statements.js @@ -1,11 +1,15 @@ import { getLiquidConditionalsWithContent } from './get-liquid-conditionals.js' import getVersionBlocks from './get-version-blocks.js' import { allVersions } from '../../lib/all-versions.js' +import { Tokenizer } from 'liquidjs' const supportedShortVersions = Object.values(allVersions).map((v) => v.shortName) const updateRangeKeepGhes = 'updateRangeKeepGhes' const updateRangeRemoveGhes = 'updateRangeRemoveGhes' const removeRangeAndContent = 'removeRangeAndContent' - +const tokenize = (str) => { + const tokenizer = new Tokenizer(str) + return tokenizer.readTopLevelTokens() +} // This module is used by script/enterprise-server-deprecations/remove-version-markup.js to remove // and update Liquid conditionals when a GHES release is being deprecated. It is also used by // tests/content/remove-liquid-statements.js. @@ -187,9 +191,25 @@ export default function removeLiquidStatements(content, release, nextOldestRelea // If the block has an else, remove the else, its content, and the endif. if (versionBlock.hasElse) { - const replaceRegex = /{%-? else -?%}[\S\s]+?{%-? endif -?%}\n?/ - - versionBlock.newContent = versionBlock.newContent.replace(replaceRegex, '') + let elseStartIndex + let ifCondFlag = false + // tokenize the content including the nested conditionals to find + // the unmatched else tag. Remove content from the start of the + // else tag to the end of the content. The tokens return have different + // `kind`s and can be liquid tags, HTML, and a variety of things. + // A value of 4 is a liquid tag. See https://liquidjs.com/api/enums/parser_token_kind_.tokenkind.html. + tokenize(versionBlock.newContent) + .filter((elem) => elem.kind === 4) + .forEach((tag) => { + if (tag.name === 'ifversion' || tag.name === 'if') { + ifCondFlag = true + } else if (tag.name === 'endif' && ifCondFlag === true) { + ifCondFlag = false + } else if (tag.name === 'else' && ifCondFlag === false) { + elseStartIndex = tag.begin + } + }) + versionBlock.newContent = versionBlock.newContent.slice(0, elseStartIndex) } } }