diff --git a/.github/workflows/update-graphql-files.yml b/.github/workflows/update-graphql-files.yml index febfcf618c..0ba265a0f7 100644 --- a/.github/workflows/update-graphql-files.yml +++ b/.github/workflows/update-graphql-files.yml @@ -37,20 +37,15 @@ jobs: env: # need to use a token from a user with access to github/github for this step GITHUB_TOKEN: ${{ secrets.ZEKE_PAT_WITH_REPO_AND_WORKFLOW_SCOPE_FOR_REPO_SYNC }} - # technically the changelog should only be updated once per day, but we can safely - # run build-changelog-from-markdown.js in its current form once per hour; when we - # rewrite the changelog script, we may need to run it in a separate workflow on a - # once-per-day schedule; see details in https://github.com/github/docs-internal/issues/12722. run: | script/graphql/update-files.js - script/graphql/build-changelog-from-markdown.js - name: Create pull request id: create-pull-request uses: peter-evans/create-pull-request@938e6aea6f8dbdaced2064e948cb806c77fe87b8 with: # need to use a token with repo and workflow scopes for this step token: ${{ secrets.OCTOMERGER_PAT_WITH_REPO_AND_WORKFLOW_SCOPE }} - commit-message: 'Action ran graphql scripts "update-files" and "build-changelog-from-markdown"' + commit-message: 'Action ran graphql script"update-files"' title: GraphQL schema update body: "Hello! Some GraphQL data in github/github was updated recently. This PR diff --git a/lib/graphql/README.md b/lib/graphql/README.md index bd34672912..00d5b0e110 100644 --- a/lib/graphql/README.md +++ b/lib/graphql/README.md @@ -24,9 +24,6 @@ Generated by `script/graphql/update-files.js`: * `lib/graphql/static/schema-VERSION.json` (separate files per version) * `lib/graphql/static/previews.json` * `lib/graphql/static/upcoming-changes.json` - -Generated by `script/graphql/build-changelog-from-markdown.js`: - * `lib/graphql/static/changelog.json` ## Rendering docs diff --git a/script/README.md b/script/README.md index ec7beb9881..178aff0367 100644 --- a/script/README.md +++ b/script/README.md @@ -179,12 +179,6 @@ Given: /github/getting-started-with-github/using-github Returns: /free-pro-team@ Given: /enterprise/admin/installation/upgrading-github-enterprise Returns: /enterprise-server@2.22/admin/installation/upgrading-github-enterprise ---- - - -### [`graphql/build-changelog-from-markdown.js`](graphql/build-changelog-from-markdown.js) - - --- @@ -446,5 +440,3 @@ This script is used by other scripts to update temporary AWS credentials and aut Use this script to upload individual or batched asset files to a versioned S3 bucket. Run `upload-images-to-s3.js --help` for usage details. --- - - diff --git a/script/graphql/README.md b/script/graphql/README.md index da3904a448..4588357efd 100644 --- a/script/graphql/README.md +++ b/script/graphql/README.md @@ -1,10 +1,9 @@ # GraphQL scripts A [scheduled workflow](../.github/workflows/update-graphql-files.yml) runs the following -scripts on an hourly basis: +scripts on a daily basis: ``` script/graphql/update-files.js -script/graphql/build-changelog-from-markdown.js ``` These scripts update the [static JSON files](../../lib/graphql/static) used to render GraphQL docs. See the [`lib/graphql/README`](../../lib/graphql/README.md) diff --git a/script/graphql/build-changelog-from-markdown.js b/script/graphql/build-changelog-from-markdown.js deleted file mode 100755 index 15d5fb3e52..0000000000 --- a/script/graphql/build-changelog-from-markdown.js +++ /dev/null @@ -1,130 +0,0 @@ -#!/usr/bin/env node - -const fs = require('fs') -const path = require('path') -const { sortBy, reverse } = require('lodash') -const frontmatter = require('../../lib/frontmatter') -const git = require('../../lib/git-utils') -const staticChangelog = path.join(process.cwd(), 'lib/graphql/static/changelog.json') - -// values for api -const owner = 'github' -const repo = 'internal-developer.github.com' -const ref = 'heads/master' - -const previewsBaseLink = '/graphql/overview/schema-previews' - -const changesList = /(\n*[\s\S]*?\n)$/m - -// until 2018-02-14, all changelogs used the phrase 'The following changes were made to the GraphQL schema' -const schemaRegexGlobal = new RegExp('(The GraphQL schema includes these changes:|The following changes were made to the GraphQL schema:)' + changesList.source, 'mg') -const previewRegexGlobal = new RegExp('(The .*?preview.*? includes these changes:)' + changesList.source, 'mg') -const upcomingRegexGlobal = new RegExp('(The following changes will be made to the schema:)' + changesList.source, 'mg') - -const schemaRegexSingle = new RegExp(schemaRegexGlobal.source, 'm') -const previewRegexSingle = new RegExp(previewRegexGlobal.source, 'm') -const upcomingRegexSingle = new RegExp(upcomingRegexGlobal.source, 'm') - -main() - -async function main () { - const tree = await git.getTree(owner, repo, ref) - const changelogFiles = tree.filter(entry => entry.path.includes('v4/changelog') && entry.type === 'blob') - - const changelog = [] - - await Promise.all(changelogFiles.map(async (blob) => { - // get the contents of `content/v4/changelog/*` files from internal-developer.github.com - const contents = await git.getContentsForBlob(owner, repo, blob) - const file = blob.path - - if (file.endsWith('index.html')) return - process.stdout.write('.') - - const date = path.basename(file).replace('-schema-changes.md', '') - const { content } = frontmatter(contents) - - // match each section title and list of changes - const schemaChangesMatches = content.match(schemaRegexGlobal) - const previewChangesMatches = content.match(previewRegexGlobal) - const upcomingChangesMatches = content.match(upcomingRegexGlobal) - - const entry = {} - - // do a little formatting cleanup - entry.date = date - entry.schemaChanges = getEntry(schemaChangesMatches, schemaRegexSingle) - entry.previewChanges = getEntry(previewChangesMatches, previewRegexSingle) - entry.upcomingChanges = getEntry(upcomingChangesMatches, upcomingRegexSingle) - - // very first changelog has custom content - if (date === '2017-05-22') { - entry.schemaChanges[0].changes.push('Nothing! The schema was made public!') - } - - changelog.push(entry) - })) - - // sort by newest entries first - const sortedChangelog = reverse(sortBy(changelog, ['date'])) - - // write json file - fs.writeFileSync(staticChangelog, JSON.stringify(sortedChangelog, null, 2)) - console.log(`\n\nupdated ${staticChangelog}`) -} - -function getEntry (matches, regex) { - return matches - ? matches.map(match => { - const entry = {} - entry.title = cleanPreviewLinks(match.match(regex)[1]) - entry.changes = getChangedItems(match.match(regex)[2]) - return entry - }) - : [] -} - -function getChangedItems (string) { - return string - .split('\n*') - .slice(1) - .map(i => i.trim()) -} - -// do some cleanup of preview links -function cleanPreviewLinks (title) { - const previewMarkup = title.match(/\[(.*?)\]\((.*?)\)/) - if (!previewMarkup) return title - - const rawName = previewMarkup[1] - const rawLink = previewMarkup[2] - - let cleanName = rawName - let cleanLink = rawLink - - // fix two malformed links - if (cleanName.includes('MergeInfoPreview')) { - cleanName = 'Merge info preview' - cleanLink = `${previewsBaseLink}#merge-info-preview` - } - - if (cleanName.includes('UpdateRefsPreview')) { - cleanName = 'Update refs preview' - cleanLink = `${previewsBaseLink}#update-refs-preview` - } - - cleanName = !cleanName.endsWith('preview') - ? `${cleanName} preview` - : cleanName - - cleanLink = !cleanLink.endsWith('-preview') - ? `${cleanLink}-preview` - : cleanLink - - cleanLink = cleanLink - .replace('/v4/previews/', previewsBaseLink) - - return title - .replace(rawName, cleanName) - .replace(rawLink, cleanLink) -} diff --git a/script/graphql/build-changelog.js b/script/graphql/build-changelog.js index 0fb281fa9a..fc67d5f558 100644 --- a/script/graphql/build-changelog.js +++ b/script/graphql/build-changelog.js @@ -111,7 +111,6 @@ async function createChangelogEntry (oldSchemaString, newSchemaString, previews, /** * Prepare the preview title from github/github source for the docs. - * (ported from build-changelog-from-markdown) * @param {string} title * @return {string} */