Add changelog creation to update-files.js
This commit is contained in:
@@ -1,43 +1,8 @@
|
||||
const { diff, ChangeType } = require('@graphql-inspector/core')
|
||||
const { loadSchema } = require('@graphql-tools/load')
|
||||
const git = require('../../lib/git-utils')
|
||||
const fs = require('fs')
|
||||
const yaml = require('js-yaml')
|
||||
|
||||
// check for required PAT
|
||||
if (!process.env.GITHUB_TOKEN) {
|
||||
console.error('Error! You must have a GITHUB_TOKEN set in an .env file to run this script.')
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
// main()
|
||||
|
||||
async function main() {
|
||||
// Load the previous schema from this repo
|
||||
// TODO -- how to make sure that this script runs _before_ this artifact is updated?
|
||||
// Maybe hook into the existing `update-files` script instead of being a stand-alone script.
|
||||
const oldSchemaString = fs.readFileSync('data/graphql/schema.docs.graphql').toString()
|
||||
|
||||
// Load the latest schema from github/github
|
||||
const tree = await git.getTree('github', 'github', 'heads/master')
|
||||
const schemaFileBlob = tree.find(entry => entry.path.includes('config/schema.docs.graphql') && entry.type === 'blob')
|
||||
const newSchemaBuffer = await git.getContentsForBlob('github', 'github', schemaFileBlob)
|
||||
|
||||
const previewsString = fs.readFileSync('data/graphql/graphql_previews.yml')
|
||||
const previews = yaml.safeLoad(previewsString)
|
||||
|
||||
// TODO how to make sure to get these before the file is updated?
|
||||
const oldUpcomingChangesString = fs.readFileSync('data/graphql/graphql_upcoming_changes_public.yml')
|
||||
const oldUpcomingChanges = yaml.safeLoad(oldUpcomingChangesString).upcoming_changes
|
||||
// TODO actually get different changes here
|
||||
const newUpcomingChanges = oldUpcomingChanges
|
||||
|
||||
const changelogEntry = createChangelogEntry(oldSchemaString, newSchemaBuffer.toString(), previews, oldUpcomingChanges, newUpcomingChanges)
|
||||
if (changelogEntry) {
|
||||
prependDatedEntry(changelogEntry, 'lib/graphql/static/changelog.json')
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tag `changelogEntry` with `date: YYYY-mm-dd`, then prepend it to the JSON
|
||||
* structure written to `targetPath`. (`changelogEntry` and that file are modified in place.)
|
||||
|
||||
@@ -14,6 +14,7 @@ const processPreviews = require('./utils/process-previews')
|
||||
const processUpcomingChanges = require('./utils/process-upcoming-changes')
|
||||
const processSchemas = require('./utils/process-schemas')
|
||||
const prerenderObjects = require('./utils/prerender-objects')
|
||||
const { prependDatedEntry, createChangelogEntry } = require("./build-changelog")
|
||||
|
||||
// check for required PAT
|
||||
if (!process.env.GITHUB_TOKEN) {
|
||||
@@ -57,6 +58,10 @@ async function main () {
|
||||
|
||||
// 2. UPDATE UPCOMING CHANGES
|
||||
const upcomingChangesPath = getDataFilepath('upcomingChanges', graphqlVersion)
|
||||
let previousUpcomingChanges = null
|
||||
if (fs.existsSync(upcomingChangesPath)) {
|
||||
previousUpcomingChanges = yaml.safeLoad(fs.readFileSync(upcomingChangesPath, "utf8"))
|
||||
}
|
||||
const safeForPublicChanges = await getRemoteRawContent(upcomingChangesPath, graphqlVersion)
|
||||
updateFile(upcomingChangesPath, safeForPublicChanges)
|
||||
upcomingChangesJson[graphqlVersion] = await processUpcomingChanges(safeForPublicChanges)
|
||||
@@ -64,6 +69,10 @@ async function main () {
|
||||
// 3. UPDATE SCHEMAS
|
||||
// note: schemas live in separate files per version
|
||||
const schemaPath = getDataFilepath('schemas', graphqlVersion)
|
||||
let previousSchemaString = null
|
||||
if (fs.existsSync(upcomingChangesPath)) {
|
||||
previousSchemaString = fs.readFileSync(schemaPath, "utf8")
|
||||
}
|
||||
const latestSchema = await getRemoteRawContent(schemaPath, graphqlVersion)
|
||||
const safeForPublicSchema = removeHiddenMembers(schemaPath, latestSchema)
|
||||
updateFile(schemaPath, safeForPublicSchema)
|
||||
@@ -73,6 +82,20 @@ async function main () {
|
||||
// 4. PRERENDER OBJECTS HTML
|
||||
// because the objects page is too big to render on page load
|
||||
prerenderedObjects[graphqlVersion] = await prerenderObjects(schemaJsonPerVersion)
|
||||
|
||||
if (allVersions[version].nonEnterpriseDefault) {
|
||||
// The Changelog is only build for free-pro-team@latest
|
||||
const changelogEntry = createChangelogEntry(
|
||||
previousSchemaString,
|
||||
safeForPublicSchema,
|
||||
safeForPublicPreviews,
|
||||
previousUpcomingChanges.upcoming_changes,
|
||||
yaml.safeLoad(safeForPublicChanges).upcoming_changes,
|
||||
)
|
||||
if (changelogEntry) {
|
||||
prependDatedEntry(changelogEntry, path.join(process.cwd(), 'lib/graphql/static/changelog.json'))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
updateStaticFile(previewsJson, path.join(graphqlStaticDir, 'previews.json'))
|
||||
|
||||
@@ -106,7 +106,7 @@ describe("updating the changelog file", () => {
|
||||
|
||||
const exampleEntry = { someStuff: true }
|
||||
prependDatedEntry(exampleEntry, testTargetPath)
|
||||
const newContents = fs.readFileSync(testTargetPath).toString()
|
||||
const newContents = fs.readFileSync(testTargetPath, "utf8")
|
||||
// reset the file:
|
||||
fs.writeFileSync(testTargetPath, previousContents)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user