add feature versions schema and tests
This commit is contained in:
@@ -13,6 +13,7 @@ const { tags } = require('../../lib/liquid-tags/extended-markdown')
|
||||
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 featureVersionsSchema = require('../helpers/schemas/feature-versions-schema')
|
||||
const renderContent = require('../../lib/render-content')
|
||||
const getApplicableVersions = require('../../lib/get-applicable-versions')
|
||||
const { execSync } = require('child_process')
|
||||
@@ -31,6 +32,7 @@ const glossariesDir = path.join(rootDir, 'data/glossaries')
|
||||
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 featureVersionsDir = path.join(rootDir, 'data/features')
|
||||
|
||||
const languageCodes = Object.keys(languages)
|
||||
|
||||
@@ -186,7 +188,7 @@ const yamlWalkOptions = {
|
||||
}
|
||||
|
||||
// different lint rules apply to different content types
|
||||
let mdToLint, ymlToLint, ghesReleaseNotesToLint, ghaeReleaseNotesToLint, learningTracksToLint
|
||||
let mdToLint, ymlToLint, ghesReleaseNotesToLint, ghaeReleaseNotesToLint, learningTracksToLint, featureVersionsToLint
|
||||
|
||||
if (!process.env.TEST_TRANSLATION) {
|
||||
// compile lists of all the files we want to lint
|
||||
@@ -227,6 +229,11 @@ if (!process.env.TEST_TRANSLATION) {
|
||||
const learningTracksYamlAbsPaths = walk(learningTracks, yamlWalkOptions).sort()
|
||||
const learningTracksYamlRelPaths = learningTracksYamlAbsPaths.map(p => slash(path.relative(rootDir, p)))
|
||||
learningTracksToLint = zip(learningTracksYamlRelPaths, learningTracksYamlAbsPaths)
|
||||
|
||||
// Feature versions
|
||||
const featureVersionsYamlAbsPaths = walk(featureVersionsDir, yamlWalkOptions).sort()
|
||||
const featureVersionsYamlRelPaths = featureVersionsYamlAbsPaths.map(p => slash(path.relative(rootDir, p)))
|
||||
featureVersionsToLint = zip(featureVersionsYamlRelPaths, featureVersionsYamlAbsPaths)
|
||||
} else {
|
||||
// get all translated markdown or yaml files by comparing files changed to main branch
|
||||
const changedFilesRelPaths = execSync('git -c diff.renameLimit=10000 diff --name-only origin/main | egrep "^translations/.*/.+.(yml|md)$"', { maxBuffer: 1024 * 1024 * 100 }).toString().split('\n')
|
||||
@@ -236,7 +243,14 @@ if (!process.env.TEST_TRANSLATION) {
|
||||
|
||||
console.log(`Found ${changedFilesRelPaths.length} translated files.`)
|
||||
|
||||
const { mdRelPaths = [], ymlRelPaths = [], ghesReleaseNotesRelPaths = [], ghaeReleaseNotesRelPaths = [], learningTracksRelPaths = [] } = groupBy(changedFilesRelPaths, (path) => {
|
||||
const {
|
||||
mdRelPaths = [],
|
||||
ymlRelPaths = [],
|
||||
ghesReleaseNotesRelPaths = [],
|
||||
ghaeReleaseNotesRelPaths = [],
|
||||
learningTracksRelPaths = [],
|
||||
featureVersionsRelPaths = [],
|
||||
} = groupBy(changedFilesRelPaths, (path) => {
|
||||
// separate the changed files to different groups
|
||||
if (path.endsWith('README.md')) {
|
||||
return 'throwAway'
|
||||
@@ -250,13 +264,29 @@ if (!process.env.TEST_TRANSLATION) {
|
||||
return 'ghaeReleaseNotesRelPaths'
|
||||
} else if (path.match(/\data\/learning-tracks/)) {
|
||||
return 'learningTracksRelPaths'
|
||||
} else if (path.match(/\data\/features/)) {
|
||||
return 'featureVersionsRelPaths'
|
||||
} else {
|
||||
// we aren't linting the rest
|
||||
return 'throwAway'
|
||||
}
|
||||
})
|
||||
|
||||
const [mdTuples, ymlTuples, ghesReleaseNotesTuples, ghaeReleaseNotesTuples, learningTracksTuples] = [mdRelPaths, ymlRelPaths, ghesReleaseNotesRelPaths, ghaeReleaseNotesRelPaths, learningTracksRelPaths].map(relPaths => {
|
||||
const [
|
||||
mdTuples,
|
||||
ymlTuples,
|
||||
ghesReleaseNotesTuples,
|
||||
ghaeReleaseNotesTuples,
|
||||
learningTracksTuples,
|
||||
featureVersionsTuples
|
||||
] = [
|
||||
mdRelPaths,
|
||||
ymlRelPaths,
|
||||
ghesReleaseNotesRelPaths,
|
||||
ghaeReleaseNotesRelPaths,
|
||||
learningTracksRelPaths,
|
||||
featureVersionsRelPaths
|
||||
].map(relPaths => {
|
||||
const absPaths = relPaths.map(p => path.join(rootDir, p))
|
||||
return zip(relPaths, absPaths)
|
||||
})
|
||||
@@ -266,6 +296,7 @@ if (!process.env.TEST_TRANSLATION) {
|
||||
ghesReleaseNotesToLint = ghesReleaseNotesTuples
|
||||
ghaeReleaseNotesToLint = ghaeReleaseNotesTuples
|
||||
learningTracksToLint = learningTracksTuples
|
||||
featureVersionsToLint = featureVersionsTuples
|
||||
}
|
||||
|
||||
function formatLinkError(message, links) {
|
||||
@@ -887,6 +918,38 @@ describe('lint learning tracks', () => {
|
||||
)
|
||||
})
|
||||
|
||||
describe('lint feature versions', () => {
|
||||
if (featureVersionsToLint.length < 1) return
|
||||
describe.each(featureVersionsToLint)(
|
||||
'%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, featureVersionsSchema)
|
||||
|
||||
const errorMessage = errors.map(error => {
|
||||
// Make this one message a little more readable than the error we get from revalidator
|
||||
// when additionalProperties is set to false and an additional prop is found.
|
||||
const errorToReport = error.message === 'must not exist' && error.actual.feature
|
||||
? `feature: '${error.actual.feature}'`
|
||||
: JSON.stringify(error.actual, null, 2)
|
||||
|
||||
return `- [${error.property}]: ${errorToReport}, ${error.message}`
|
||||
})
|
||||
.join('\n')
|
||||
|
||||
expect(errors.length, errorMessage).toBe(0)
|
||||
})
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
function validateVersion (version) {
|
||||
return versionShortNames.includes(version) ||
|
||||
versionShortNameExceptions.some(exception => version.startsWith(exception))
|
||||
|
||||
Reference in New Issue
Block a user