1
0
mirror of synced 2025-12-22 03:16:52 -05:00

Add changelog creation to update-files.js

This commit is contained in:
Robert Mosolgo
2020-11-23 08:42:12 -05:00
parent f2119bc619
commit ab06aadf82
3 changed files with 24 additions and 36 deletions

View File

@@ -1,43 +1,8 @@
const { diff, ChangeType } = require('@graphql-inspector/core') const { diff, ChangeType } = require('@graphql-inspector/core')
const { loadSchema } = require('@graphql-tools/load') const { loadSchema } = require('@graphql-tools/load')
const git = require('../../lib/git-utils')
const fs = require('fs') const fs = require('fs')
const yaml = require('js-yaml') 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 * 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.) * structure written to `targetPath`. (`changelogEntry` and that file are modified in place.)

View File

@@ -14,6 +14,7 @@ const processPreviews = require('./utils/process-previews')
const processUpcomingChanges = require('./utils/process-upcoming-changes') const processUpcomingChanges = require('./utils/process-upcoming-changes')
const processSchemas = require('./utils/process-schemas') const processSchemas = require('./utils/process-schemas')
const prerenderObjects = require('./utils/prerender-objects') const prerenderObjects = require('./utils/prerender-objects')
const { prependDatedEntry, createChangelogEntry } = require("./build-changelog")
// check for required PAT // check for required PAT
if (!process.env.GITHUB_TOKEN) { if (!process.env.GITHUB_TOKEN) {
@@ -57,6 +58,10 @@ async function main () {
// 2. UPDATE UPCOMING CHANGES // 2. UPDATE UPCOMING CHANGES
const upcomingChangesPath = getDataFilepath('upcomingChanges', graphqlVersion) 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) const safeForPublicChanges = await getRemoteRawContent(upcomingChangesPath, graphqlVersion)
updateFile(upcomingChangesPath, safeForPublicChanges) updateFile(upcomingChangesPath, safeForPublicChanges)
upcomingChangesJson[graphqlVersion] = await processUpcomingChanges(safeForPublicChanges) upcomingChangesJson[graphqlVersion] = await processUpcomingChanges(safeForPublicChanges)
@@ -64,6 +69,10 @@ async function main () {
// 3. UPDATE SCHEMAS // 3. UPDATE SCHEMAS
// note: schemas live in separate files per version // note: schemas live in separate files per version
const schemaPath = getDataFilepath('schemas', graphqlVersion) const schemaPath = getDataFilepath('schemas', graphqlVersion)
let previousSchemaString = null
if (fs.existsSync(upcomingChangesPath)) {
previousSchemaString = fs.readFileSync(schemaPath, "utf8")
}
const latestSchema = await getRemoteRawContent(schemaPath, graphqlVersion) const latestSchema = await getRemoteRawContent(schemaPath, graphqlVersion)
const safeForPublicSchema = removeHiddenMembers(schemaPath, latestSchema) const safeForPublicSchema = removeHiddenMembers(schemaPath, latestSchema)
updateFile(schemaPath, safeForPublicSchema) updateFile(schemaPath, safeForPublicSchema)
@@ -73,6 +82,20 @@ async function main () {
// 4. PRERENDER OBJECTS HTML // 4. PRERENDER OBJECTS HTML
// because the objects page is too big to render on page load // because the objects page is too big to render on page load
prerenderedObjects[graphqlVersion] = await prerenderObjects(schemaJsonPerVersion) 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')) updateStaticFile(previewsJson, path.join(graphqlStaticDir, 'previews.json'))

View File

@@ -106,7 +106,7 @@ describe("updating the changelog file", () => {
const exampleEntry = { someStuff: true } const exampleEntry = { someStuff: true }
prependDatedEntry(exampleEntry, testTargetPath) prependDatedEntry(exampleEntry, testTargetPath)
const newContents = fs.readFileSync(testTargetPath).toString() const newContents = fs.readFileSync(testTargetPath, "utf8")
// reset the file: // reset the file:
fs.writeFileSync(testTargetPath, previousContents) fs.writeFileSync(testTargetPath, previousContents)