Skip to content

Commit ab06aad

Browse files
committed
Add changelog creation to update-files.js
1 parent f2119bc commit ab06aad

3 files changed

Lines changed: 24 additions & 36 deletions

File tree

script/graphql/build-changelog.js

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,8 @@
11
const { diff, ChangeType } = require('@graphql-inspector/core')
22
const { loadSchema } = require('@graphql-tools/load')
3-
const git = require('../../lib/git-utils')
43
const fs = require('fs')
54
const yaml = require('js-yaml')
65

7-
// check for required PAT
8-
if (!process.env.GITHUB_TOKEN) {
9-
console.error('Error! You must have a GITHUB_TOKEN set in an .env file to run this script.')
10-
process.exit(1)
11-
}
12-
13-
// main()
14-
15-
async function main() {
16-
// Load the previous schema from this repo
17-
// TODO -- how to make sure that this script runs _before_ this artifact is updated?
18-
// Maybe hook into the existing `update-files` script instead of being a stand-alone script.
19-
const oldSchemaString = fs.readFileSync('data/graphql/schema.docs.graphql').toString()
20-
21-
// Load the latest schema from github/github
22-
const tree = await git.getTree('github', 'github', 'heads/master')
23-
const schemaFileBlob = tree.find(entry => entry.path.includes('config/schema.docs.graphql') && entry.type === 'blob')
24-
const newSchemaBuffer = await git.getContentsForBlob('github', 'github', schemaFileBlob)
25-
26-
const previewsString = fs.readFileSync('data/graphql/graphql_previews.yml')
27-
const previews = yaml.safeLoad(previewsString)
28-
29-
// TODO how to make sure to get these before the file is updated?
30-
const oldUpcomingChangesString = fs.readFileSync('data/graphql/graphql_upcoming_changes_public.yml')
31-
const oldUpcomingChanges = yaml.safeLoad(oldUpcomingChangesString).upcoming_changes
32-
// TODO actually get different changes here
33-
const newUpcomingChanges = oldUpcomingChanges
34-
35-
const changelogEntry = createChangelogEntry(oldSchemaString, newSchemaBuffer.toString(), previews, oldUpcomingChanges, newUpcomingChanges)
36-
if (changelogEntry) {
37-
prependDatedEntry(changelogEntry, 'lib/graphql/static/changelog.json')
38-
}
39-
}
40-
416
/**
427
* Tag `changelogEntry` with `date: YYYY-mm-dd`, then prepend it to the JSON
438
* structure written to `targetPath`. (`changelogEntry` and that file are modified in place.)

script/graphql/update-files.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const processPreviews = require('./utils/process-previews')
1414
const processUpcomingChanges = require('./utils/process-upcoming-changes')
1515
const processSchemas = require('./utils/process-schemas')
1616
const prerenderObjects = require('./utils/prerender-objects')
17+
const { prependDatedEntry, createChangelogEntry } = require("./build-changelog")
1718

1819
// check for required PAT
1920
if (!process.env.GITHUB_TOKEN) {
@@ -57,13 +58,21 @@ async function main () {
5758

5859
// 2. UPDATE UPCOMING CHANGES
5960
const upcomingChangesPath = getDataFilepath('upcomingChanges', graphqlVersion)
61+
let previousUpcomingChanges = null
62+
if (fs.existsSync(upcomingChangesPath)) {
63+
previousUpcomingChanges = yaml.safeLoad(fs.readFileSync(upcomingChangesPath, "utf8"))
64+
}
6065
const safeForPublicChanges = await getRemoteRawContent(upcomingChangesPath, graphqlVersion)
6166
updateFile(upcomingChangesPath, safeForPublicChanges)
6267
upcomingChangesJson[graphqlVersion] = await processUpcomingChanges(safeForPublicChanges)
6368

6469
// 3. UPDATE SCHEMAS
6570
// note: schemas live in separate files per version
6671
const schemaPath = getDataFilepath('schemas', graphqlVersion)
72+
let previousSchemaString = null
73+
if (fs.existsSync(upcomingChangesPath)) {
74+
previousSchemaString = fs.readFileSync(schemaPath, "utf8")
75+
}
6776
const latestSchema = await getRemoteRawContent(schemaPath, graphqlVersion)
6877
const safeForPublicSchema = removeHiddenMembers(schemaPath, latestSchema)
6978
updateFile(schemaPath, safeForPublicSchema)
@@ -73,6 +82,20 @@ async function main () {
7382
// 4. PRERENDER OBJECTS HTML
7483
// because the objects page is too big to render on page load
7584
prerenderedObjects[graphqlVersion] = await prerenderObjects(schemaJsonPerVersion)
85+
86+
if (allVersions[version].nonEnterpriseDefault) {
87+
// The Changelog is only build for free-pro-team@latest
88+
const changelogEntry = createChangelogEntry(
89+
previousSchemaString,
90+
safeForPublicSchema,
91+
safeForPublicPreviews,
92+
previousUpcomingChanges.upcoming_changes,
93+
yaml.safeLoad(safeForPublicChanges).upcoming_changes,
94+
)
95+
if (changelogEntry) {
96+
prependDatedEntry(changelogEntry, path.join(process.cwd(), 'lib/graphql/static/changelog.json'))
97+
}
98+
}
7699
}
77100

78101
updateStaticFile(previewsJson, path.join(graphqlStaticDir, 'previews.json'))

tests/graphql/build-changelog-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ describe("updating the changelog file", () => {
106106

107107
const exampleEntry = { someStuff: true }
108108
prependDatedEntry(exampleEntry, testTargetPath)
109-
const newContents = fs.readFileSync(testTargetPath).toString()
109+
const newContents = fs.readFileSync(testTargetPath, "utf8")
110110
// reset the file:
111111
fs.writeFileSync(testTargetPath, previousContents)
112112

0 commit comments

Comments
 (0)