From 4bc6096ec0415a83446b274f249c57ceb4fe93a3 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Fri, 30 Mar 2018 14:48:20 +0200 Subject: Fetch Github release notes from CHANGELOG.json and update CHANGELOG once they've been successfully published to Github --- packages/monorepo-scripts/src/postpublish_utils.ts | 36 ++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) (limited to 'packages') diff --git a/packages/monorepo-scripts/src/postpublish_utils.ts b/packages/monorepo-scripts/src/postpublish_utils.ts index c4f3135a5..fb1680afd 100644 --- a/packages/monorepo-scripts/src/postpublish_utils.ts +++ b/packages/monorepo-scripts/src/postpublish_utils.ts @@ -1,9 +1,12 @@ import { execAsync } from 'async-child-process'; import * as promisify from 'es6-promisify'; +import * as fs from 'fs'; import * as _ from 'lodash'; +import * as path from 'path'; import * as publishRelease from 'publish-release'; import semverSort = require('semver-sort'); +import { constants } from './constants'; import { utils } from './utils'; const publishReleaseAsync = promisify(publishRelease); @@ -88,23 +91,52 @@ export const postpublishUtils = { ); }, async publishReleaseNotesAsync(cwd: string, packageName: string, version: string, assets: string[]): Promise { + const notes = this.getReleaseNotes(packageName); const releaseName = this.getReleaseName(packageName, version); const tag = this.getTag(packageName, version); - utils.log('POSTPUBLISH: Releasing ', releaseName, '...'); const finalAssets = this.adjustAssetPaths(cwd, assets); + utils.log('POSTPUBLISH: Releasing ', releaseName, '...'); const result = await publishReleaseAsync({ token: githubPersonalAccessToken, owner: '0xProject', repo: '0x-monorepo', tag, name: releaseName, - notes: 'N/A', + notes, draft: false, prerelease: false, reuseRelease: true, reuseDraftOnly: false, assets, }); + this.updateChangelogIsPublished(packageName); + }, + getReleaseNotes(packageName: string) { + const changelogJSONPath = path.join(constants.monorepoRootPath, 'packages', packageName, 'CHANGELOG.json'); + const changelogJSON = fs.readFileSync(changelogJSONPath, 'utf-8'); + const changelogs = JSON.parse(changelogJSON); + const latestLog = changelogs[0]; + if (_.isUndefined(latestLog.isPublished)) { + let notes = ''; + _.each(latestLog.changes, change => { + notes = `* ${change.note}`; + if (change.pr) { + notes += ` (${change.pr})`; + } + notes += `\n`; + }); + return notes; + } + return 'N/A'; + }, + updateChangelogIsPublished(packageName: string) { + const changelogJSONPath = path.join(constants.monorepoRootPath, 'packages', packageName, 'CHANGELOG.json'); + const changelogJSON = fs.readFileSync(changelogJSONPath, 'utf-8'); + const changelogs = JSON.parse(changelogJSON); + const latestLog = changelogs[0]; + latestLog.isPublished = true; + changelogs[0] = latestLog; + fs.writeFileSync(changelogJSONPath, JSON.stringify(changelogs, null, '\t')); }, getTag(packageName: string, version: string) { return `${packageName}@${version}`; -- cgit v1.2.3