From 8c1ec05947bc5a78a7a3bd5417865bc3faf2e6b2 Mon Sep 17 00:00:00 2001 From: mashehu Date: Fri, 1 Mar 2024 08:29:11 +0100 Subject: [PATCH 1/5] handle also patch version before `dev` suffix --- .github/workflows/changelog.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/changelog.py b/.github/workflows/changelog.py index 4835b0d0f0..7106cc7501 100644 --- a/.github/workflows/changelog.py +++ b/.github/workflows/changelog.py @@ -144,10 +144,11 @@ def _skip_existing_entry_for_this_pr(line: str, same_section: bool = True) -> st # Parse version from the line `## v2.12dev` or # `## [v2.11.1 - Magnesium Dragon Patch](https://github.com/nf-core/tools/releases/tag/2.11) - [2023-12-20]` ... - if not (m := re.match(r".*(v\d+\.\d+(dev)?).*", line)): + if not (m := re.match(r".*(v\d+\.\d+.\d*(dev)?).*", line)): print(f"Cannot parse version from line {line.strip()}.", file=sys.stderr) sys.exit(1) version = m.group(1) + print(f"Found version: {version}") if not inside_version_dev: if not version.endswith("dev"): From 6e6e916992b93dc336afb3d6e31bc7b9111770db Mon Sep 17 00:00:00 2001 From: mashehu Date: Fri, 1 Mar 2024 09:01:30 +0100 Subject: [PATCH 2/5] add ability to add new sections with word before colon in PR title --- .github/workflows/changelog.py | 76 +++++++++++++++++++--------------- 1 file changed, 43 insertions(+), 33 deletions(-) diff --git a/.github/workflows/changelog.py b/.github/workflows/changelog.py index 7106cc7501..412912812b 100644 --- a/.github/workflows/changelog.py +++ b/.github/workflows/changelog.py @@ -71,6 +71,11 @@ def _determine_change_type(pr_title) -> tuple[str, str]: if re.sub(r"s$", "", section.lower().replace("ing", "")) in pr_title.lower(): current_section_header = section_header current_section = section + # Add new section type if PR title has a colon and the section is not in the list + if ": " in pr_title and current_section == "General": + section = pr_title.split(":")[0] + current_section_header = f"### {section}" + current_section = section print(f"Detected section: {current_section}") return current_section, current_section_header @@ -79,7 +84,7 @@ def _determine_change_type(pr_title) -> tuple[str, str]: section, section_header = _determine_change_type(pr_title) # Remove section indicator from the PR title. -pr_title = re.sub(rf"{section}[:\s]*", "", pr_title, flags=re.IGNORECASE) +pr_title = re.sub(rf"{section}:[\s]*", "", pr_title, flags=re.IGNORECASE) # Prepare the change log entry. pr_link = f"([#{pr_number}]({REPO_URL}/pull/{pr_number}))" @@ -91,8 +96,11 @@ def _determine_change_type(pr_title) -> tuple[str, str]: new_lines = [ f"- {pr_title} {pr_link}\n", ] - print(f"Adding new lines into section '{section}':\n" + "".join(new_lines)) +# Add new section if it doesn't exist +if section_header not in open(changelog_path).read(): + print(f"Adding new section '{section}'") + new_lines = [f"{section_header}\n"] + new_lines # Finally, updating the changelog. # Read the current changelog lines. We will print them back as is, except for one new @@ -179,37 +187,39 @@ def _skip_existing_entry_for_this_pr(line: str, same_section: bool = True) -> st print(f"Found line: {line.strip()}") print(f"inside_version_dev: {inside_version_dev}") print(f"section_header: {section_header}") - if inside_version_dev and line.lower().startswith(section_header.lower()): # Section of interest header - print(f"Found section header: {line.strip()}") - if already_added_entry: - print( - f"Already added new lines into section {section}, is the section duplicated?", - file=sys.stderr, - ) - sys.exit(1) - updated_lines.append(line) - # Collecting lines until the next section. - section_lines: List[str] = [] - while True: - line = orig_lines.pop(0) - if line.startswith("#"): - print(f"Found the next section header: {line.strip()}") - # Found the next section header, so need to put all the lines we collected. - updated_lines.append("\n") - _updated_lines = [_l for _l in section_lines + new_lines if _l.strip()] - updated_lines.extend(_updated_lines) - updated_lines.append("\n") - if new_lines: - print(f"Updated {changelog_path} section '{section}' with lines:\n" + "".join(new_lines)) - else: - print(f"Removed existing entry from {changelog_path} section '{section}'") - already_added_entry = True - # Pushing back the next section header line - orig_lines.insert(0, line) - break - # If the line already contains a link to the PR, don't add it again. - line = _skip_existing_entry_for_this_pr(line, same_section=True) - section_lines.append(line) + if inside_version_dev: + if line.lower().startswith(section_header.lower()): # Section of interest header + print(f"Found section header: {line.strip()}") + if already_added_entry: + print( + f"Already added new lines into section {section}, is the section duplicated?", + file=sys.stderr, + ) + sys.exit(1) + updated_lines.append(line) + # Collecting lines until the next section. + section_lines: List[str] = [] + while True: + line = orig_lines.pop(0) + if line.startswith("#"): + print(f"Found the next section header: {line.strip()}") + # Found the next section header, so need to put all the lines we collected. + updated_lines.append("\n") + _updated_lines = [_l for _l in section_lines + new_lines if _l.strip()] + updated_lines.extend(_updated_lines) + updated_lines.append("\n") + if new_lines: + print(f"Updated {changelog_path} section '{section}' with lines:\n" + "".join(new_lines)) + else: + print(f"Removed existing entry from {changelog_path} section '{section}'") + already_added_entry = True + # Pushing back the next section header line + orig_lines.insert(0, line) + break + # If the line already contains a link to the PR, don't add it again. + line = _skip_existing_entry_for_this_pr(line, same_section=True) + section_lines.append(line) + else: updated_lines.append(line) From 61880487a1c649e167b98b16d96013c06a9c3f44 Mon Sep 17 00:00:00 2001 From: mashehu Date: Fri, 1 Mar 2024 13:23:28 +0100 Subject: [PATCH 3/5] remove abilty to add arbitrary sections --- .github/workflows/changelog.py | 9 --------- 1 file changed, 9 deletions(-) diff --git a/.github/workflows/changelog.py b/.github/workflows/changelog.py index 412912812b..ce5306e9ef 100644 --- a/.github/workflows/changelog.py +++ b/.github/workflows/changelog.py @@ -71,11 +71,6 @@ def _determine_change_type(pr_title) -> tuple[str, str]: if re.sub(r"s$", "", section.lower().replace("ing", "")) in pr_title.lower(): current_section_header = section_header current_section = section - # Add new section type if PR title has a colon and the section is not in the list - if ": " in pr_title and current_section == "General": - section = pr_title.split(":")[0] - current_section_header = f"### {section}" - current_section = section print(f"Detected section: {current_section}") return current_section, current_section_header @@ -97,10 +92,6 @@ def _determine_change_type(pr_title) -> tuple[str, str]: f"- {pr_title} {pr_link}\n", ] print(f"Adding new lines into section '{section}':\n" + "".join(new_lines)) -# Add new section if it doesn't exist -if section_header not in open(changelog_path).read(): - print(f"Adding new section '{section}'") - new_lines = [f"{section_header}\n"] + new_lines # Finally, updating the changelog. # Read the current changelog lines. We will print them back as is, except for one new From 582a68d86910a574f9330f3716a4544ccdcbd509 Mon Sep 17 00:00:00 2001 From: mashehu Date: Fri, 1 Mar 2024 13:31:50 +0100 Subject: [PATCH 4/5] fix if clause --- .github/workflows/changelog.py | 63 +++++++++++++++++----------------- 1 file changed, 31 insertions(+), 32 deletions(-) diff --git a/.github/workflows/changelog.py b/.github/workflows/changelog.py index ce5306e9ef..471665e4b1 100644 --- a/.github/workflows/changelog.py +++ b/.github/workflows/changelog.py @@ -178,38 +178,37 @@ def _skip_existing_entry_for_this_pr(line: str, same_section: bool = True) -> st print(f"Found line: {line.strip()}") print(f"inside_version_dev: {inside_version_dev}") print(f"section_header: {section_header}") - if inside_version_dev: - if line.lower().startswith(section_header.lower()): # Section of interest header - print(f"Found section header: {line.strip()}") - if already_added_entry: - print( - f"Already added new lines into section {section}, is the section duplicated?", - file=sys.stderr, - ) - sys.exit(1) - updated_lines.append(line) - # Collecting lines until the next section. - section_lines: List[str] = [] - while True: - line = orig_lines.pop(0) - if line.startswith("#"): - print(f"Found the next section header: {line.strip()}") - # Found the next section header, so need to put all the lines we collected. - updated_lines.append("\n") - _updated_lines = [_l for _l in section_lines + new_lines if _l.strip()] - updated_lines.extend(_updated_lines) - updated_lines.append("\n") - if new_lines: - print(f"Updated {changelog_path} section '{section}' with lines:\n" + "".join(new_lines)) - else: - print(f"Removed existing entry from {changelog_path} section '{section}'") - already_added_entry = True - # Pushing back the next section header line - orig_lines.insert(0, line) - break - # If the line already contains a link to the PR, don't add it again. - line = _skip_existing_entry_for_this_pr(line, same_section=True) - section_lines.append(line) + if inside_version_dev and line.lower().startswith(section_header.lower()): # Section of interest header + print(f"Found section header: {line.strip()}") + if already_added_entry: + print( + f"Already added new lines into section {section}, is the section duplicated?", + file=sys.stderr, + ) + sys.exit(1) + updated_lines.append(line) + # Collecting lines until the next section. + section_lines: List[str] = [] + while True: + line = orig_lines.pop(0) + if line.startswith("#"): + print(f"Found the next section header: {line.strip()}") + # Found the next section header, so need to put all the lines we collected. + updated_lines.append("\n") + _updated_lines = [_l for _l in section_lines + new_lines if _l.strip()] + updated_lines.extend(_updated_lines) + updated_lines.append("\n") + if new_lines: + print(f"Updated {changelog_path} section '{section}' with lines:\n" + "".join(new_lines)) + else: + print(f"Removed existing entry from {changelog_path} section '{section}'") + already_added_entry = True + # Pushing back the next section header line + orig_lines.insert(0, line) + break + # If the line already contains a link to the PR, don't add it again. + line = _skip_existing_entry_for_this_pr(line, same_section=True) + section_lines.append(line) else: updated_lines.append(line) From f65253cc3895036fd9f1147462eb38c5d27b159f Mon Sep 17 00:00:00 2001 From: nf-core-bot Date: Fri, 1 Mar 2024 12:33:32 +0000 Subject: [PATCH 5/5] [automated] Update CHANGELOG.md --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6d59140f95..eefa851fd1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,8 @@ ### General +- Changelog bot: handle also patch version before dev suffix ([#2820](https://github.com/nf-core/tools/pull/2820)) + ## [v2.13.1 - Tin Puppy Patch](https://github.com/nf-core/tools/releases/tag/2.13) - [2024-02-29] ### Template