From e0e5dac4acd6ca6ff3a1e867bac2209ccc467ce7 Mon Sep 17 00:00:00 2001 From: Nick Lynch Date: Tue, 12 Oct 2021 15:56:48 +0100 Subject: [PATCH] feat: support release notes for GitHub publishing Currently, the GitHub publishing job looks for a CHANGELOG file (either in a default location or set by environment variable), parses the changelog for the current version, and uses that result as the release notes. This change enables an alternative approach; creating a RELEASE_NOTES file which contains the complete release notes, ready for publishing. The advantage of this new approach might be if you want to do some post-processing formatting on the changelog (or even include extra notes not normally present in the default changelog). For CDKv2, this will be used to combine the changelog entries for the stable release (aws-cdk-lib) and for the alpha modules. --- lib/__tests__/expected.yml | 5 ++++- lib/publishing.ts | 19 ++++++++++++++++++- lib/publishing/github/create-release.js | 22 ++++++++++++++++++---- 3 files changed, 40 insertions(+), 6 deletions(-) diff --git a/lib/__tests__/expected.yml b/lib/__tests__/expected.yml index 157f55e6..86aa4561 100644 --- a/lib/__tests__/expected.yml +++ b/lib/__tests__/expected.yml @@ -3268,13 +3268,16 @@ Resources: Value: cdk-hnb659fds-assets-712950704752-us-east-1 - Name: SCRIPT_S3_KEY Type: PLAINTEXT - Value: 8052fca741da226259577a0857de974eff37334424d24ba483890caa366a6045.zip + Value: 168799fb36a5c07de842b73d47e38fc33983aadeec36fca33b73cdc9388dce6a.zip - Name: BUILD_MANIFEST Type: PLAINTEXT Value: ./build.json - Name: CHANGELOG Type: PLAINTEXT Value: ./CHANGELOG.md + - Name: RELEASE_NOTES + Type: PLAINTEXT + Value: ./RELEASE_NOTES.md - Name: SIGNING_KEY_ARN Type: PLAINTEXT Value: diff --git a/lib/publishing.ts b/lib/publishing.ts index 287af35e..2d3ec99a 100644 --- a/lib/publishing.ts +++ b/lib/publishing.ts @@ -367,6 +367,17 @@ export interface PublishToGitHubProps { */ changelogFileName?: string; + /** + * The name of the release notes file, containing the completed release notes + * for the current release. + * Relative to the artifacts root. + * NOTE - If this value is set and points to a valid file, the file in its entirety + * will be read and used for the release notes. The value of `changelogFileName` will + * be ignored. + * @default "./RELEASE_NOTES.md" + */ + releaseNotesFileName?: string; + /** * Additional input artifacts to publish binaries from to GitHub release */ @@ -391,6 +402,11 @@ export class PublishToGitHub extends Construct implements IPublisher { const forReal = props.dryRun === undefined ? 'false' : (!props.dryRun).toString(); this.additionalInputArtifacts = props.additionalInputArtifacts; + // The release notes, if set and a valid file, overrides any usages of the changelog. + if (props.changelogFileName && props.releaseNotesFileName) { + throw new Error('both `releaseNotesFileName` and `changelogFileName` cannot be specified; use one or the other'); + } + const shellable = new Shellable(this, 'Default', { platform: new LinuxPlatform(cbuild.LinuxBuildImage.UBUNTU_14_04_NODEJS_10_1_0), scriptDirectory: path.join(__dirname, 'publishing', 'github'), @@ -398,6 +414,7 @@ export class PublishToGitHub extends Construct implements IPublisher { environment: noUndefined({ BUILD_MANIFEST: props.buildManifestFileName || './build.json', CHANGELOG: props.changelogFileName || './CHANGELOG.md', + RELEASE_NOTES: props.releaseNotesFileName || './RELEASE_NOTES.md', SIGNING_KEY_ARN: props.signingKey.credential.secretArn, GITHUB_OWNER: props.githubRepo.owner, GITHUB_REPO: props.githubRepo.repo, @@ -633,4 +650,4 @@ export class PublishToGolang extends Construct { project: this.project, })); } -} \ No newline at end of file +} diff --git a/lib/publishing/github/create-release.js b/lib/publishing/github/create-release.js index 38607932..d454897f 100644 --- a/lib/publishing/github/create-release.js +++ b/lib/publishing/github/create-release.js @@ -12,6 +12,7 @@ if (!process.env.GITHUB_OWNER) { throw new Error('GITHUB_OWNER is required'); } const build_manifest = process.env.BUILD_MANIFEST || './build.json'; const changelog_file = process.env.CHANGELOG || './CHANGELOG.md'; +const release_notes_file = process.env.RELEASE_NOTES || './RELEASE_NOTES.md'; const client = github.client(process.env.GITHUB_TOKEN); @@ -31,6 +32,14 @@ async function release_exists(repository, tag_name) { }); } +async function read_release_notes() { + if (!await exists(release_notes_file)) { + return undefined; + } + + return fs.readFile(release_notes_file, 'utf8'); +} + async function read_changelog(version) { if (!await exists(changelog_file)) { return undefined; @@ -101,11 +110,16 @@ async function main() { return; } - console.log('reading changelog...'); - const changelog = await read_changelog(manifest.version); + console.log('reading release notes...'); + let release_notes = await read_release_notes(); + + if (!release_notes) { + console.log('reading changelog...'); + release_notes = await read_changelog(manifest.version); + } console.log('creating release...'); - const release_id = await create_release(repository, tag_name, commit, changelog); + const release_id = await create_release(repository, tag_name, commit, release_notes); console.log('uploading assets...'); await upload_assets(repository, release_id, process.argv.slice(2)); @@ -116,4 +130,4 @@ async function main() { main().catch(e => { console.error('❌', e); process.exit(1); -}); \ No newline at end of file +});