Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support release notes for GitHub publishing #1044

Merged
merged 1 commit into from
Oct 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/__tests__/expected.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
19 changes: 18 additions & 1 deletion lib/publishing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -391,13 +402,19 @@ 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'),
entrypoint: 'publish.sh',
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,
Expand Down Expand Up @@ -633,4 +650,4 @@ export class PublishToGolang extends Construct {
project: this.project,
}));
}
}
}
22 changes: 18 additions & 4 deletions lib/publishing/github/create-release.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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;
Expand Down Expand Up @@ -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));
Expand All @@ -116,4 +130,4 @@ async function main() {
main().catch(e => {
console.error('❌', e);
process.exit(1);
});
});