c4urself / bump2version

Version-bump your software with a single command
https://pypi.python.org/pypi/bump2version
MIT License
1.06k stars 134 forks source link

Parse cli parameter is not working #122

Open fabiomatavelli opened 4 years ago

fabiomatavelli commented 4 years ago

We have a pipeline that runs the bump2version automatically but, to avoid configure all the repositories with the version standard, we are passing it through the --parse parameter.

The problem is that if it is not defined in .bumpversion.cfg or setup.cfg, the program simply ignore the parameter.

Here follows two examples:

export NEW_VERSION=0.0.1-xxxx.000000

bump2version --verbose \
  --parse "(?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(\-(?P<commit>.*))?" \
  --serialize "['{major}.{minor}.{patch}-{commit}', '{major}.{minor}.{patch}']" \
  --message 'Automatic build version: {current_version} → {new_version}' \
  --dry-run --allow-dirty \
  --new-version ${NEW_VERSION} \
  commit

Returns:

current_version=0.0.1-9ad4d93d.20704390
commit=True
tag=False
new_version=0.0.1-xxxx.000000

If we set the parse and serialize on .bumpversion.cfg, the same command returns:

current_version=0.0.1-9ad4d93d.20704390
commit=True
tag=False
parse=(?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(\-(?P<commit>.*))?
serialize=
{major}.{minor}.{patch}-{commit}
{major}.{minor}.{patch}
new_version=0.0.1-xxxx.000000
florisla commented 4 years ago

What was your expected output? Something like new_version=['0.0.1-xxxx.000000', '0.0.1'] ?

Otherwise, if you want to specify two different serializations, you should use multiple --serialize arguments:

--serialize "{major}.{minor}.{patch}-{commit}" --serialize "{major}.{minor}.{patch}"

instead of

--serialize "['{major}.{minor}.{patch}-{commit}', '{major}.{minor}.{patch}']"
florisla commented 4 years ago

It seems there's a bug in the --list functionality; it does not always show what it needs to show.

florisla commented 4 years ago

I think I found the cause: bump2version requires a --new-version --current-version argument. When that's missing, the tool crashes instead of reporting it nicely.

See #94 .

The added .bumpversion.cfg file probably contains new_version current_version?

Can you try this one?

bump2version
    --verbose
    --parse "(?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(\-(?P<commit>.*))?"
    --serialize "{major}.{minor}.{patch}-{commit}"
    --serialize "{major}.{minor}.{patch}"
    --message "Automatic build version: {current_version} → {new_version}"
    --dry-run
    --allow-dirty
    --current-version "0.0.1-9ad4d93d.20704390"
    --new-version "0.0.1-xxxx.000000"
    commit
    versionfile.txt
florisla commented 4 years ago

Sorry, I meant --current_version of course.

florisla commented 4 years ago

(replying to @jpettit email) (he later clarified he was using a .bumversion.cfg file)

On Fri, Jan 17, 2020 at 5:15 AM jpettit wrote:

Just FYI - this works for me:

        bump2version --verbose \
        --parse "(?P<major>\d+).(?P<minor>\d+).(?P<patch>\d+)(\-(?P<commit>.*))?" \
        --serialize "{major}.{minor}.{patch}-{commit}" \
        --serialize "{major}.{minor}.{patch}" \
        --message "CICD Automatic Version {current_version} → {new_version} [skip ci]" \
        --allow-dirty --list \
        --new-version ${NEW_VERSION} \
        commit

I don't understand how bump2version determines the current_version in your case? Do you have a .bumpversion.cfg file present?

The last argument, "commit" is not a file on disk right? It's a version [part] which is not really used because you supply --new-version explicitly.

fabiomatavelli commented 4 years ago

@florisla hey, sorry for the delay. Yes, the commit is part of the version. I will try with multiple --serialize params to see if it works. My idea is to developers only specify the files that they want to update in the config file, and then I pass the rest of the parameters through the command.

I will test here and I let you know.

Thank you