Skip to content

Commit

Permalink
Merge pull request #2645 from mashehu/update-image-syntax-in-template
Browse files Browse the repository at this point in the history
Template: switch to new image syntax in readme (and fix changelog action)
  • Loading branch information
mashehu authored Jan 9, 2024
2 parents ccf1104 + 243084b commit da485a8
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 25 deletions.
46 changes: 24 additions & 22 deletions .github/workflows/changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import os
import re
import subprocess
import sys
from pathlib import Path
from typing import List
Expand Down Expand Up @@ -51,39 +50,33 @@
sys.exit(0)


def _run_cmd(cmd):
print(cmd)
result = subprocess.run(cmd, shell=True, capture_output=True, text=True)
if result.returncode != 0:
raise RuntimeError(f"Error executing command: {result.stderr}")
return result


def _determine_change_type(pr_title) -> str:
def _determine_change_type(pr_title) -> tuple[str, str]:
"""
Determine the type of the PR: Template, Download, Linting, Modules, Subworkflows, or General
Returns a tuple of the section name and the module info.
"""
sections = {
"Template": "### Template updates",
"Download": "### Download updates",
"Linting": "### Linting updates",
"Template": "### Template",
"Download": "### Download",
"Linting": "### Linting",
"Modules": "### Modules",
"Subworkflows": "### Subworkflows",
}
current_section = "### General"
current_section_header = "### General"
current_section = "General"

# Check if the PR in any of the sections.
for section, section_header in sections.items():
# check if the PR title contains any of the section headers, with some loose matching, e.g. removing plural and suffixes
if re.sub(r"s$", "", section.lower().replace("ing", "")) in pr_title.lower():
current_section = section_header

return current_section
current_section_header = section_header
current_section = section
print(f"Detected section: {current_section}")
return current_section, current_section_header


# Determine the type of the PR: new module, module update, or core update.
section = _determine_change_type(pr_title)
# Determine the type of the PR
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)
Expand All @@ -93,11 +86,14 @@ def _determine_change_type(pr_title) -> str:

# Handle manual changelog entries through comments.
if comment := comment.removeprefix("@nf-core-bot changelog").strip():
print(f"Adding manual changelog entry: {comment}")
pr_title = comment
new_lines = [
f"- {pr_title} {pr_link}\n",
]

print(f"Adding new lines into section '{section}':\n" + "".join(new_lines))

# Finally, updating the changelog.
# Read the current changelog lines. We will print them back as is, except for one new
# entry, corresponding to this new PR.
Expand All @@ -108,6 +104,7 @@ def _determine_change_type(pr_title) -> str:

def _skip_existing_entry_for_this_pr(line: str, same_section: bool = True) -> str:
if line.strip().endswith(pr_link):
print(f"Found existing entry for this pull request #{pr_number}:")
existing_lines = [line]
if new_lines and new_lines == existing_lines and same_section:
print(f"Found existing identical entry for this pull request #{pr_number} in the same section:")
Expand All @@ -126,7 +123,7 @@ def _skip_existing_entry_for_this_pr(line: str, same_section: bool = True) -> st
return line


# Find the next line in the change log that matches the pattern "## MultiQC v.*dev"
# Find the next line in the change log that matches the pattern "# nf-core/tools v.*dev"
# If it doesn't exist, exist with code 1 (let's assume that a new section is added
# manually or by CI when a release is pushed).
# Else, find the next line that matches the `section` variable, and insert a new line
Expand All @@ -140,6 +137,7 @@ def _skip_existing_entry_for_this_pr(line: str, same_section: bool = True) -> st
line = _skip_existing_entry_for_this_pr(line, same_section=False)

if line.startswith("# ") and not line.strip() == "# nf-core/tools: Changelog": # Version header, e.g. "# v2.12dev"
print(f"Found version header: {line.strip()}")
updated_lines.append(line)

# Parse version from the line `# v2.12dev` or
Expand Down Expand Up @@ -175,8 +173,11 @@ def _skip_existing_entry_for_this_pr(line: str, same_section: bool = True) -> st
updated_lines.append(line)
break
continue

if inside_version_dev and line.lower().startswith(section.lower()): # Section of interest header
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?",
Expand All @@ -189,6 +190,7 @@ def _skip_existing_entry_for_this_pr(line: str, same_section: bool = True) -> st
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()]
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

- Add a Github Action Workflow to the pipeline template that tests a successful download with 'nf-core download' ([#2618](https://github.com/nf-core/tools/pull/2618))
- Use `pre-commit` to lint files in GitHub CI ([#2635](https://github.com/nf-core/tools/pull/2635))
- Use pdiff also on gitpod for nf-test ([#2640](https://github.com/nf-core/tools/pull/2640))
- switch to new image syntax in readme ([#2645](https://github.com/nf-core/tools/pull/2645))
- Add conda channel order to nextflow.config ([#2094](https://github.com/nf-core/tools/pull/2094))

### Download
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# ![nf-core/tools](docs/images/nfcore-tools_logo_light.png#gh-light-mode-only) ![nf-core/tools](docs/images/nfcore-tools_logo_dark.png#gh-dark-mode-only) <!-- omit in toc -->
<picture>
<source media="(prefers-color-scheme: dark)" srcset="docs/images/nfcore-tools_logo_dark.png">
<img alt="nf-core/tools logo" src="docs/images/nfcore-tools_logo_light.png">
</picture><!-- omit in toc -->

[![Python tests](https://github.com/nf-core/tools/workflows/Python%20tests/badge.svg?branch=master&event=push)](https://github.com/nf-core/tools/actions?query=workflow%3A%22Python+tests%22+branch%3Amaster)
[![codecov](https://codecov.io/gh/nf-core/tools/branch/master/graph/badge.svg)](https://codecov.io/gh/nf-core/tools)
Expand Down
6 changes: 4 additions & 2 deletions nf_core/pipeline-template/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{% if branded -%}
<picture>

# ![{{ name }}](docs/images/{{ logo_light }}#gh-light-mode-only) ![{{ name }}](docs/images/{{ logo_dark }}#gh-dark-mode-only)

<source media="(prefers-color-scheme: dark)" srcset="docs/images/{{ logo_dark }}">
<img alt="{{ name }} logo" src="docs/images/{{ logo_light }}">
</picture>
{% endif -%}
{% if github_badges -%}
[![GitHub Actions CI Status](https://github.com/{{ name }}/workflows/nf-core%20CI/badge.svg)](https://github.com/{{ name }}/actions?query=workflow%3A%22nf-core+CI%22)
Expand Down

0 comments on commit da485a8

Please sign in to comment.