Skip to content

Commit 443d028

Browse files
authored
Merge pull request #18281 from github/support-next-release-in-frontmatter
Support next release in frontmatter
2 parents 4aa879e + 56d8ebd commit 443d028

5 files changed

Lines changed: 57 additions & 1 deletion

File tree

lib/enterprise-server-releases.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ const versionSatisfiesRange = require('./version-satisfies-range')
44
// enterprise-releases/docs/supported-versions.md#release-lifecycle-dates
55
const dates = require('../lib/enterprise-dates.json')
66

7+
// Some frontmatter may contain the upcoming GHES release number
8+
const next = '3.1'
9+
710
const supported = [
811
'3.0',
912
'2.22',
@@ -57,6 +60,7 @@ const deprecatedReleasesWithNewFormat = deprecated.filter(version => versionSati
5760
const deprecatedReleasesOnDeveloperSite = deprecated.filter(version => versionSatisfiesRange(version, '<=2.16'))
5861

5962
module.exports = {
63+
next,
6064
supported,
6165
deprecated,
6266
legacyAssetVersions,

lib/get-applicable-versions.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const allVersions = require('./all-versions')
2+
const { next } = require('./enterprise-server-releases')
23
const versionSatisfiesRange = require('./version-satisfies-range')
34

45
// return an array of versions that an article's product versions encompasses
@@ -15,6 +16,8 @@ function getApplicableVersions (frontmatterVersions, filepath) {
1516
// get an array like: [ 'free-pro-team@latest', 'enterprise-server@2.21', 'enterprise-cloud@latest' ]
1617
const applicableVersions = []
1718

19+
let nextVersion = false
20+
1821
// where frontmatter is something like:
1922
// free-pro-team: '*'
2023
// enterprise-server: '>=2.19'
@@ -23,6 +26,15 @@ function getApplicableVersions (frontmatterVersions, filepath) {
2326
// ^ where each key corresponds to a plan
2427
Object.entries(frontmatterVersions)
2528
.forEach(([plan, planValue]) => {
29+
// Special handling for frontmatter that evalues to the next GHES release number or a hardcoded `next`:
30+
// we don't want to return it in the applicable versions array or it will become a permalink,
31+
// but we also don't want to throw an error if no other versions are found.
32+
if (planValue !== '*') {
33+
if (versionSatisfiesRange(next, planValue) || planValue === 'next') {
34+
nextVersion = true
35+
}
36+
}
37+
2638
// for each plan (e.g., enterprise-server), get matching versions from allVersions object
2739
const relevantVersions = Object.values(allVersions).filter(v => v.plan === plan)
2840

@@ -42,7 +54,7 @@ function getApplicableVersions (frontmatterVersions, filepath) {
4254
})
4355
})
4456

45-
if (!applicableVersions.length) {
57+
if (!applicableVersions.length && !nextVersion) {
4658
throw new Error(`No applicable versions found for ${filepath}. Please double-check the page's \`versions\` frontmatter.`)
4759
}
4860

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
title: Page versioned for next GitHub AE release
3+
versions:
4+
github-ae: 'next'
5+
---
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
title: Page versioned for next Enterprise release
3+
versions:
4+
enterprise-server: '>=3.1'
5+
---

tests/unit/page.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,36 @@ describe('Page class', () => {
190190
expect($.text()).not.toBe('This text should render on any actively supported version of Enterprise Server')
191191
expect($.text()).toBe('This text should only render on non-Enterprise')
192192
})
193+
194+
test('support next to-be-released Enterprise Server version in frontmatter', async () => {
195+
// This fixture has `enterprise-server: '>=3.1'` hardcoded in the frontmatter
196+
const page = await Page.init({
197+
relativePath: 'page-versioned-for-next-enterprise-release.md',
198+
basePath: path.join(__dirname, '../fixtures'),
199+
languageCode: 'en'
200+
})
201+
// set version to 3.0
202+
const context = {
203+
currentVersion: 'enterprise-server@3.0',
204+
currentLanguage: 'en'
205+
}
206+
await expect(() => { return page.render(context) }).not.toThrow()
207+
})
208+
209+
test('support next GitHub AE version in frontmatter', async () => {
210+
// This fixture has `github-ae: 'next'` hardcoded in the frontmatter
211+
const page = await Page.init({
212+
relativePath: 'page-versioned-for-ghae-next.md',
213+
basePath: path.join(__dirname, '../fixtures'),
214+
languageCode: 'en'
215+
})
216+
// set version to @latest
217+
const context = {
218+
currentVersion: 'github-ae@latest',
219+
currentLanguage: 'en'
220+
}
221+
await expect(() => { return page.render(context) }).not.toThrow()
222+
})
193223
})
194224

195225
test('preserves `languageCode`', async () => {

0 commit comments

Comments
 (0)