1
0
mirror of synced 2025-12-21 10:57:10 -05:00

exercise the GHAE schema in lint-files

This commit is contained in:
Sarah Schneider
2021-05-28 11:32:41 -04:00
parent 70f7384b75
commit 49166811f5

View File

@@ -10,7 +10,8 @@ const readFileAsync = require('../../lib/readfile-async')
const frontmatter = require('../../lib/frontmatter') const frontmatter = require('../../lib/frontmatter')
const languages = require('../../lib/languages') const languages = require('../../lib/languages')
const { tags } = require('../../lib/liquid-tags/extended-markdown') const { tags } = require('../../lib/liquid-tags/extended-markdown')
const ghesReleaseNotesSchema = require('../helpers/schemas/release-notes-schema') const ghesReleaseNotesSchema = require('../helpers/schemas/ghes-release-notes-schema')
const ghaeReleaseNotesSchema = require('../helpers/schemas/ghae-release-notes-schema')
const learningTracksSchema = require('../helpers/schemas/learning-tracks-schema') const learningTracksSchema = require('../helpers/schemas/learning-tracks-schema')
const renderContent = require('../../lib/render-content') const renderContent = require('../../lib/render-content')
const { execSync } = require('child_process') const { execSync } = require('child_process')
@@ -22,7 +23,8 @@ const contentDir = path.join(rootDir, 'content')
const reusablesDir = path.join(rootDir, 'data/reusables') const reusablesDir = path.join(rootDir, 'data/reusables')
const variablesDir = path.join(rootDir, 'data/variables') const variablesDir = path.join(rootDir, 'data/variables')
const glossariesDir = path.join(rootDir, 'data/glossaries') const glossariesDir = path.join(rootDir, 'data/glossaries')
const ghesReleaseNotesDir = path.join(rootDir, 'data/release-notes') const ghesReleaseNotesDir = path.join(rootDir, 'data/release-notes/enterprise-server')
const ghaeReleaseNotesDir = path.join(rootDir, 'data/release-notes/github-ae')
const learningTracks = path.join(rootDir, 'data/learning-tracks') const learningTracks = path.join(rootDir, 'data/learning-tracks')
const languageCodes = Object.keys(languages) const languageCodes = Object.keys(languages)
@@ -171,7 +173,7 @@ const yamlWalkOptions = {
} }
// different lint rules apply to different content types // different lint rules apply to different content types
let mdToLint, ymlToLint, releaseNotesToLint, learningTracksToLint let mdToLint, ymlToLint, ghesReleaseNotesToLint, ghaeReleaseNotesToLint, learningTracksToLint
if (!process.env.TEST_TRANSLATION) { if (!process.env.TEST_TRANSLATION) {
// compile lists of all the files we want to lint // compile lists of all the files we want to lint
@@ -201,7 +203,12 @@ if (!process.env.TEST_TRANSLATION) {
// GHES release notes // GHES release notes
const ghesReleaseNotesYamlAbsPaths = walk(ghesReleaseNotesDir, yamlWalkOptions).sort() const ghesReleaseNotesYamlAbsPaths = walk(ghesReleaseNotesDir, yamlWalkOptions).sort()
const ghesReleaseNotesYamlRelPaths = ghesReleaseNotesYamlAbsPaths.map(p => slash(path.relative(rootDir, p))) const ghesReleaseNotesYamlRelPaths = ghesReleaseNotesYamlAbsPaths.map(p => slash(path.relative(rootDir, p)))
releaseNotesToLint = zip(ghesReleaseNotesYamlRelPaths, ghesReleaseNotesYamlAbsPaths) ghesReleaseNotesToLint = zip(ghesReleaseNotesYamlRelPaths, ghesReleaseNotesYamlAbsPaths)
// GHAE release notes
const ghaeReleaseNotesYamlAbsPaths = walk(ghaeReleaseNotesDir, yamlWalkOptions).sort()
const ghaeReleaseNotesYamlRelPaths = ghaeReleaseNotesYamlAbsPaths.map(p => slash(path.relative(rootDir, p)))
ghaeReleaseNotesToLint = zip(ghaeReleaseNotesYamlRelPaths, ghaeReleaseNotesYamlAbsPaths)
// Learning tracks // Learning tracks
const learningTracksYamlAbsPaths = walk(learningTracks, yamlWalkOptions).sort() const learningTracksYamlAbsPaths = walk(learningTracks, yamlWalkOptions).sort()
@@ -216,7 +223,7 @@ if (!process.env.TEST_TRANSLATION) {
console.log(`Found ${changedFilesRelPaths.length} translated files.`) console.log(`Found ${changedFilesRelPaths.length} translated files.`)
const { mdRelPaths = [], ymlRelPaths = [], releaseNotesRelPaths = [], learningTracksRelPaths = [] } = groupBy(changedFilesRelPaths, (path) => { const { mdRelPaths = [], ymlRelPaths = [], ghesReleaseNotesRelPaths = [], ghaeReleaseNotesRelPaths = [], learningTracksRelPaths = [] } = groupBy(changedFilesRelPaths, (path) => {
// separate the changed files to different groups // separate the changed files to different groups
if (path.endsWith('README.md')) { if (path.endsWith('README.md')) {
return 'throwAway' return 'throwAway'
@@ -224,8 +231,10 @@ if (!process.env.TEST_TRANSLATION) {
return 'mdRelPaths' return 'mdRelPaths'
} else if (path.match(/\/data\/(variables|glossaries)\//i)) { } else if (path.match(/\/data\/(variables|glossaries)\//i)) {
return 'ymlRelPaths' return 'ymlRelPaths'
} else if (path.match(/\/data\/release-notes\//i)) { } else if (path.match(/\/data\/release-notes\/enterprise-server/i)) {
return 'releaseNotesRelPaths' return 'ghesReleaseNotesRelPaths'
} else if (path.match(/\/data\/release-notes\/github-ae/i)) {
return 'ghaeReleaseNotesRelPaths'
} else if (path.match(/\data\/learning-tracks/)) { } else if (path.match(/\data\/learning-tracks/)) {
return 'learningTracksRelPaths' return 'learningTracksRelPaths'
} else { } else {
@@ -234,14 +243,15 @@ if (!process.env.TEST_TRANSLATION) {
} }
}) })
const [mdTuples, ymlTuples, releaseNotesTuples, learningTracksTuples] = [mdRelPaths, ymlRelPaths, releaseNotesRelPaths, learningTracksRelPaths].map(relPaths => { const [mdTuples, ymlTuples, ghesReleaseNotesTuples, ghaeReleaseNotesTuples, learningTracksTuples] = [mdRelPaths, ymlRelPaths, ghesReleaseNotesRelPaths, ghaeReleaseNotesRelPaths, learningTracksRelPaths].map(relPaths => {
const absPaths = relPaths.map(p => path.join(rootDir, p)) const absPaths = relPaths.map(p => path.join(rootDir, p))
return zip(relPaths, absPaths) return zip(relPaths, absPaths)
}) })
mdToLint = mdTuples mdToLint = mdTuples
ymlToLint = ymlTuples ymlToLint = ymlTuples
releaseNotesToLint = releaseNotesTuples ghesReleaseNotesToLint = ghesReleaseNotesTuples
ghaeReleaseNotesToLint = ghaeReleaseNotesTuples
learningTracksToLint = learningTracksTuples learningTracksToLint = learningTracksTuples
} }
@@ -661,9 +671,9 @@ describe('lint yaml content', () => {
) )
}) })
describe('lint release notes', () => { describe('lint GHES release notes', () => {
if (releaseNotesToLint.length < 1) return if (ghesReleaseNotesToLint.length < 1) return
describe.each(releaseNotesToLint)( describe.each(ghesReleaseNotesToLint)(
'%s', '%s',
(yamlRelPath, yamlAbsPath) => { (yamlRelPath, yamlAbsPath) => {
let dictionary let dictionary
@@ -707,6 +717,59 @@ describe('lint release notes', () => {
) )
}) })
describe('lint GHAE release notes', () => {
if (ghaeReleaseNotesToLint.length < 1) return
const currentWeeksFound = []
describe.each(ghaeReleaseNotesToLint)(
'%s',
(yamlRelPath, yamlAbsPath) => {
let dictionary
beforeAll(async () => {
const fileContents = await readFileAsync(yamlAbsPath, 'utf8')
dictionary = yaml.load(fileContents, { filename: yamlRelPath })
})
it('matches the schema', () => {
const { errors } = revalidator.validate(dictionary, ghaeReleaseNotesSchema)
const errorMessage = errors.map(error => `- [${error.property}]: ${error.actual}, ${error.message}`).join('\n')
expect(errors.length, errorMessage).toBe(0)
})
it('does not have more than one yaml file with currentWeek set to true', () => {
if (dictionary.currentWeek) currentWeeksFound.push(yamlRelPath)
const errorMessage = `Found more than one file with currentWeek set to true: ${currentWeeksFound.join('\n')}`
expect(currentWeeksFound.length, errorMessage).not.toBeGreaterThan(1)
})
it('contains valid liquid', () => {
const { intro, sections } = dictionary
let toLint = { intro }
for (const key in sections) {
const section = sections[key]
const label = `sections.${key}`
section.forEach((part) => {
if (Array.isArray(part)) {
toLint = { ...toLint, ...{ [label]: section.join('\n') } }
} else {
for (const prop in section) {
toLint = { ...toLint, ...{ [`${label}.${prop}`]: section[prop] } }
}
}
})
}
for (const key in toLint) {
if (!toLint[key]) continue
expect(() => renderContent.liquid.parse(toLint[key]), `${key} contains invalid liquid`)
.not
.toThrow()
}
})
}
)
})
describe('lint learning tracks', () => { describe('lint learning tracks', () => {
if (learningTracksToLint.length < 1) return if (learningTracksToLint.length < 1) return
describe.each(learningTracksToLint)( describe.each(learningTracksToLint)(