Skip to content

feat: Commit parser w/ path filter for monorepos #614

Open
@lucasvieirasilva

Description

@lucasvieirasilva

Description

Adding the use_only_cwd_commits config makes it possible to make the semantic release look for commits in the cwd folder only.

The default behavior is any commit in the repo can trigger a package release.

https://github.com/python-semantic-release/python-semantic-release/blob/master/semantic_release/vcs_helpers.py#L19-L26

_repo: Optional[Repo]
_sub_directory = ""
try:
    _repo = Repo(".", search_parent_directories=True)
    if config.get("use_only_cwd_commits") and config.get("version_source") == "commit":
        _sub_directory = os.path.relpath(os.getcwd(), _repo.working_dir)
except InvalidGitRepositoryError:
    _repo = None

it will be good to have a config option to define one or more folders in the repo to semantic release CLI look for commits.

Use cases

Monorepo: When you have multiple packages in the same repo, you can use use_only_cwd_commits to force the semantic release to look for commits only in the package folder.

However, when you have local dependencies that could potentially trigger the release of the application, it is required to look at multiple folders to decide if a release is necessary.

Issue reference: lucasvieirasilva/nx-plugins#122

Example:

- apps/app1/pyproject.toml
- libs/lib1/pyproject.toml

In this example, app1 references lib1 as a local dependency using the Poetry path reference https://python-poetry.org/docs/dependency-specification/#path-dependencies

...
[tool.poetry]
name = "app1"
...

    [tool.poetry.dependencies.lib1]
    path = "../../libs/lib1"
    develop = true
...

If something changes in the lib1 it should trigger the app1 release, however, the commit path is only in the libs/lib1 folder, not in the apps/app1 folder.

In this case, the use_only_cwd_commits config isn't gonna work.

If we have the option to specify multiple paths for the commit analyzer, I could explicitly reference libs/lib1 in the apps/app1/pyproject.toml semantic release config.

Possible implementation

  • a new config entry commit_paths that accepts a list of paths.
[tool.semantic_release]
version_variable = [
    "pyproject.toml:version"
]
branch = "main"
upload_to_pypi = false
upload_to_release = false
commit_paths = [
    "apps/app1",
    "libs/lib1"
]

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmedPrevent from becoming stalefeatureA new feature or a feature request

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions