1
0
mirror of synced 2025-12-19 18:10:59 -05:00

Tweak the rest api ghes release script (#18509)

This commit is contained in:
Rachael Sewell
2021-03-31 10:22:25 -07:00
committed by GitHub
parent af89030b21
commit 071317da3d
2 changed files with 47 additions and 44 deletions

View File

@@ -55,10 +55,15 @@ const objectsFile = path.join(graphqlStaticDir, 'prerendered-objects.json')
const previews = require(previewsFile)
const changes = require(changesFile)
const objects = require(objectsFile)
// The prerendered objects file for the "old version" contains hardcoded links with the old version number.
// We need to update those links to include the new version to prevent a test from failing.
const regexOldVersion = new RegExp(oldVersion, 'gi')
const stringifiedObject = JSON.stringify(objects[oldVersionId])
.replace(regexOldVersion, newVersion)
previews[newVersionId] = previews[oldVersionId]
changes[newVersionId] = changes[oldVersionId]
objects[newVersionId] = objects[oldVersionId]
objects[newVersionId] = JSON.parse(stringifiedObject)
// check that it worked
if (!Object.keys(previews).includes(newVersionId)) {

View File

@@ -4,12 +4,15 @@ const fs = require('fs')
const path = require('path')
const program = require('commander')
const allVersions = require('../../lib/all-versions')
const getOperations = require('../rest/utils/get-operations')
const dereferencedDir = 'lib/rest/static/dereferenced'
const decoratedDir = 'lib/rest/static/decorated'
// [start-readme]
//
// This script creates new static openAPI files for a new version and modifies the info.version.
// This script first copies the dereferenced schema from the previous GHES version for the new one.
// 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).
// Finally, it generates a new decorated file from the new dereferenced file to ensure that the dereferenced and decorated files match.
//
// [end-readme]
@@ -32,48 +35,43 @@ if (!(Object.keys(allVersions).includes(newVersion) && Object.keys(allVersions).
process.exit(1)
}
const oldDereferencedFilename = `${allVersions[oldVersion].openApiVersionName}.deref.json`
const newDereferencedFilename = `${allVersions[newVersion].openApiVersionName}.deref.json`
const oldDecoratedFilename = `${allVersions[oldVersion].openApiVersionName}.json`
const newDecoratedFilename = `${allVersions[newVersion].openApiVersionName}.json`
main()
const oldDereferencedFile = path.join(dereferencedDir, oldDereferencedFilename)
const newDereferencedFile = path.join(dereferencedDir, newDereferencedFilename)
const oldDecoratedFile = path.join(decoratedDir, oldDecoratedFilename)
const newDecoratedFile = path.join(decoratedDir, newDecoratedFilename)
async function main () {
const oldDereferencedFilename = `${allVersions[oldVersion].openApiVersionName}.deref.json`
const newDereferencedFilename = `${allVersions[newVersion].openApiVersionName}.deref.json`
const newDecoratedFilename = `${allVersions[newVersion].openApiVersionName}.json`
// check that the old files exist
if (!fs.existsSync(oldDereferencedFile)) {
console.log(`Error! Can't find ${oldDereferencedFile} for ${oldVersion}.`)
process.exit(1)
const oldDereferencedFile = path.join(dereferencedDir, oldDereferencedFilename)
const newDereferencedFile = path.join(dereferencedDir, newDereferencedFilename)
const newDecoratedFile = path.join(decoratedDir, newDecoratedFilename)
// check that the old files exist
if (!fs.existsSync(oldDereferencedFile)) {
console.log(`Error! Can't find ${oldDereferencedFile} for ${oldVersion}.`)
process.exit(1)
}
const oldDereferencedContent = fs.readFileSync(oldDereferencedFile, 'utf8')
// Replace old version with new version
// (ex: enterprise-server@3.0 -> enterprise-server@3.1)
const regexOldVersion = new RegExp(oldVersion, 'gi')
const newDereferenceContent = oldDereferencedContent.replace(regexOldVersion, newVersion)
// Write processed dereferenced schema to disk
fs.writeFileSync(newDereferencedFile, newDereferenceContent)
console.log(`Created ${newDereferencedFile}.`)
const dereferencedSchema = require(path.join(process.cwd(), newDereferencedFile))
// Store all operations in an array of operation objects
const operations = await getOperations(dereferencedSchema)
// Process each operation asynchronously
await Promise.all(operations.map(operation => operation.process()))
// Write processed operations to disk
fs.writeFileSync(newDecoratedFile, JSON.stringify(operations, null, 2))
console.log(`Done! Created ${newDecoratedFile}.`)
}
if (!fs.existsSync(oldDecoratedFile)) {
console.log(`Error! Can't find ${oldDecoratedFile} for ${oldVersion}.`)
process.exit(1)
}
// copy the files
fs.copyFileSync(oldDereferencedFile, newDereferencedFile)
fs.copyFileSync(oldDecoratedFile, newDecoratedFile)
// check that it worked
if (!fs.existsSync(newDereferencedFile)) {
console.log(`Error! Can't find ${newDereferencedFile} for ${oldVersion}.`)
process.exit(1)
}
if (!fs.existsSync(newDecoratedFile)) {
console.log(`Error! Can't find ${newDecoratedFile} for ${oldVersion}.`)
process.exit(1)
}
// set the info.version to development mode
const derefFilepath = path.join(process.cwd(), newDereferencedFile)
const derefSchema = require(derefFilepath)
console.log(derefSchema.info.version)
derefSchema.info.version = `Copy of ${oldVersion} !!DEVELOPMENT MODE - DO NOT MERGE!!`
fs.writeFileSync(derefFilepath, JSON.stringify(derefSchema, null, 2))
// print success message
console.log(`Done! Created ${newDereferencedFile} and ${newDecoratedFile}.`)