GitHub AE (GHAE) (#16090)
This commit is contained in:
@@ -4,13 +4,12 @@ const fs = require('fs')
|
||||
const path = require('path')
|
||||
const mkdirp = require('mkdirp').sync
|
||||
const yaml = require('js-yaml')
|
||||
const assert = require('assert')
|
||||
const { execSync } = require('child_process')
|
||||
const graphqlDataDir = path.join(process.cwd(), 'data/graphql')
|
||||
const graphqlStaticDir = path.join(process.cwd(), 'lib/graphql/static')
|
||||
const { getContents } = require('../../lib/git-utils')
|
||||
const { getContents, listMatchingRefs } = require('../../lib/git-utils')
|
||||
const dataFilenames = require('./utils/data-filenames')
|
||||
const { oldVersions } = require('../../lib/old-versions-utils')
|
||||
const allVersions = require('../../lib/all-versions')
|
||||
const processPreviews = require('./utils/process-previews')
|
||||
const processUpcomingChanges = require('./utils/process-upcoming-changes')
|
||||
const processSchemas = require('./utils/process-schemas')
|
||||
@@ -20,16 +19,7 @@ const prerenderObjects = require('./utils/prerender-objects')
|
||||
// as soon as 2.20 is deprecated on 2021-02-11, we can remove all graphql-ruby filtering
|
||||
const removeHiddenMembersScript = path.join(__dirname, './utils/remove-hidden-schema-members.rb')
|
||||
|
||||
// optionally build only 'dotcom' or any GHE version by passing the number ('2.20')
|
||||
// TODO need to update this to the new versions
|
||||
// for now, fall back to the old versions for use in schema filenames
|
||||
let versionsToBuild = oldVersions
|
||||
|
||||
if (process.argv.length === 3) {
|
||||
const version = process.argv[2]
|
||||
assert(oldVersions.includes(version), `'${version}' is not valid! must be one of: ${oldVersions}`)
|
||||
versionsToBuild = [version]
|
||||
}
|
||||
const versionsToBuild = Object.keys(allVersions)
|
||||
|
||||
main()
|
||||
|
||||
@@ -39,30 +29,36 @@ async function main () {
|
||||
const prerenderedObjects = {}
|
||||
|
||||
for (const version of versionsToBuild) {
|
||||
// Get the relevant GraphQL name for the current version
|
||||
// For example, free-pro-team@latest corresponds to dotcom,
|
||||
// enterprise-server@2.22 corresponds to ghes-2.22,
|
||||
// and github-ae@latest corresponds to ghae
|
||||
const graphqlVersion = allVersions[version].miscVersionName
|
||||
|
||||
// 1. UPDATE PREVIEWS
|
||||
const previewsPath = getDataFilepath('previews', version)
|
||||
const safeForPublicPreviews = yaml.safeLoad(await getRemoteRawContent(previewsPath, version))
|
||||
const previewsPath = getDataFilepath('previews', graphqlVersion)
|
||||
const safeForPublicPreviews = yaml.safeLoad(await getRemoteRawContent(previewsPath, graphqlVersion))
|
||||
updateFile(previewsPath, yaml.safeDump(safeForPublicPreviews))
|
||||
previewsJson[version] = processPreviews(safeForPublicPreviews)
|
||||
previewsJson[graphqlVersion] = processPreviews(safeForPublicPreviews)
|
||||
|
||||
// 2. UPDATE UPCOMING CHANGES
|
||||
const upcomingChangesPath = getDataFilepath('upcomingChanges', version)
|
||||
const safeForPublicChanges = await getRemoteRawContent(upcomingChangesPath, version)
|
||||
const upcomingChangesPath = getDataFilepath('upcomingChanges', graphqlVersion)
|
||||
const safeForPublicChanges = await getRemoteRawContent(upcomingChangesPath, graphqlVersion)
|
||||
updateFile(upcomingChangesPath, safeForPublicChanges)
|
||||
upcomingChangesJson[version] = await processUpcomingChanges(safeForPublicChanges)
|
||||
upcomingChangesJson[graphqlVersion] = await processUpcomingChanges(safeForPublicChanges)
|
||||
|
||||
// 3. UPDATE SCHEMAS
|
||||
// note: schemas live in separate files per version
|
||||
const schemaPath = getDataFilepath('schemas', version)
|
||||
const latestSchema = await getRemoteRawContent(schemaPath, version)
|
||||
const schemaPath = getDataFilepath('schemas', graphqlVersion)
|
||||
const latestSchema = await getRemoteRawContent(schemaPath, graphqlVersion)
|
||||
const safeForPublicSchema = removeHiddenMembers(schemaPath, latestSchema)
|
||||
updateFile(schemaPath, safeForPublicSchema)
|
||||
const schemaJsonPerVersion = await processSchemas(safeForPublicSchema, safeForPublicPreviews)
|
||||
updateStaticFile(schemaJsonPerVersion, path.join(graphqlStaticDir, `schema-${version}.json`))
|
||||
updateStaticFile(schemaJsonPerVersion, path.join(graphqlStaticDir, `schema-${graphqlVersion}.json`))
|
||||
|
||||
// 4. PRERENDER OBJECTS HTML
|
||||
// because the objects page is too big to render on page load
|
||||
prerenderedObjects[version] = await prerenderObjects(schemaJsonPerVersion)
|
||||
prerenderedObjects[graphqlVersion] = await prerenderObjects(schemaJsonPerVersion)
|
||||
}
|
||||
|
||||
updateStaticFile(previewsJson, path.join(graphqlStaticDir, 'previews.json'))
|
||||
@@ -71,21 +67,66 @@ async function main () {
|
||||
}
|
||||
|
||||
// get latest from github/github
|
||||
async function getRemoteRawContent (filepath, version) {
|
||||
async function getRemoteRawContent (filepath, graphqlVersion) {
|
||||
const options = {
|
||||
owner: 'github',
|
||||
repo: 'github',
|
||||
ref: version === 'dotcom' ? 'master' : `enterprise-${version}-release`,
|
||||
path: `config/${path.basename(filepath)}`
|
||||
repo: 'github'
|
||||
}
|
||||
|
||||
// find the relevant branch in github/github and set it as options.ref
|
||||
await setBranchAsRef(options, graphqlVersion)
|
||||
|
||||
// add the filepath to the options so we can get the contents of the file
|
||||
options.path = `config/${path.basename(filepath)}`
|
||||
|
||||
return getContents(...Object.values(options))
|
||||
}
|
||||
|
||||
function getDataFilepath (id, version) {
|
||||
return version === 'dotcom'
|
||||
? path.join(graphqlDataDir, dataFilenames[id].dotcom)
|
||||
: path.join(graphqlDataDir, version, dataFilenames[id].enterprise)
|
||||
// find the relevant filepath in script/graphql/utils/data-filenames.json
|
||||
function getDataFilepath (id, graphqlVersion) {
|
||||
const versionType = getVersionType(graphqlVersion)
|
||||
|
||||
// for example, dataFilenames['schema']['ghes'] = schema.docs-enterprise.graphql
|
||||
const filename = dataFilenames[id][versionType]
|
||||
|
||||
// dotcom files live at the root of data/graphql
|
||||
// non-dotcom files live in data/graphql/<version_subdir>
|
||||
const dataSubdir = graphqlVersion === 'dotcom' ? '' : graphqlVersion
|
||||
|
||||
return path.join(graphqlDataDir, dataSubdir, filename)
|
||||
}
|
||||
|
||||
async function setBranchAsRef (options, graphqlVersion, branch = false) {
|
||||
const versionType = getVersionType(graphqlVersion)
|
||||
const defaultBranch = 'master'
|
||||
|
||||
const branches = {
|
||||
dotcom: defaultBranch,
|
||||
ghes: `enterprise-${graphqlVersion.replace('ghes-', '')}-release`,
|
||||
// TODO confirm the below is accurate after the release branch is created
|
||||
ghae: 'github-ae-release'
|
||||
}
|
||||
|
||||
// the first time this runs, it uses the branch found for the version above
|
||||
if (!branch) branch = branches[versionType]
|
||||
|
||||
// set the branch as the ref
|
||||
options.ref = `heads/${branch}`
|
||||
|
||||
// check whether the branch can be found in github/github
|
||||
const foundRefs = await listMatchingRefs(...Object.values(options))
|
||||
|
||||
// if foundRefs array is empty, the branch cannot be found, so try a fallback
|
||||
if (!foundRefs.length) {
|
||||
const fallbackBranch = defaultBranch
|
||||
await setBranchAsRef(options, graphqlVersion, fallbackBranch)
|
||||
}
|
||||
}
|
||||
|
||||
// given a GraphQL version like `ghes-2.22`, return `ghes`;
|
||||
// given a GraphQL version like `ghae` or `dotcom`, return as is
|
||||
function getVersionType (graphqlVersion) {
|
||||
return graphqlVersion.split('-')[0]
|
||||
}
|
||||
|
||||
function updateFile (filepath, content) {
|
||||
|
||||
Reference in New Issue
Block a user