Skip to content
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

feat: accept a fallback value in all formatted expressions #2179

Merged
merged 2 commits into from
Mar 14, 2020

Conversation

piedar
Copy link
Contributor

@piedar piedar commented Mar 13, 2020

Description

This PR extends the custom formatting syntax to support a fallback value in a variable expression, to be consistent with the fallback syntax for environment variables. It also adds the ability to specify a more complex fallback value in a quoted string.

For example

assembly-file-versioning-format: '{Major}.{Minor}.{Patch}.{WeightedPreReleaseNumber ?? 0}'
assembly-informational-format: '{AssemblySemFileVer}+{env:BUILD_TAG ?? "fancy-string*with%special#characters"}'

Motivation and Context

I tried to use

assembly-file-versioning-format: '{Major}.{Minor}.{Patch}.{WeightedPreReleaseNumber}'

but that fails for versions where there is no pre-release label because WeightedPreReleaseNumber is null. So then I tried

assembly-file-versioning-format: '{Major}.{Minor}.{Patch}.{WeightedPreReleaseNumber ?? 0}'

but discovered that this syntax was only supported for environment variables.

How Has This Been Tested?

  • added unit tests to better cover existing cases
  • added unit tests to cover new cases
  • examined references to discover that the changed code is used only for custom version formatting

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

Copy link
Member

@asbjornu asbjornu left a comment

Choose a reason for hiding this comment

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

This is great!

@asbjornu asbjornu merged commit 0703eaa into GitTools:master Mar 14, 2020
@asbjornu
Copy link
Member

Thank you so much for improving GitVersion, @piedar! 🙏

@arturcic arturcic added this to the 5.2.4 milestone Mar 14, 2020
arturcic pushed a commit that referenced this pull request Mar 14, 2020
Merge pull request #2179 from piedar/feat/format-fallback

Accept a fallback value in all formatted expressions
@github-actions
Copy link

🎉 This issue has been resolved in version 5.2.4 🎉
The release is available on:

Your GitReleaseManager bot 📦🚀

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

Successfully merging this pull request may close these issues.

3 participants