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

When workflow is set to empty string, gitversion gives errors for values not provided in config #4149

Open
2 tasks done
David-Hari opened this issue Aug 9, 2024 · 13 comments

Comments

@David-Hari
Copy link

David-Hari commented Aug 9, 2024

Prerequisites

  • I have written a descriptive issue title
  • I have searched issues to ensure it has not already been reported

GitVersion package

GitVersion.Portable

GitVersion version

6.0.1+Branch.main.Sha.0fd23d1af997a7b7c6f22f27310443270a91fb18

Operating system

Windows

What are you seeing?

I'm just getting started with GitVersion so I'm unsure of the exact config that will suit my needs. I want my GitVersion.yml file to be minimal, without needing to specify properties when they will be the default. However, I also don't want to use any of the workflow templates, as they define specific branch config that I do not want. Therefore, I set workflow: '' in my config.
My entire config so far looks like this:

workflow: ''
mode: ContinuousDelivery
branches:
  master:
    regex: ^master$|^main$
    increment: Minor
  maintenance:
    regex: ^maintenance/(\d+\.\d+)\.x$
    increment: Patch

But this causes GitVersion to give an error complaining about missing values. I then set a few more properties,

assembly-versioning-scheme: MajorMinorPatch
assembly-file-versioning-scheme: MajorMinorPatch
commit-message-incrementing: Disabled

This still does not satisfy GitVersion and it now complains about tag-pre-release-weight having no value:

An unexpected error occurred:
System.Exception: Configuration value for 'TagPreReleaseWeight' has no value. (this should not happen, please report an issue)
   at GitVersion.Configuration.EffectiveConfiguration..ctor(IGitVersionConfiguration configuration, IBranchConfiguration branchConfiguration, EffectiveConfiguration fallbackConfiguration) in /_/src/GitVersion.Core/Configuration/EffectiveConfiguration.cs:line 42
   at GitVersion.VersionCalculation.NextVersionCalculator.FindVersion() in /_/src/GitVersion.Core/VersionCalculation/VersionCalculators/NextVersionCalculator.cs:line 32
   at GitVersion.GitVersionCalculateTool.CalculateVersionVariables() in /_/src/GitVersion.Core/Core/GitVersionCalculateTool.cs:line 45
   at GitVersion.GitVersionExecutor.RunGitVersionTool(GitVersionOptions gitVersionOptions) in /_/src/GitVersion.App/GitVersionExecutor.cs:line 66

The documentation states that the default value for this property is 60000, so it should use that instead of forcing me to explicitly define it.
Also, as you can see from the above, the error message tells me to report this issue!

What is expected?

If a property has a default value, then that value should be used if the property is not specified in the config.
This really only applies when not using a workflow template.

Steps to Reproduce

Create a GitVersion.yml file as mentioned in the description, then run gitversion on a repo.

RepositoryFixture Test

No response

Output log or link to your CI build (if appropriate).

Applicable build agent found: 'LocalBuild'.
Working directory: C:\<my project>
Project root is: C:\<my project>\
DotGit directory is: C:\<my project>\.git
Branch from build environment:
Found configuration file at 'C:\<my project>\GitVersion.yml'
-< Begin: Loading version variables from disk cache file C:\<my project>\.git\gitversion_cache\F469652E2BB642746C44ADE725BF5092A940179D >-
Cache file C:\<my project>\.git\gitversion_cache\F469652E2BB642746C44ADE725BF5092A940179D not found.
-< End: Loading version variables from disk cache file C:\dev\<my project>\.git\gitversion_cache\F469652E2BB642746C44ADE725BF5092A940179D (Took: 0.31ms) >-
Found configuration file at 'C:\<my project>\GitVersion.yml'
Using latest commit on specified branch
Getting tagged semantic versions. TagPrefix:  and Format: Strict
Running against branch: master ('83613eb' - test commit)
@HHobeck
Copy link
Contributor

HHobeck commented Aug 12, 2024

The reason why we have introduced the workflow templates was exactly to not providing any default values in code.

I think we have three options:

  • Define the default values in code
  • Change just the documentation
  • Create a template which just defines a minimal set of properties

At this point I'm not sure what the desired solution might be for your issue. @asbjornu what do you think?

@asbjornu
Copy link
Member

@HHobeck, I think the best option is:

Create a template which just defines a minimal set of properties

@HHobeck HHobeck added this to the 6.x milestone Aug 12, 2024
@HHobeck
Copy link
Contributor

HHobeck commented Aug 12, 2024

@David-Hari: May I ask you to do the changes and create a pull-request?

@David-Hari
Copy link
Author

So what you are saying is that if a template is not used (the workflow property is set to an empty string) then gitversion should use a minimal template instead of none?
Or are you suggesting that I create and use such a template (is that even possible)?

@HHobeck
Copy link
Contributor

HHobeck commented Aug 13, 2024

So what you are saying is that if a template is not used (the workflow property is set to an empty string) then gitversion should use a minimal template instead of none? Or are you suggesting that I create and use such a template (is that even possible)?

I think the second option is appropriated. I would say create a new template with the name e.g. default/v1 which includes a minimal set of configuration values. This template you can use for your scenario instead of an empty string.

@David-Hari
Copy link
Author

Can you point me to the documentation on how to create my own template? I did not think that was possible.

Also, if I am to create my own template I may as well just keep the properties in my GitVersion.yml file as it's one less file to deal with.
But then you should still do something about that "this should not happen, please report an issue" message in the errors.

@David-Hari
Copy link
Author

David-Hari commented Aug 13, 2024

Also, if you say that the point of the templates is to provide the default values then why do I see this here:
https://github.com/GitTools/GitVersion/blob/main/schemas/6.0/GitVersion.configuration.json#L34

Seems like the code could read from there if no value is provided by the user's config file.

Looks like there is code for handling default attributes. Maybe it's just not working.

@HHobeck
Copy link
Contributor

HHobeck commented Aug 14, 2024

A new template mechanism was introduced to provide templates you can use in the custom configuration file. The json scheme file itselfe will be generated based on the json attribute annotation. Obviously the annotation (and also the documentation) doesn't reflect the actual implementation and needs to be updated. We don't want to have any default values in code (only in configuration template files).

A starting point might be:

  • create a new file under the folder docs/input/docs/workflows/
  • add this file as a link in project GitVersion.Configuration under the folder Workflows
  • define Build Action Embedded resource
  • change the annotation in GitVersionConfiguration.cs
  • generate the json scheme file

@arturcic: Something I've forgotten?

There is no How To yet. If you not mind please document the steps.

Thank you very much.

@arturcic
Copy link
Member

I think adding an test case here https://github.com/arturcic/GitVersion/blob/main/src/GitVersion.Configuration.Tests/Workflows/WorkflowsTests.cs

And unit tests for the new workflow?

@David-Hari
Copy link
Author

@HHobeck, so you are asking me to make all these changes in the GitVersion source code right? To add a new template that contains the default values, yes?

What about my earlier comment on the existing code that appears to handle default values?
You keep saying that you don't want to have any default values in code yet the above seems to indicate that it already does define the defaults in the schema json. I don't see what's wrong with that, except that it obviously isn't working at the moment.

@HHobeck
Copy link
Contributor

HHobeck commented Aug 15, 2024

@HHobeck, so you are asking me to make all these changes in the GitVersion source code right? To add a new template that contains the default values, yes?

Yes correct.

What about my earlier comment on the existing code that appears to handle default values? You keep saying that you don't want to have any default values in code yet the above seems to indicate that it already does define the defaults in the schema json.

What code do you mean? The JSON schema is generated from the annotation and it is just there for documenting reason.

I don't see what's wrong with that, except that it obviously isn't working at the moment.

@asbjornu Can you please elaborate?

@David-Hari
Copy link
Author

What code do you mean? The JSON schema is generated from the annotation and it is just there for documenting reason.

The json I linked to in my earlier comment. This file.
I did not realise it was only for documentation. When I said it wasn't working I did not know that.
However, it seems like it would be a good idea to also use that json file to let the GitVersion code know about the default values. That way you still don't have to hard-code anything and you also don't need to define every single property in the templates.
When the code needs to resolve a property value (perhaps in the EffectiveConfiguration class), it would first look in the user's config file and if not there it would look in the template and if not there it would use the default.

Anyway, that's just my opinion. I am not involved in this project so I am not going to attempt to make any changes. I will instead just leave my GitVersion.yml file the way it is.
I would suggest, however, that you remove the "this should not happen, please report an issue" message as it can be confusing to new users who are not aware of how default values do or do not work.

@HHobeck
Copy link
Contributor

HHobeck commented Aug 16, 2024

We have removed the default values in code and introduced a template mechanism. That means introducing default values in code is not the desired solution here because we want to have a single source of truth. If you like you can create a template which includes a minimal set of values which can be used as a base template. Yes, I agree the annotation and the exception messages like you mentioned should be removed/changed as well.

Regards
Hardy

@HHobeck HHobeck removed this from the 6.x milestone Sep 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants