commitizen icon indicating copy to clipboard operation
commitizen copied to clipboard

[feature] Check the consistency of commitizen version and versions in version_file

Open Lee-W opened this issue 5 years ago • 6 comments

Currently, this checking behavior does not work when --dry-run is passed. The reason is that reading version in version and writing version to file is implemented in the same function (i.e. commitizen/bump.py::update_version_in_files)

TODO

  • [ ] Separate the read step and write step in commitizen/bump.py::update_version_in_files
  • [ ] fix the error that checking consistency is not performed when passing --dry-run

Lee-W avatar Apr 28 '20 07:04 Lee-W

Shall we close this one?

woile avatar Jun 26 '20 13:06 woile

No, #186 only implements a portion of it.

Lee-W avatar Jun 26 '20 14:06 Lee-W

Can u expand on what needs to be done for this ticket?

woile avatar Jun 27 '20 08:06 woile

I just update the description. See if it's clear 🙂

Lee-W avatar Jun 27 '20 10:06 Lee-W

I recently experienced this issue.

We use the --dry-run and --check-consistency flags on feature branches. On master, we use just --check-consistency.

Our expectation would be that any consistency issues would be raised on the feature branch. However, as noted above, the --check-consistency flag isn't valid when using --dry-run.

I have two proposals:

  1. Update the code to check-consistency when using --dry-run
  2. Raise a warning or error when both flags are passed

jmuddle-via avatar Jan 27 '23 10:01 jmuddle-via

One option is to pass dry_run as a flag into https://github.com/commitizen-tools/commitizen/blob/cb798dc6400fba04df8c6c1d1b3ec96bfe9c13b0/commitizen/bump.py#L148

def update_version_in_files(
    current_version: str, new_version: str, files: List[str], *, check_consistency=False, dry_run=False
) -> None:
    """Change old version to the new one in every file given.
    Note that this version is not the tag formatted one.
    So for example, your tag could look like `v1.0.0` while your version in
    the package like `1.0.0`.
    """
    # TODO: separate check step and write step
    for location in files:
        drive, tail = os.path.splitdrive(location)
        path, _, regex = tail.partition(":")
        filepath = drive + path
        if not regex:
            regex = _version_to_regex(current_version)

        current_version_found, version_file = _bump_with_regex(
            filepath, current_version, new_version, regex
        )

        if check_consistency and not current_version_found:
            raise CurrentVersionNotFoundError(
                f"Current version {current_version} is not found in {location}.\n"
                "The version defined in commitizen configuration and the ones in "
                "version_files are possibly inconsistent."
            )

        # Write the file out again
        if not dry_run:
            with smart_open(filepath, "w") as file:
                file.write(version_file)

The DryRunExit() would also need to move https://github.com/commitizen-tools/commitizen/blob/cb798dc6400fba04df8c6c1d1b3ec96bfe9c13b0/commitizen/commands/bump.py#L247

jmuddle-via avatar Jan 27 '23 10:01 jmuddle-via