Skip to content

Commit

Permalink
Merge pull request #103 from callowayproject/fix-regression
Browse files Browse the repository at this point in the history
Fix multiple changes to single file regression
  • Loading branch information
coordt authored Dec 15, 2023
2 parents 3fc195e + 909396d commit d5d02e2
Show file tree
Hide file tree
Showing 34 changed files with 1,049 additions and 636 deletions.
4 changes: 2 additions & 2 deletions .changelog-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ commit_classifiers:
- action: SummaryRegexMatch
category: Updates
kwargs:
pattern: (?i)^(?:update|change|rename|remove|delete|improve|refactor|chg|modif)[^\n]*$
pattern: (?i)^(?:update|change|rename|remove|delete|improve|chg|modif)[^\n]*$
- action: SummaryRegexMatch
category: Fixes
kwargs:
pattern: (?i)^(?:fix)[^\n]*$
pattern: (?i)^(?:refactor|fix)[^\n]*$
- action:
category: Other

Expand Down
23 changes: 23 additions & 0 deletions .github/actions/setup-python-and-git/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: checkout-and-setup-python
description: 'Checkout the repository and setup Python'
inputs:
python-version:
description: 'Python version to use'
required: false
default: '3.11'
runs:
using: 'composite'
steps:
- uses: actions/setup-python@v4
name: Setup Python
with:
python-version: ${{ inputs.python-version }}
cache: 'pip' # caching pip dependencies

- name: Git check
run: |
git config --global user.email "[email protected]"
git config --global user.name "Testing Git"
git --version
git config --list
shell: bash
2 changes: 1 addition & 1 deletion .github/workflows/bumpversion-pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:

- name: Install requirements
run: |
python -m pip install . bump-my-version
python -m pip install generate-changelog bump-my-version
- name: Get the release hint
id: generate-changelog
Expand Down
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Changelog

## Unreleased (2023-12-06)
## Unreleased (2023-12-09)
[Compare the full difference.](https://github.com/callowayproject/bump-my-version/compare/0.13.0...HEAD)


## 0.13.0 (2023-12-06)
[Compare the full difference.](https://github.com/callowayproject/bump-my-version/compare/0.12.0...0.13.0)

### Fixes
Expand Down
21 changes: 17 additions & 4 deletions bumpversion/bump.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""Version changing methods."""
import logging
import shlex
from pathlib import Path
from typing import TYPE_CHECKING, ChainMap, List, Optional
Expand All @@ -9,11 +8,13 @@
from bumpversion.version_part import Version

from bumpversion.config import Config
from bumpversion.config.files import update_config_file, update_ini_config_file
from bumpversion.config.files import update_config_file
from bumpversion.config.files_legacy import update_ini_config_file
from bumpversion.exceptions import ConfigurationError
from bumpversion.ui import get_indented_logger
from bumpversion.utils import get_context, key_val_string

logger = logging.getLogger("bumpversion")
logger = get_indented_logger(__name__)


def get_next_version(
Expand All @@ -35,14 +36,18 @@ def get_next_version(
ConfigurationError: If it can't generate the next version.
"""
if new_version:
logger.info("Attempting to set new version '%s'", new_version)
logger.indent()
next_version = config.version_config.parse(new_version)
elif version_part:
logger.info("Attempting to increment part '%s'", version_part)
logger.indent()
next_version = current_version.bump(version_part, config.version_config.order)
else:
raise ConfigurationError("Unable to get the next version.")

logger.info("Values are now: %s", key_val_string(next_version.values))
logger.dedent()
return next_version


Expand All @@ -65,8 +70,13 @@ def do_bump(
"""
from bumpversion.files import modify_files, resolve_file_config

logger.indent()

ctx = get_context(config)
logger.info("Parsing current version '%s'", config.current_version)
logger.indent()
version = config.version_config.parse(config.current_version)
logger.dedent()
next_version = get_next_version(version, config, version_part, new_version)
next_version_str = config.version_config.serialize(next_version, ctx)
logger.info("New version will be '%s'", next_version_str)
Expand All @@ -75,6 +85,8 @@ def do_bump(
logger.info("Version is already '%s'", next_version_str)
return

logger.dedent()

if dry_run:
logger.info("Dry run active, won't touch any files.")

Expand All @@ -90,6 +102,7 @@ def do_bump(
ctx = get_context(config, version, next_version)
ctx["new_version"] = next_version_str
commit_and_tag(config, config_file, configured_files, ctx, dry_run)
logger.info("Done.")


def commit_and_tag(
Expand All @@ -114,7 +127,7 @@ def commit_and_tag(

extra_args = shlex.split(config.commit_args) if config.commit_args else []

commit_files = {f.path for f in configured_files}
commit_files = {f.file_change.filename for f in configured_files}
if config_file:
commit_files |= {str(config_file)}

Expand Down
6 changes: 3 additions & 3 deletions bumpversion/cli.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""bump-my-version Command line interface."""
import logging
from typing import List, Optional

import rich_click as click
Expand All @@ -12,10 +11,10 @@
from bumpversion.config.files import find_config_file
from bumpversion.files import ConfiguredFile, modify_files
from bumpversion.show import do_show, log_list
from bumpversion.ui import print_warning, setup_logging
from bumpversion.ui import get_indented_logger, print_warning, setup_logging
from bumpversion.utils import get_context, get_overrides

logger = logging.getLogger(__name__)
logger = get_indented_logger(__name__)


@click.group(
Expand Down Expand Up @@ -307,6 +306,7 @@ def bump(
config.add_files(files)
config.included_paths = files

logger.dedent()
do_bump(version_part, new_version, config, found_config_file, dry_run)


Expand Down
9 changes: 7 additions & 2 deletions bumpversion/config/__init__.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
"""Configuration management."""
from __future__ import annotations

import logging
from typing import TYPE_CHECKING, Union

from bumpversion.config.files import read_config_file
from bumpversion.config.models import Config
from bumpversion.exceptions import ConfigurationError
from bumpversion.ui import get_indented_logger

if TYPE_CHECKING: # pragma: no-coverage
from pathlib import Path

logger = logging.getLogger(__name__)
logger = get_indented_logger(__name__)

DEFAULTS = {
"current_version": None,
Expand Down Expand Up @@ -49,6 +49,9 @@ def get_configuration(config_file: Union[str, Path, None] = None, **overrides) -
from bumpversion.config.utils import get_all_file_configs, get_all_part_configs
from bumpversion.scm import SCMInfo, SourceCodeManager, get_scm_info # noqa: F401

logger.info("Reading configuration")
logger.indent()

config_dict = DEFAULTS.copy()
parsed_config = read_config_file(config_file) if config_file else {}

Expand All @@ -75,6 +78,8 @@ def get_configuration(config_file: Union[str, Path, None] = None, **overrides) -
# Update and verify the current_version
config.current_version = check_current_version(config)

logger.dedent()

return config


Expand Down
Loading

0 comments on commit d5d02e2

Please sign in to comment.