Skip to content

Commit 5356841

Browse files
authored
Add CHANGELOG.md (#1010)
* add CHANGELOG.md * update release instructions ** Add step to consider updating CHANGELOG.md ** Revise ticket auditing to remove suggestion that ticket titles are used in release notes. * add test of `make_release.py`.
1 parent 737c562 commit 5356841

File tree

4 files changed

+153
-29
lines changed

4 files changed

+153
-29
lines changed

CHANGELOG.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## 3.9.0 [Unreleased]
9+
10+
### Added
11+
12+
- Add CMake option `USE_DEFAULT_INSTALL_PATH`.
13+
- Add API to manage Atlas Search Indexes.
14+
- Automatically download C driver dependency if not provided.
15+
16+
### Changed
17+
- Do not build tests as part of `all` target. Configure with `BUILD_TESTING=ON` to build tests.

etc/make_release.py

Lines changed: 62 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
Make a release of the C++ Driver, including steps associated with the CXX
2121
project in Jira, and with the mongodb/mongo-cxx-driver GitHub repository.
2222
See releasing.md for complete release instructions.
23+
When editing this file, consider running `test_make_release.py` to validate changes.
2324
"""
2425

2526
# CXX Project ID - 11980
@@ -36,6 +37,7 @@
3637
# | Task | 3 |
3738
# ------------------------
3839

40+
import textwrap
3941
import re
4042
from distutils.version import LooseVersion
4143
import os
@@ -204,7 +206,9 @@ def release(jira_creds_file,
204206
# all_issues_closed() has already produced an error message
205207
sys.exit(1)
206208

207-
release_notes_text = generate_release_notes(issues, release_version)
209+
with open ("CHANGELOG.md", "r") as changelog:
210+
changelog_contents = changelog.read()
211+
release_notes_text = generate_release_notes(release_version, changelog_contents)
208212

209213
gh_repo = auth_gh.get_repo('mongodb/mongo-cxx-driver')
210214
gh_release_dict = get_github_releases(gh_repo)
@@ -565,28 +569,63 @@ def all_issues_closed(issues):
565569

566570
return True
567571

568-
def generate_release_notes(issues, release_version):
569-
"""
570-
Produce HTML release notes which can be used as part of the project release
571-
announcement.
572-
"""
573-
574-
release_notes = '<h1>Release Notes - C++ Driver - Version {}</h1>\n'.format(release_version)
575-
release_notes += '<h2>Bug</h2>\n'
576-
release_notes += '<ul>\n'
577-
bug_filter = lambda i: i.fields.issuetype.id == ISSUE_TYPE_ID['Bug']
578-
release_notes += print_issues(list(filter(bug_filter, issues)))
579-
release_notes += '</ul>\n'
580-
release_notes += '<h2>New Feature</h2>\n'
581-
release_notes += '<ul>\n'
582-
new_feature_filter = lambda i: i.fields.issuetype.id == ISSUE_TYPE_ID['New Feature']
583-
release_notes += print_issues(list(filter(new_feature_filter, issues)))
584-
release_notes += '</ul>\n'
585-
release_notes += '<h2>Improvement</h2>\n'
586-
release_notes += '<ul>\n'
587-
improvement_filter = lambda i: i.fields.issuetype.id == ISSUE_TYPE_ID['Improvement']
588-
release_notes += print_issues(list(filter(improvement_filter, issues)))
589-
release_notes += '</ul>\n'
572+
def generate_release_notes(release_version: str, changelog_contents: str) -> str:
573+
lines = []
574+
adding_to_lines = False
575+
for line in changelog_contents.splitlines(keepends=True):
576+
# Check for a version title. Example: `## 3.9.0`.
577+
match = re.match(r"^## (.*?)\s(.*)$".format(release_version), line)
578+
if match:
579+
matched_version = match.group(1)
580+
if matched_version == release_version:
581+
# Found matching version.
582+
extra = match.group(2)
583+
if extra != "":
584+
raise click.ClickException(
585+
"Unexpected extra characters in CHANGELOG: {}. Is the CHANGELOG updated?".format(extra))
586+
if adding_to_lines:
587+
raise click.ClickException(
588+
"Unexpected second changelog entry matching version: {}: {}".format(release_version), line)
589+
# Begin adding lines to `lines` list.
590+
adding_to_lines = True
591+
continue
592+
# End adding lines when another title is seen.
593+
else:
594+
adding_to_lines = False
595+
break
596+
597+
if adding_to_lines:
598+
# Reduce title by one.
599+
if line.startswith("#"):
600+
lines.append(line[1:])
601+
else:
602+
lines.append(line)
603+
604+
# Removing beginning empty lines.
605+
while len(lines) > 0 and lines[0] == "\n":
606+
lines = lines[1:]
607+
608+
# Remove trailing empty lines.
609+
while len(lines) > 0 and lines[-1] == "\n":
610+
lines = lines[0:-1]
611+
612+
if lines == []:
613+
raise click.ClickException(
614+
"Failed to find changelog contents for {}".format(release_version))
615+
616+
footer = textwrap.dedent("""
617+
## Feedback
618+
To report a bug or request a feature, please open a ticket in the MongoDB issue management tool Jira:
619+
620+
- [Create an account](https://jira.mongodb.org) and login.
621+
- Navigate to the [CXX project](https://jira.mongodb.org/browse/CXX)
622+
- Click `Create`.
623+
""").lstrip()
624+
625+
release_notes = "".join(lines) + "\n"
626+
release_notes += "See the [full list of changes in Jira](https://jira.mongodb.org/issues/?jql=project%20%3D%20CXX%20AND%20fixVersion%20%3D%20{}).\n\n".format(
627+
release_version)
628+
release_notes += footer
590629

591630
return release_notes
592631

etc/releasing.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,16 @@ changes cherry-picked onto the release branch. This is indicated by a comment on
4444
the ticket. Here is an
4545
[example comment](https://jira.mongodb.com/browse/CXX-2650?focusedCommentId=5271981&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-5271981).
4646

47-
## Audit Jira ticket titles and types for use in release notes
47+
## Audit Jira ticket titles and types
4848

49-
From the releases page click the "Release Notes" link to see a summary of
50-
tickets to be included in release notes. Update the ticket type and title as
51-
appropriate. User-facing issues should generally be either "Bug" or
52-
"New Feature". Non-user facing issues should generally be "Task" tickets (and
53-
will be omitted later, so you can ignore them here).
49+
Update Jira ticket types and titles as appropriate.
50+
User-facing issues should generally be either "Bug" or "New Feature".
51+
Non-user facing issues should generally be "Task" tickets.
52+
53+
## Update CHANGELOG.md
54+
55+
Check Jira for tickets closed in this fix version. Consider updating CHANGELOG.md
56+
with notable changes not already mentioned.
5457

5558
## Clone and set up environment
5659

etc/test_make_release.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import make_release
2+
import unittest
3+
import textwrap
4+
import click
5+
6+
7+
class TestMakeRelease(unittest.TestCase):
8+
def test_generate_release_notes(self):
9+
# Test can generate.
10+
changelog = textwrap.dedent("""
11+
# Changelog
12+
13+
All notable changes to this project will be documented in this file.
14+
15+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
16+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
17+
18+
## 3.9.0
19+
20+
### Added
21+
22+
- Add CMake option `USE_DEFAULT_INSTALL_PATH`.
23+
- Add API to manage Atlas Search Indexes.
24+
25+
## 3.8.0
26+
27+
### Fixed
28+
29+
- Fix foo.
30+
""").lstrip()
31+
expected_release_notes = textwrap.dedent("""
32+
## Added
33+
34+
- Add CMake option `USE_DEFAULT_INSTALL_PATH`.
35+
- Add API to manage Atlas Search Indexes.
36+
37+
See the [full list of changes in Jira](https://jira.mongodb.org/issues/?jql=project%20%3D%20CXX%20AND%20fixVersion%20%3D%203.9.0).
38+
39+
## Feedback
40+
To report a bug or request a feature, please open a ticket in the MongoDB issue management tool Jira:
41+
42+
- [Create an account](https://jira.mongodb.org) and login.
43+
- Navigate to the [CXX project](https://jira.mongodb.org/browse/CXX)
44+
- Click `Create`.
45+
""").lstrip()
46+
47+
got = make_release.generate_release_notes("3.9.0", changelog)
48+
self.assertEqual(got, expected_release_notes)
49+
50+
# Test exception occurs if CHANGELOG includes extra characters in title.
51+
with self.assertRaises(click.ClickException) as ctx:
52+
make_release.generate_release_notes(
53+
"3.9.0", "## 3.9.0 [Unreleased]")
54+
self.assertIn("Unexpected extra characters",
55+
str(ctx.exception.message))
56+
57+
# Test exception occurs if CHANGELOG does not include matching entry.
58+
with self.assertRaises(click.ClickException) as ctx:
59+
make_release.generate_release_notes(
60+
"3.9.0", "## 3.8.0")
61+
self.assertIn("Failed to find", str(ctx.exception.message))
62+
63+
64+
if __name__ == "__main__":
65+
unittest.main()

0 commit comments

Comments
 (0)