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

Fix CloudBuildAllVars value formatting #882

Merged

Conversation

ronaldbarendse
Copy link
Contributor

As mentioned in #876 (comment), the formatting of the CloudBuildAllVars values used the current culture and didn't specify a format for date values, causing the format to change based on the current culture and not be consistent (between systems/build servers).

Although currently only the GitCommitDate value is affected, I've ensured the code also uses the invariant culture for other types (e.g. in case a decimal value is added in the future). I've also ignored the VersionOptions property, since that isn't a simple value type and other complex values aren't outputted as well (like BuildMetadataWithCommitId and BuildMetadata).

Before this PR, nbgv.exe get-version -f json would output the following:

{
  // ...
  "CloudBuildAllVars": {
    "NBGV_CloudBuildNumber": "3.6.72-alpha",
    "NBGV_VersionFileFound": "True",
    "NBGV_VersionOptions": "Nerdbank.GitVersioning.VersionOptions",
    "NBGV_AssemblyVersion": "3.6.72.10058",
    "NBGV_AssemblyFileVersion": "3.6.72.10058",
    "NBGV_AssemblyInformationalVersion": "3.6.72-alpha+274a42ed33",
    "NBGV_PublicRelease": "True",
    "NBGV_PrereleaseVersion": "-alpha",
    "NBGV_PrereleaseVersionNoLeadingHyphen": "alpha",
    "NBGV_SimpleVersion": "3.6.72",
    "NBGV_BuildNumber": "72",
    "NBGV_VersionRevision": "10058",
    "NBGV_MajorMinorVersion": "3.6",
    "NBGV_VersionMajor": "3",
    "NBGV_VersionMinor": "6",
    "NBGV_GitCommitId": "274a42ed3321bcc43632dc970d65677f99a486a9",
    "NBGV_GitCommitIdShort": "274a42ed33",
    "NBGV_GitCommitDate": "5-12-2022 23:22:02 +00:00",
    "NBGV_VersionHeight": "72",
    "NBGV_VersionHeightOffset": "0",
    "NBGV_BuildingRef": "refs/heads/main",
    "NBGV_Version": "3.6.72.10058",
    "NBGV_BuildMetadataFragment": "+274a42ed33",
    "NBGV_NuGetPackageVersion": "3.6.72-alpha",
    "NBGV_ChocolateyPackageVersion": "3.6.72-alpha",
    "NBGV_NpmPackageVersion": "3.6.72-alpha",
    "NBGV_SemVer1": "3.6.72-alpha",
    "NBGV_SemVer2": "3.6.72-alpha",
    "NBGV_SemVer1NumericIdentifierPadding": "4"
  },
  // ...
}

With this PR applied, you'll notice the NBGV_VersionOptions is not present anymore and NBGV_GitCommitDate contains an ISO 8601 date format:

{
  // ...
  "CloudBuildAllVars": {
    "NBGV_CloudBuildNumber": "3.6.73-alpha+03e9883256",
    "NBGV_VersionFileFound": "True",
    "NBGV_AssemblyVersion": "3.6.73.1001",
    "NBGV_AssemblyFileVersion": "3.6.73.1001",
    "NBGV_AssemblyInformationalVersion": "3.6.73-alpha+03e9883256",
    "NBGV_PublicRelease": "False",
    "NBGV_PrereleaseVersion": "-alpha",
    "NBGV_PrereleaseVersionNoLeadingHyphen": "alpha",
    "NBGV_SimpleVersion": "3.6.73",
    "NBGV_BuildNumber": "73",
    "NBGV_VersionRevision": "1001",
    "NBGV_MajorMinorVersion": "3.6",
    "NBGV_VersionMajor": "3",
    "NBGV_VersionMinor": "6",
    "NBGV_GitCommitId": "03e988325666cd92193afb2ce5b10688276d9ee3",
    "NBGV_GitCommitIdShort": "03e9883256",
    "NBGV_GitCommitDate": "2023-01-04T09:22:10+00:00",
    "NBGV_VersionHeight": "73",
    "NBGV_VersionHeightOffset": "0",
    "NBGV_BuildingRef": "refs/heads/feature/cloudbuildallvars-formatting",
    "NBGV_Version": "3.6.73.1001",
    "NBGV_BuildMetadataFragment": "+03e9883256",
    "NBGV_NuGetPackageVersion": "3.6.73-alpha-g03e9883256",
    "NBGV_ChocolateyPackageVersion": "3.6.73-alpha-g03e9883256",
    "NBGV_NpmPackageVersion": "3.6.73-alpha.g03e9883256",
    "NBGV_SemVer1": "3.6.73-alpha-03e9883256",
    "NBGV_SemVer2": "3.6.73-alpha.g03e9883256",
    "NBGV_SemVer1NumericIdentifierPadding": "4"
  },
  // ...
}

Copy link
Collaborator

@AArnott AArnott left a comment

Choose a reason for hiding this comment

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

Thanks so much for this contribution. It is well thought out and executed.

src/NerdBank.GitVersioning/VersionOracle.cs Outdated Show resolved Hide resolved
@AArnott AArnott added this to the v3.6 milestone Jan 20, 2023
@AArnott AArnott merged commit 175cea8 into dotnet:main Jan 20, 2023
@ronaldbarendse ronaldbarendse deleted the feature/cloudbuildallvars-formatting branch January 31, 2023 15:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants