Skip to content

feat(bump): add functionality to write the next version to stdout #1195

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

Merged

Conversation

marcelblijleven
Copy link
Contributor

Adds a --get-next flag which determines the next version and writes it to stdout.

Description

The new --get-next flag can be used to determine the next version based on the available commits, and output it to stdout. This can be useful in CI, for example to determine the version for a preview build image.

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

When provided, the --get-next flag makes commitizen behave similarly to --dry-run, it doesn't change any files and it doesn't create a tag. It determines the next version the same way a dry run does. It writes the next version to stdout, with no other output.

The flag can't be used with --changelog, --changelog-to-stdout and MANUAL_VERSION, a NotAllowed exception will be raised if these options are provided together with --get-next.

An example use case is assigning the output to a variable in CI.

Steps to Test This Pull Request

  1. Make sure you have fetched tags locally
  2. Add a commit that is eligible for a bump
  3. Run poetry run cz bump --get-next
  4. Compare the output with poetry run cz bump --dry-run

Additional context

Copy link

codecov bot commented Jul 30, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.61%. Comparing base (120d514) to head (008c652).
Report is 395 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1195      +/-   ##
==========================================
+ Coverage   97.33%   97.61%   +0.27%     
==========================================
  Files          42       55      +13     
  Lines        2104     2516     +412     
==========================================
+ Hits         2048     2456     +408     
- Misses         56       60       +4     
Flag Coverage Δ
unittests 97.61% <100.00%> (+0.27%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Adds a --get-next flag which determines the next version and writes it to stdout.
@marcelblijleven marcelblijleven force-pushed the feature/add-get-next-flag branch from 76c6975 to 476be78 Compare July 30, 2024 19:01
@woile
Copy link
Member

woile commented Jul 31, 2024

Thanks for the contribution! It looks good 🎉 . Could you add a comparison in the docs with dry-run? Why chose one over the other.

Moreover, should this be part of the version command? I wonder if instead we should have: cz version --project --next 🤔 I know it might be a bit harder to implement. @Lee-W ?

@Lee-W
Copy link
Member

Lee-W commented Jul 31, 2024

The idea looks great! I'll take a look this weekend when leading yet another dev sprint haha

@marcelblijleven
Copy link
Contributor Author

Thanks for the feedback, I've just added some additional information to the documentation.

@Lee-W
Copy link
Member

Lee-W commented Aug 4, 2024

did not actually have the time to check it this weekend 🤦‍♂️ will try to do it these days!

Copy link
Member

@Lee-W Lee-W left a comment

Choose a reason for hiding this comment

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

I left a few nitpicks. non-blocking

@@ -190,6 +192,9 @@ def __call__(self) -> None: # noqa: C901
"--prerelease-offset cannot be combined with MANUAL_VERSION"
)

if get_next:
Copy link
Member

Choose a reason for hiding this comment

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

Probably not required in this PR, but I feel we could move these validations out as a separate function 🤔



@pytest.mark.usefixtures("tmp_commitizen_project")
def test_bump_get_next__changelog_is_not_allowed(mocker: MockFixture):
Copy link
Member

Choose a reason for hiding this comment

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

I feel we can combine these not_allowed test cases

@Lee-W
Copy link
Member

Lee-W commented Aug 8, 2024

I'm planning on merging it these days. But please do let me know if you want to take a look 🙂 @woile @noirbizarre

@Lee-W Lee-W added pr-status: ready-to-merge almost ready to merge. just keep it for a few days for others to check and removed pr-status: wait-for-review labels Aug 9, 2024
@Lee-W Lee-W merged commit b84a83b into commitizen-tools:master Aug 11, 2024
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr-status: ready-to-merge almost ready to merge. just keep it for a few days for others to check pr-status: wait-for-review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants