Skip to content

[pull] master from python-semantic-release:master #171

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

Merged
merged 3 commits into from
Oct 17, 2024
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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# CHANGELOG


## v9.11.1 (2024-10-15)

### Fixes

* fix(changelog): prevent custom template errors when components are in hidden folders (#1060) ([`a7614b0`](https://github.com/python-semantic-release/python-semantic-release/commit/a7614b0db8ce791e4252209e66f42b5b5275dffd))


## v9.11.0 (2024-10-12)

### Features
Expand Down
10 changes: 5 additions & 5 deletions docs/automatic-releases/github-actions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ before the :ref:`version <cmd-version>` subcommand.

.. code:: yaml

- uses: python-semantic-release/python-semantic-release@v9.11.0
- uses: python-semantic-release/python-semantic-release@v9.11.1
with:
root_options: "-vv --noop"

Expand Down Expand Up @@ -684,7 +684,7 @@ to the GitHub Release Assets as well.
- name: Action | Semantic Version Release
id: release
# Adjust tag with desired version if applicable.
uses: python-semantic-release/python-semantic-release@v9.11.0
uses: python-semantic-release/python-semantic-release@v9.11.1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
git_committer_name: "github-actions"
Expand Down Expand Up @@ -744,7 +744,7 @@ The equivalent GitHub Action configuration would be:

- name: Action | Semantic Version Release
# Adjust tag with desired version if applicable.
uses: python-semantic-release/python-semantic-release@v9.11.0
uses: python-semantic-release/python-semantic-release@v9.11.1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
force: patch
Expand Down Expand Up @@ -772,13 +772,13 @@ Publish Action.
.. code:: yaml

- name: Release Project 1
uses: python-semantic-release/python-semantic-release@v9.11.0
uses: python-semantic-release/python-semantic-release@v9.11.1
with:
directory: ./project1
github_token: ${{ secrets.GITHUB_TOKEN }}

- name: Release Project 2
uses: python-semantic-release/python-semantic-release@v9.11.0
uses: python-semantic-release/python-semantic-release@v9.11.1
with:
directory: ./project2
github_token: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "python-semantic-release"
version = "9.11.0"
version = "9.11.1"
description = "Automatic Semantic Versioning for Python projects"
requires-python = ">=3.8"
license = { text = "MIT" }
Expand Down
2 changes: 1 addition & 1 deletion semantic_release/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
tags_and_versions,
)

__version__ = "9.11.0"
__version__ = "9.11.1"

__all__ = [
"CommitParser",
Expand Down
4 changes: 4 additions & 0 deletions semantic_release/changelog/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,12 @@ def make_changelog_context(

def read_file(filepath: str) -> str:
try:
if not filepath:
raise FileNotFoundError("No file path provided") # noqa: TRY301

with Path(filepath).open(newline=os.linesep) as rfd:
return rfd.read()

except FileNotFoundError as err:
logging.warning(err)
return ""
Expand Down
8 changes: 1 addition & 7 deletions semantic_release/changelog/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ def join_path(self, template: str, parent: str) -> str:
return str(PurePosixPath(parent).parent / template)


# pylint: disable=redefined-outer-name
def recursive_render(
template_dir: Path,
environment: Environment,
Expand All @@ -103,13 +102,8 @@ def recursive_render(
(Path(root), file)
for root, _, files in os.walk(template_dir)
for file in files
# we slice relpath.parts[1:] to allow the top-level
# template folder to have a dot prefix.
# e.g. to permit ".github/psr-templates" to contain the templates,
# rather than enforcing a top-level, non-hidden directory
if not any(
elem.startswith(".")
for elem in Path(root).relative_to(template_dir).parts[1:]
elem.startswith(".") for elem in Path(root).relative_to(template_dir).parts
)
and not file.startswith(".")
):
Expand Down
81 changes: 81 additions & 0 deletions tests/unit/semantic_release/changelog/test_changelog_context.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import os
from datetime import datetime
from textwrap import dedent
from typing import TYPE_CHECKING
Expand All @@ -15,11 +16,15 @@
from semantic_release.hvcs import Bitbucket, Gitea, Github, Gitlab
from semantic_release.version.translator import Version

from tests.const import EXAMPLE_CHANGELOG_MD_CONTENT

if TYPE_CHECKING:
from pathlib import Path

from git import Actor

from tests.fixtures.git_repo import BuildRepoFn


@pytest.fixture
def changelog_tpl_github_context() -> str:
Expand Down Expand Up @@ -358,3 +363,79 @@ def test_changelog_context_gitlab(

# Evaluate
assert expected_changelog == actual_changelog


def test_changelog_context_read_file(
example_git_https_url: str,
build_configured_base_repo: BuildRepoFn,
artificial_release_history: ReleaseHistory,
changelog_md_file: Path,
change_to_ex_proj_dir: Path,
example_project_dir: Path,
):
build_configured_base_repo(example_project_dir)

# normalize expected to os specific newlines
expected_changelog = str.join(
os.linesep,
[
*[
line.replace("\r", "")
for line in EXAMPLE_CHANGELOG_MD_CONTENT.strip().split("\n")
],
"",
],
)

changelog_tpl = """{{ "%s" | read_file | trim }}%ls""".replace(
"%s", str(changelog_md_file)
).replace("%ls", os.linesep)

env = environment(
newline_sequence="\n" if os.linesep == "\n" else "\r\n",
trim_blocks=True,
lstrip_blocks=True,
keep_trailing_newline=True,
autoescape=False,
)
context = make_changelog_context(
hvcs_client=Gitlab(example_git_https_url),
release_history=artificial_release_history,
mode=ChangelogMode.UPDATE,
prev_changelog_file=changelog_md_file,
insertion_flag="",
)
context.bind_to_environment(env)

# Create changelog from template with environment
actual_changelog = env.from_string(changelog_tpl).render()

# Evaluate
assert expected_changelog.encode() == actual_changelog.encode()


@pytest.mark.parametrize("file_path", ["", "nonexistent.md"])
def test_changelog_context_read_file_fails_gracefully(
example_git_https_url: str,
artificial_release_history: ReleaseHistory,
changelog_md_file: Path,
file_path: str,
):
changelog_tpl = """{{ "%s" | read_file }}""".replace("%s", file_path)
expected_changelog = ""

env = environment(trim_blocks=True, lstrip_blocks=True, keep_trailing_newline=True)
context = make_changelog_context(
hvcs_client=Gitlab(example_git_https_url),
release_history=artificial_release_history,
mode=ChangelogMode.UPDATE,
prev_changelog_file=changelog_md_file,
insertion_flag="",
)
context.bind_to_environment(env)

# Create changelog from template with environment
actual_changelog = env.from_string(changelog_tpl).render()

# Evaluate
assert expected_changelog == actual_changelog