Skip to content

feat(scm_provider): add branch-based version retrieval #1155

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

Conversation

mgcollie
Copy link

@mgcollie mgcollie commented Jun 6, 2024

Description

The get_version function within the ScmProvider class has been enhanced to include branch-specific version retrieval capabilities. This update introduces the optional branch_prerelease_map configuration, allowing users to link branch names to specific release types (e.g., "b" for beta, "rc" for release candidate). This feature provides targeted version management suitable for different stages of the release workflow while ensuring backward compatibility by defaulting to the highest semver tag when no branch map is provided.

Checklist

  • Add test cases to all the changes you introduce
  • Run ./scripts/format and ./scripts/test locally to ensure this change passes linter check and test
  • Test the changes on the local machine manually
  • Update the documentation for the changes

Expected behavior

Upon defining a branch_prerelease_map in the project configuration, the get_version function should retrieve the latest version number based on the current branch and its associated release type. If no map is provided, the function will revert to fetching the highest semver tag across all branches, maintaining functionality for existing setups.

Steps to Test This Pull Request

  1. Update the pyrpoject.toml with a branch_prerelease_map (see below example)
  2. run the test_scm_provider.py tests

Additional context

This enhancement aligns with evolving development practices requiring more granular control over version management across multiple branches, particularly in environments employing CI/CD pipelines for automated release management.

Example pyproject.toml

[project]
name = "semver-demo"

[tool.commitizen]
name = "cz_conventional_commits"
tag_format = "$version"
version_scheme = "pep440"
version_provider = "scm"
major_version_zero = false

[tool.commitizen.branch_prerelease_map]
develop = "b"
staging = "rc"
master = ""

The get_version function in the ScmProvider class has been enhanced to
support branch-based version retrieval while maintaining backward
compatibility.

A new optional configuration setting branch_prerelease_map has been
introduced. It allows users to specify a mapping of branch names to release
types (e.g., "b" for beta, "rc" for release candidate) in their project
configuration file.

If the branch_prerelease_map is defined, the get_version function will use
the current branch and the specified release type to retrieve the highest
version matching that criteria. This enables users to obtain the latest
version specific to their release workflow.

When the branch_prerelease_map is not defined, the get_version function
falls back to its previous behavior of returning the highest semver tag,
ensuring backward compatibility for existing users.

This change provides more flexibility in version retrieval based on branch
names while maintaining a seamless experience for users who have not yet
adopted the new configuration.

pyproject.toml example:
[project]
name = "semver-demo"

[tool.commitizen]
name = "cz_conventional_commits"
tag_format = "$version"
version_scheme = "pep440"
version_provider = "scm"
major_version_zero = false

[tool.commitizen.branch_prerelease_map]
develop = "b"
staging = "rc"
master = ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant