|
20 | 20 | Make a release of the C++ Driver, including steps associated with the CXX
|
21 | 21 | project in Jira, and with the mongodb/mongo-cxx-driver GitHub repository.
|
22 | 22 | See releasing.md for complete release instructions.
|
| 23 | +When editing this file, consider running `test_make_release.py` to validate changes. |
23 | 24 | """
|
24 | 25 |
|
25 | 26 | # CXX Project ID - 11980
|
|
36 | 37 | # | Task | 3 |
|
37 | 38 | # ------------------------
|
38 | 39 |
|
| 40 | +import textwrap |
39 | 41 | import re
|
40 | 42 | from distutils.version import LooseVersion
|
41 | 43 | import os
|
@@ -204,7 +206,9 @@ def release(jira_creds_file,
|
204 | 206 | # all_issues_closed() has already produced an error message
|
205 | 207 | sys.exit(1)
|
206 | 208 |
|
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) |
208 | 212 |
|
209 | 213 | gh_repo = auth_gh.get_repo('mongodb/mongo-cxx-driver')
|
210 | 214 | gh_release_dict = get_github_releases(gh_repo)
|
@@ -565,28 +569,63 @@ def all_issues_closed(issues):
|
565 | 569 |
|
566 | 570 | return True
|
567 | 571 |
|
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 |
590 | 629 |
|
591 | 630 | return release_notes
|
592 | 631 |
|
|
0 commit comments