Skip to content

Commit edd9343

Browse files
authored
Merge branch 'main' into script-to-move-toc-links-into-frontmatter
2 parents 4caecee + 071317d commit edd9343

2 files changed

Lines changed: 42 additions & 39 deletions

File tree

script/enterprise-server-releases/create-graphql-files.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,15 @@ const objectsFile = path.join(graphqlStaticDir, 'prerendered-objects.json')
5555
const previews = require(previewsFile)
5656
const changes = require(changesFile)
5757
const objects = require(objectsFile)
58+
// The prerendered objects file for the "old version" contains hardcoded links with the old version number.
59+
// We need to update those links to include the new version to prevent a test from failing.
60+
const regexOldVersion = new RegExp(oldVersion, 'gi')
61+
const stringifiedObject = JSON.stringify(objects[oldVersionId])
62+
.replace(regexOldVersion, newVersion)
5863

5964
previews[newVersionId] = previews[oldVersionId]
6065
changes[newVersionId] = changes[oldVersionId]
61-
objects[newVersionId] = objects[oldVersionId]
66+
objects[newVersionId] = JSON.parse(stringifiedObject)
6267

6368
// check that it worked
6469
if (!Object.keys(previews).includes(newVersionId)) {

script/enterprise-server-releases/create-rest-files.js

Lines changed: 36 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@ const fs = require('fs')
44
const path = require('path')
55
const program = require('commander')
66
const allVersions = require('../../lib/all-versions')
7+
const getOperations = require('../rest/utils/get-operations')
78
const dereferencedDir = 'lib/rest/static/dereferenced'
89
const decoratedDir = 'lib/rest/static/decorated'
910

1011
// [start-readme]
1112
//
12-
// This script creates new static openAPI files for a new version and modifies the info.version.
13+
// This script first copies the dereferenced schema from the previous GHES version for the new one.
14+
// It then replaces references to the previous version's docs URL (e.g., enterprise-server@3.0) with the new version (e.g., enterprise-server@3.1).
15+
// Finally, it generates a new decorated file from the new dereferenced file to ensure that the dereferenced and decorated files match.
1316
//
1417
// [end-readme]
1518

@@ -32,48 +35,43 @@ if (!(Object.keys(allVersions).includes(newVersion) && Object.keys(allVersions).
3235
process.exit(1)
3336
}
3437

35-
const oldDereferencedFilename = `${allVersions[oldVersion].openApiVersionName}.deref.json`
36-
const newDereferencedFilename = `${allVersions[newVersion].openApiVersionName}.deref.json`
37-
const oldDecoratedFilename = `${allVersions[oldVersion].openApiVersionName}.json`
38-
const newDecoratedFilename = `${allVersions[newVersion].openApiVersionName}.json`
38+
main()
3939

40-
const oldDereferencedFile = path.join(dereferencedDir, oldDereferencedFilename)
41-
const newDereferencedFile = path.join(dereferencedDir, newDereferencedFilename)
42-
const oldDecoratedFile = path.join(decoratedDir, oldDecoratedFilename)
43-
const newDecoratedFile = path.join(decoratedDir, newDecoratedFilename)
40+
async function main () {
41+
const oldDereferencedFilename = `${allVersions[oldVersion].openApiVersionName}.deref.json`
42+
const newDereferencedFilename = `${allVersions[newVersion].openApiVersionName}.deref.json`
43+
const newDecoratedFilename = `${allVersions[newVersion].openApiVersionName}.json`
4444

45-
// check that the old files exist
46-
if (!fs.existsSync(oldDereferencedFile)) {
47-
console.log(`Error! Can't find ${oldDereferencedFile} for ${oldVersion}.`)
48-
process.exit(1)
49-
}
45+
const oldDereferencedFile = path.join(dereferencedDir, oldDereferencedFilename)
46+
const newDereferencedFile = path.join(dereferencedDir, newDereferencedFilename)
47+
const newDecoratedFile = path.join(decoratedDir, newDecoratedFilename)
5048

51-
if (!fs.existsSync(oldDecoratedFile)) {
52-
console.log(`Error! Can't find ${oldDecoratedFile} for ${oldVersion}.`)
53-
process.exit(1)
54-
}
49+
// check that the old files exist
50+
if (!fs.existsSync(oldDereferencedFile)) {
51+
console.log(`Error! Can't find ${oldDereferencedFile} for ${oldVersion}.`)
52+
process.exit(1)
53+
}
5554

56-
// copy the files
57-
fs.copyFileSync(oldDereferencedFile, newDereferencedFile)
58-
fs.copyFileSync(oldDecoratedFile, newDecoratedFile)
55+
const oldDereferencedContent = fs.readFileSync(oldDereferencedFile, 'utf8')
5956

60-
// check that it worked
61-
if (!fs.existsSync(newDereferencedFile)) {
62-
console.log(`Error! Can't find ${newDereferencedFile} for ${oldVersion}.`)
63-
process.exit(1)
64-
}
57+
// Replace old version with new version
58+
// (ex: enterprise-server@3.0 -> enterprise-server@3.1)
59+
const regexOldVersion = new RegExp(oldVersion, 'gi')
60+
const newDereferenceContent = oldDereferencedContent.replace(regexOldVersion, newVersion)
6561

66-
if (!fs.existsSync(newDecoratedFile)) {
67-
console.log(`Error! Can't find ${newDecoratedFile} for ${oldVersion}.`)
68-
process.exit(1)
69-
}
62+
// Write processed dereferenced schema to disk
63+
fs.writeFileSync(newDereferencedFile, newDereferenceContent)
64+
console.log(`Created ${newDereferencedFile}.`)
65+
66+
const dereferencedSchema = require(path.join(process.cwd(), newDereferencedFile))
7067

71-
// set the info.version to development mode
72-
const derefFilepath = path.join(process.cwd(), newDereferencedFile)
73-
const derefSchema = require(derefFilepath)
74-
console.log(derefSchema.info.version)
75-
derefSchema.info.version = `Copy of ${oldVersion} !!DEVELOPMENT MODE - DO NOT MERGE!!`
76-
fs.writeFileSync(derefFilepath, JSON.stringify(derefSchema, null, 2))
68+
// Store all operations in an array of operation objects
69+
const operations = await getOperations(dereferencedSchema)
7770

78-
// print success message
79-
console.log(`Done! Created ${newDereferencedFile} and ${newDecoratedFile}.`)
71+
// Process each operation asynchronously
72+
await Promise.all(operations.map(operation => operation.process()))
73+
74+
// Write processed operations to disk
75+
fs.writeFileSync(newDecoratedFile, JSON.stringify(operations, null, 2))
76+
console.log(`Done! Created ${newDecoratedFile}.`)
77+
}

0 commit comments

Comments
 (0)