我正在寻找看起来像这样的1类轮:

(gitversion | ConvertFrom-Json).SemVer.split('.') | [string]::Format("{0}.{1}.{2}",$_[0],$_[1] + 1,$_[2]) | git tag $_

所以,现在我有了0.1.0,我想要一个1的内衬将其映射到:0.2.0
我相信PS中的专家可以快速解决这个问题

最佳答案

您可以阅读整个json,使用版本的Major,Minor和Patch编号,并更新您感兴趣的任何一个……patch,minor或major。

我正在使用foreach-object访问json的所有属性,即使只有一个可用。 1线:

gitversion | ConvertFrom-Json | % { "$($_.Major).$($_.Minor + 1).$($_.Patch)" } | % { git tag $_ }



如果您在运行gitversion的路径上只有一个存储库,它将始终为您提供一个对象。 (当您在没有git存储库的目录中运行此命令时,gitversion失败并显示错误。)

我想强调一点,这在您只有主要版本,次要版本和补丁版本的情况下非常有用。在SemVersion类似于"SemVer":"0.1.0"的情况下,这很好。但是,如果您希望在下一个版本中也保留PreReleaseTag(并且不要删除alpha / beta等标记),则也可以在输出中包含PreReleaseTagWithDash。例如,预发布标签:"SemVer":"0.1.0-alpha.915"
gitversion | ConvertFrom-Json | % { "$($_.Major).$($_.Minor + 1).$($_.Patch)$($_.PreReleaseTagWithDash)" } | % { git tag $_ }

gitversion的JSON示例
  • 在dev或其他分支机构中,您可以期望semVer中包含预发行标签的变体。
  • {
      "Major":0,
      "Minor":1,
      "Patch":0,
      "PreReleaseTag":"alpha.915",
      "PreReleaseTagWithDash":"-alpha.915",
      "PreReleaseLabel":"alpha",
      "PreReleaseNumber":915,
      "WeightedPreReleaseNumber":915,
      "BuildMetaData":"",
      "BuildMetaDataPadded":"",
      "FullBuildMetaData":"Branch.dev.Sha.888xxx.xxx888",
      "MajorMinorPatch":"0.1.0",
      "SemVer":"0.1.0-alpha.915",
      "LegacySemVer":"0.1.0-alpha915",
      "LegacySemVerPadded":"0.1.0-alpha0915",
      "AssemblySemVer":"0.1.0.0",
      "AssemblySemFileVer":"0.1.0.0",
      "FullSemVer":"0.1.0-alpha.915",
      "InformationalVersion":"0.1.0-alpha.915+Branch.dev.Sha.888xx.xx888",
      "BranchName":"dev",
      "Sha":"888xx.xx888",
      "ShortSha":"7a1152f",
      "NuGetVersionV2":"0.1.0-alpha0915",
      "NuGetVersion":"0.1.0-alpha0915",
      "NuGetPreReleaseTagV2":"alpha0915",
      "NuGetPreReleaseTag":"alpha0915",
      "VersionSourceSha":"88xxx.xx88",
      "CommitsSinceVersionSource":915,
      "CommitsSinceVersionSourcePadded":"0915",
      "CommitDate":"2019-12-06"
    }
    
  • 在master分支中,通常会期望一个semver = major.minor.patch。
  • {
      "Major":0,
      "Minor":1,
      "Patch":0,
      "PreReleaseTag":"",
      "PreReleaseTagWithDash":"",
      "PreReleaseLabel":"",
      "PreReleaseNumber":"",
      "WeightedPreReleaseNumber":"",
      "BuildMetaData":0,
      "BuildMetaDataPadded":"0000",
      "FullBuildMetaData":"0.Branch.master.Sha.9999xxx....xxx999",
      "MajorMinorPatch":"0.1.0",
      "SemVer":"0.1.0",
      "LegacySemVer":"0.1.0",
      "LegacySemVerPadded":"0.1.0",
      "AssemblySemVer":"0.1.0.0",
      "AssemblySemFileVer":"0.1.0.0",
      "FullSemVer":"0.1.0+0",
      "InformationalVersion":"0.1.0+0.Branch.master.Sha.999xxx...xxx999",
      "BranchName":"master",
      "Sha":"86b0be929a84ba7e9b2a463e7dbdc9a3c9325dc1",
      "ShortSha":"86b0be9",
      "NuGetVersionV2":"0.1.0",
      "NuGetVersion":"0.1.0",
      "NuGetPreReleaseTagV2":"",
      "NuGetPreReleaseTag":"",
      "VersionSourceSha":"999xxx...xxx999",
      "CommitsSinceVersionSource":0,
      "CommitsSinceVersionSourcePadded":"0000",
      "CommitDate":"2018-02-18"
    }
    

    注意:我尚未在一个位置使用多个git存储库对此进行测试。如果您正在运行的路径上只有存储库,则此解决方案将起作用。

    关于powershell - Powershell:如何拆分,进行数学运算和格式化,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/60241494/

    10-08 21:14