Skip to content

Commit

Permalink
Add changelog creation to update-files.js
Browse files Browse the repository at this point in the history
  • Loading branch information
rmosolgo committed Nov 23, 2020
1 parent f2119bc commit ab06aad
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 36 deletions.
35 changes: 0 additions & 35 deletions script/graphql/build-changelog.js
Original file line number Diff line number Diff line change
@@ -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.)
Expand Down
23 changes: 23 additions & 0 deletions script/graphql/update-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -57,13 +58,21 @@ 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)

// 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)
Expand All @@ -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'))
Expand Down
2 changes: 1 addition & 1 deletion tests/graphql/build-changelog-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit ab06aad

Please sign in to comment.