8000 feat(scm_provider): add branch-based version retrieval by mgcollie · Pull Request #1 · mgcollie/commitizen · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

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

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mgcollie
Copy link
Owner
@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 = ""
v for v in matches if v.is_prerelease and release_type in v.prerelease
]
if prerelease_matches:
return str(prerelease_matches[-1])
Copy link
@chadrik chadrik Jun 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we want to only keep tags of the same prerelease type? isn't it possible that I could be on staging/rc branch and the latest version is a beta version because no rc versions have been created from that beta version?

would it work to say that we want to filter prereleases that are "higher" than the prerelease that corresponds to our branch?

  • alpha would filter beta and rc.
  • beta would filter rc.
  • rc would not filter any prereleases

or to put this in the reverse:

  • rc would keep rc, beta, and alpha versions
  • beta would keep beta, and alpha versions
  • alpha would keep only alpha

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0