Merge pull request #18281 from github/support-next-release-in-frontmatter
Support next release in frontmatter
This commit is contained in:
@@ -4,6 +4,9 @@ const versionSatisfiesRange = require('./version-satisfies-range')
|
||||
// enterprise-releases/docs/supported-versions.md#release-lifecycle-dates
|
||||
const dates = require('../lib/enterprise-dates.json')
|
||||
|
||||
// Some frontmatter may contain the upcoming GHES release number
|
||||
const next = '3.1'
|
||||
|
||||
const supported = [
|
||||
'3.0',
|
||||
'2.22',
|
||||
@@ -57,6 +60,7 @@ const deprecatedReleasesWithNewFormat = deprecated.filter(version => versionSati
|
||||
const deprecatedReleasesOnDeveloperSite = deprecated.filter(version => versionSatisfiesRange(version, '<=2.16'))
|
||||
|
||||
module.exports = {
|
||||
next,
|
||||
supported,
|
||||
deprecated,
|
||||
legacyAssetVersions,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
const allVersions = require('./all-versions')
|
||||
const { next } = require('./enterprise-server-releases')
|
||||
const versionSatisfiesRange = require('./version-satisfies-range')
|
||||
|
||||
// return an array of versions that an article's product versions encompasses
|
||||
@@ -15,6 +16,8 @@ function getApplicableVersions (frontmatterVersions, filepath) {
|
||||
// get an array like: [ 'free-pro-team@latest', 'enterprise-server@2.21', 'enterprise-cloud@latest' ]
|
||||
const applicableVersions = []
|
||||
|
||||
let nextVersion = false
|
||||
|
||||
// where frontmatter is something like:
|
||||
// free-pro-team: '*'
|
||||
// enterprise-server: '>=2.19'
|
||||
@@ -23,6 +26,15 @@ function getApplicableVersions (frontmatterVersions, filepath) {
|
||||
// ^ where each key corresponds to a plan
|
||||
Object.entries(frontmatterVersions)
|
||||
.forEach(([plan, planValue]) => {
|
||||
// Special handling for frontmatter that evalues to the next GHES release number or a hardcoded `next`:
|
||||
// we don't want to return it in the applicable versions array or it will become a permalink,
|
||||
// but we also don't want to throw an error if no other versions are found.
|
||||
if (planValue !== '*') {
|
||||
if (versionSatisfiesRange(next, planValue) || planValue === 'next') {
|
||||
nextVersion = true
|
||||
}
|
||||
}
|
||||
|
||||
// for each plan (e.g., enterprise-server), get matching versions from allVersions object
|
||||
const relevantVersions = Object.values(allVersions).filter(v => v.plan === plan)
|
||||
|
||||
@@ -42,7 +54,7 @@ function getApplicableVersions (frontmatterVersions, filepath) {
|
||||
})
|
||||
})
|
||||
|
||||
if (!applicableVersions.length) {
|
||||
if (!applicableVersions.length && !nextVersion) {
|
||||
throw new Error(`No applicable versions found for ${filepath}. Please double-check the page's \`versions\` frontmatter.`)
|
||||
}
|
||||
|
||||
|
||||
5
tests/fixtures/page-versioned-for-ghae-next.md
vendored
Normal file
5
tests/fixtures/page-versioned-for-ghae-next.md
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
title: Page versioned for next GitHub AE release
|
||||
versions:
|
||||
github-ae: 'next'
|
||||
---
|
||||
5
tests/fixtures/page-versioned-for-next-enterprise-release.md
vendored
Normal file
5
tests/fixtures/page-versioned-for-next-enterprise-release.md
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
title: Page versioned for next Enterprise release
|
||||
versions:
|
||||
enterprise-server: '>=3.1'
|
||||
---
|
||||
@@ -190,6 +190,36 @@ describe('Page class', () => {
|
||||
expect($.text()).not.toBe('This text should render on any actively supported version of Enterprise Server')
|
||||
expect($.text()).toBe('This text should only render on non-Enterprise')
|
||||
})
|
||||
|
||||
test('support next to-be-released Enterprise Server version in frontmatter', async () => {
|
||||
// This fixture has `enterprise-server: '>=3.1'` hardcoded in the frontmatter
|
||||
const page = await Page.init({
|
||||
relativePath: 'page-versioned-for-next-enterprise-release.md',
|
||||
basePath: path.join(__dirname, '../fixtures'),
|
||||
languageCode: 'en'
|
||||
})
|
||||
// set version to 3.0
|
||||
const context = {
|
||||
currentVersion: 'enterprise-server@3.0',
|
||||
currentLanguage: 'en'
|
||||
}
|
||||
await expect(() => { return page.render(context) }).not.toThrow()
|
||||
})
|
||||
|
||||
test('support next GitHub AE version in frontmatter', async () => {
|
||||
// This fixture has `github-ae: 'next'` hardcoded in the frontmatter
|
||||
const page = await Page.init({
|
||||
relativePath: 'page-versioned-for-ghae-next.md',
|
||||
basePath: path.join(__dirname, '../fixtures'),
|
||||
languageCode: 'en'
|
||||
})
|
||||
// set version to @latest
|
||||
const context = {
|
||||
currentVersion: 'github-ae@latest',
|
||||
currentLanguage: 'en'
|
||||
}
|
||||
await expect(() => { return page.render(context) }).not.toThrow()
|
||||
})
|
||||
})
|
||||
|
||||
test('preserves `languageCode`', async () => {
|
||||
|
||||
Reference in New Issue
Block a user