public void Hotfix_branch()
 {
     var versionAndBranch = new VersionAndBranch
                            {
                                BranchType = BranchType.Hotfix,
                                Version = new SemanticVersion
                                          {
                                              Stability = Stability.Beta,
                                              PreReleasePartOne = 4
                                          }
                            };
     var tcVersion = TeamCityVersionBuilder.GenerateBuildVersion(versionAndBranch);
     Assert.AreEqual("##teamcity[buildNumber '0.0.0-Beta4']", tcVersion);
 }
 public void Develop_branch()
 {
     var versionAndBranch = new VersionAndBranch
                            {
                                BranchType = BranchType.Develop,
                                Version = new SemanticVersion
                                          {
                                              PreReleasePartOne = 4,
                                              Stability = Stability.Unstable
                                          }
                            };
     var tcVersion = TeamCityVersionBuilder.GenerateBuildVersion(versionAndBranch);
     Assert.AreEqual("##teamcity[buildNumber '0.0.0-Unstable4']", tcVersion);
 }
 public void Develop_branch()
 {
     var versionAndBranch = new VersionAndBranch
                            {
                                BranchType = BranchType.Develop,
                                Version = new SemanticVersion
                                          {
                                              PreReleasePartOne = 4,
                                              Stability = Stability.Unstable
                                          }
                            };
     var nugetVersion = NugetVersionBuilder.GenerateNugetVersion(versionAndBranch);
     NuGet.SemanticVersion.Parse(nugetVersion);
     Assert.AreEqual("0.0.0-Unstable0004", nugetVersion);
 }
    public void Hotfix_branch()
    {
        var versionAndBranch = new VersionAndBranch
                               {
                                   BranchType = BranchType.Hotfix,
                                   Version = new SemanticVersion
                                             {
                                                 Stability = Stability.Beta,
                                                 PreReleasePartOne = 4
                                             }
                               };

        var nugetVersion = NugetVersionBuilder.GenerateNugetVersion(versionAndBranch);
        NuGet.SemanticVersion.Parse(nugetVersion);
        Assert.AreEqual("0.0.0-Beta0004", nugetVersion);
    }
 public void Feature_branch()
 {
     var versionAndBranch = new VersionAndBranch
                            {
                                BranchType = BranchType.Feature,
                                Sha = "TheSha",
                                BranchName = "AFeature",
                                Version = new SemanticVersion
                                          {
                                              PreReleasePartOne = 4, //ignored
                                              PreReleasePartTwo = 4, //ignored
                                              Stability = Stability.Unstable
                                          }
                            };
     var tcVersion = TeamCityVersionBuilder.GenerateBuildVersion(versionAndBranch);
     Assert.AreEqual("##teamcity[buildNumber '0.0.0-Feature-AFeature-TheSha']", tcVersion);
 }
示例#6
0
        public static IEnumerable<string> GenerateBuildLogOutput(VersionAndBranch versionAndBranch)
        {
            if (!IsRunningInBuildAgent())
            {
                yield break;
            }
            var semanticVersion = versionAndBranch.Version;

            yield return TeamCityVersionBuilder.GenerateBuildVersion(versionAndBranch);
            yield return GenerateBuildParameter("Major", semanticVersion.Major.ToString());
            yield return GenerateBuildParameter("Minor", semanticVersion.Minor.ToString());
            yield return GenerateBuildParameter("Patch", semanticVersion.Patch.ToString());
            yield return GenerateBuildParameter("Stability", semanticVersion.Stability.ToString());
            yield return GenerateBuildParameter("PreReleaseNumber", semanticVersion.PreReleasePartOne.ToString());
            yield return GenerateBuildParameter("Version", TeamCityVersionBuilder.CreateVersionString(versionAndBranch));
            yield return GenerateBuildParameter("NugetVersion", NugetVersionBuilder.GenerateNugetVersion(versionAndBranch));
        }
    public void Feature_branch()
    {
        var versionAndBranch = new VersionAndBranch
                               {
                                   BranchType = BranchType.Feature,
                                   Sha = "TheSha",
                                   BranchName = "AFeature",
                                   Version = new SemanticVersion
                                             {
                                                 PreReleasePartOne = 4, //ignored
                                                 PreReleasePartTwo = 4, //ignored
                                                 Stability = Stability.Unstable
                                             }
                               };

        var nugetVersion = NugetVersionBuilder.GenerateNugetVersion(versionAndBranch);
        NuGet.SemanticVersion.Parse(nugetVersion);
        Assert.AreEqual("0.0.0-Feature-AFeature-TheSha", nugetVersion);
    }
    public void DevelopUnstable()
    {
        var semanticVersion = new VersionAndBranch
                              {
                                  BranchType = BranchType.Develop,
                                  BranchName = "develop",
                                  Sha = "a682956dccae752aa24597a0f5cd939f93614509",
                                  Version = new SemanticVersion
                                                       {
                                                           Major = 1,
                                                           Minor = 2,
                                                           Patch = 3,
                                                           PreReleasePartOne = 645,
                                                           Stability = Stability.Unstable,
                                                       }
                              };
        var informationalVersion = semanticVersion.ToLongString();

        Assert.AreEqual("1.2.3-unstable645 Branch:'develop' Sha:'a682956dccae752aa24597a0f5cd939f93614509'", informationalVersion);
    }
        public static string CreateVersionString(VersionAndBranch versionAndBranch)
        {
            var prereleaseString = "";

            var stability = versionAndBranch.Version.Stability;
            if (stability == null)
            {
                throw new Exception("Stability cannot be null");
            }
            if (stability != Stability.Final)
            {
                var preReleaseVersion = versionAndBranch.Version.PreReleasePartOne.ToString();
                if (versionAndBranch.Version.PreReleasePartTwo != null)
                {
                    preReleaseVersion += "." + versionAndBranch.Version.PreReleasePartTwo;
                }

                switch (versionAndBranch.BranchType)
                {
                    case BranchType.Develop:
                        prereleaseString = "-" + stability + preReleaseVersion;
                        break;

                    case BranchType.Release:
                        prereleaseString = "-" + stability + preReleaseVersion;
                        break;

                    case BranchType.Hotfix:
                        prereleaseString = "-" + stability + preReleaseVersion;
                        break;
                    case BranchType.PullRequest:
                        prereleaseString = "-PullRequest-" + versionAndBranch.Version.Suffix;
                        break;
                    case BranchType.Feature:
                        prereleaseString = "-Feature-" + versionAndBranch.BranchName + "-" + versionAndBranch.Sha;
                        break;
                }
            }
            return string.Format("{0}.{1}.{2}{3}", versionAndBranch.Version.Major, versionAndBranch.Version.Minor,
                versionAndBranch.Version.Patch, prereleaseString);
        }
        public static string GenerateBuildVersion(VersionAndBranch versionAndBranch)
        {
            var versionString = CreateVersionString(versionAndBranch);

            return string.Format("##teamcity[buildNumber '{0}']", versionString);
        }
 public void Release_branch_with_preReleaseTwo()
 {
     var versionAndBranch = new VersionAndBranch
                            {
                                BranchType = BranchType.Release,
                                Version = new SemanticVersion
                                          {
                                              PreReleasePartOne = 4,
                                              PreReleasePartTwo = 8,
                                              Stability = Stability.Beta,
                                          }
                            };
     var tcVersion = TeamCityVersionBuilder.GenerateBuildVersion(versionAndBranch);
     Assert.AreEqual("##teamcity[buildNumber '0.0.0-Beta4.8']", tcVersion);
 }
    public void Feature()
    {
        var semanticVersion = new VersionAndBranch
                              {
                                  BranchType = BranchType.Feature,
                                  BranchName = "feature1",
                                  Sha = "a682956dccae752aa24597a0f5cd939f93614509",
                                  Version = new SemanticVersion
                                                       {
                                                           Major = 1,
                                                           Minor = 2,
                                                           Patch = 3,
                                                           Stability = Stability.Unstable,
                                                           Suffix = "a682956d",
                                                       }
                              };
        var informationalVersion = semanticVersion.ToLongString();

        Assert.AreEqual("1.2.3-unstable.feature-a682956d Branch:'feature1' Sha:'a682956dccae752aa24597a0f5cd939f93614509'", informationalVersion);
    }
    public void HotfixAlpha()
    {
        var semanticVersion = new VersionAndBranch
                              {
                                  BranchType = BranchType.Hotfix,
                                  BranchName = "hotfix-foo",
                                  Sha = "a682956dccae752aa24597a0f5cd939f93614509",
                                  Version = new SemanticVersion
                                                       {
                                                           Major = 1,
                                                           Minor = 2,
                                                           Patch = 3,
                                                           PreReleasePartOne = 645,
                                                           Stability = Stability.Alpha,
                                                       }

                              };
        var informationalVersion = semanticVersion.ToLongString();

        Assert.AreEqual("1.2.3-alpha645 Branch:'hotfix-foo' Sha:'a682956dccae752aa24597a0f5cd939f93614509'", informationalVersion);
    }
    public void ReleaseBeta()
    {
        var semanticVersion = new VersionAndBranch
                              {
                                  BranchType = BranchType.Release,
                                  BranchName = "release-1.2",
                                  Sha = "a682956dccae752aa24597a0f5cd939f93614509",
                                  Version = new SemanticVersion
                                                       {
                                                           Major = 1,
                                                           Minor = 2,
                                                           Patch = 0,
                                                           PreReleasePartOne = 2,
                                                           Stability = Stability.Beta,
                                                       }
                              };
        var informationalVersion = semanticVersion.ToLongString();

        Assert.AreEqual("1.2.0-beta2 Branch:'release-1.2' Sha:'a682956dccae752aa24597a0f5cd939f93614509'", informationalVersion);
    }
    public void Master_branch()
    {
        var versionAndBranch = new VersionAndBranch
                               {
                                   Version = new SemanticVersion
                                             {
                                                 Stability = Stability.Final,
                                                 Suffix = "1571", //ignored
                                                 PreReleasePartOne = 131231232, //ignored
                                                 PreReleasePartTwo = 131231232 //ignored
                                             }
                               };

        var nugetVersion = NugetVersionBuilder.GenerateNugetVersion(versionAndBranch);
        NuGet.SemanticVersion.Parse(nugetVersion);
        Assert.AreEqual("0.0.0", nugetVersion);
    }
    public void Master()
    {
        var semanticVersion = new VersionAndBranch
                              {
                                  BranchType = BranchType.Master,
                                  BranchName = "master",
                                  Sha = "a682956dccae752aa24597a0f5cd939f93614509",
                                  Version = new SemanticVersion
                                                       {
                                                           Major = 1,
                                                           Minor = 2,
                                                           Patch = 3,
                                                           Stability = Stability.Final,
                                                       }
                              };
        var informationalVersion = semanticVersion.ToLongString();

        Assert.AreEqual("1.2.3 Sha:'a682956dccae752aa24597a0f5cd939f93614509'", informationalVersion);
    }
    public void PullRequest()
    {
        var semanticVersion = new VersionAndBranch
                              {
                                  BranchType = BranchType.PullRequest,
                                  BranchName = "myPullRequest",
                                  Sha = "a682956dccae752aa24597a0f5cd939f93614509",
                                  Version = new SemanticVersion
                                                       {
                                                           Major = 1,
                                                           Minor = 2,
                                                           Patch = 3,
                                                           PreReleasePartOne = 3,
                                                           Stability = Stability.Unstable,
                                                       }
                              };
        var informationalVersion = semanticVersion.ToLongString();

        Assert.AreEqual("1.2.3-unstable.pull-request-3 Branch:'myPullRequest' Sha:'a682956dccae752aa24597a0f5cd939f93614509'", informationalVersion);
    }
 public void NuGet_version_should_be_padded_to_workaround_stupid_nuget_issue_with_sorting_two_digits_with_preReleaseTwo()
 {
     var versionAndBranch = new VersionAndBranch
                            {
                                BranchType = BranchType.Develop,
                                Version = new SemanticVersion
                                          {
                                              PreReleasePartOne = 40,
                                              PreReleasePartTwo = 50,
                                              Stability = Stability.Unstable
                                          }
                            };
     var nugetVersion = NugetVersionBuilder.GenerateNugetVersion(versionAndBranch);
     NuGet.SemanticVersion.Parse(nugetVersion);
     Assert.AreEqual("0.0.0-Unstable0040-0050", nugetVersion);
 }
 public void Master_branch()
 {
     var versionAndBranch = new VersionAndBranch
                            {
                                Version = new SemanticVersion
                                          {
                                              Stability = Stability.Final,
                                              Suffix = "1571", //ignored
                                              PreReleasePartOne = 131231232, //ignored
                                              PreReleasePartTwo = 131231232 //ignored
                                          }
                            };
     var tcVersion = TeamCityVersionBuilder.GenerateBuildVersion(versionAndBranch);
     Assert.AreEqual("##teamcity[buildNumber '0.0.0']", tcVersion);
 }
    public void Pull_branch()
    {
        var versionAndBranch = new VersionAndBranch
                               {
                                   BranchType = BranchType.PullRequest,
                                   Version = new SemanticVersion
                                             {
                                                 Suffix = "1571",
                                                 PreReleasePartOne = 131231232, //ignored
                                                 PreReleasePartTwo = 131231232, //ignored
                                                 Stability = Stability.Unstable
                                             }
                               };

        var nugetVersion = NugetVersionBuilder.GenerateNugetVersion(versionAndBranch);
        NuGet.SemanticVersion.Parse(nugetVersion);
        Assert.AreEqual("0.0.0-PullRequest-1571", nugetVersion);
    }
    public void Release_branch_with_preReleaseTwo()
    {
        var versionAndBranch = new VersionAndBranch
                               {
                                   BranchType = BranchType.Release,
                                   Version = new SemanticVersion
                                             {
                                                 PreReleasePartOne = 4,
                                                 PreReleasePartTwo = 8,
                                                 Stability = Stability.Beta,
                                             }
                               };

        var nugetVersion = NugetVersionBuilder.GenerateNugetVersion(versionAndBranch);
        NuGet.SemanticVersion.Parse(nugetVersion);
        Assert.AreEqual("0.0.0-Beta0004-0008", nugetVersion);
    }
 public void Pull_branch()
 {
     var versionAndBranch = new VersionAndBranch
                            {
                                BranchType = BranchType.PullRequest,
                                Version = new SemanticVersion
                                          {
                                              Suffix = "1571",
                                              PreReleasePartOne = 131231232, //ignored
                                              PreReleasePartTwo = 131231232, //ignored
                                              Stability = Stability.Unstable
                                          }
                            };
     var tcVersion = TeamCityVersionBuilder.GenerateBuildVersion(versionAndBranch);
     Assert.AreEqual("##teamcity[buildNumber '0.0.0-PullRequest-1571']", tcVersion);
 }
        void CreateTempAssemblyInfo(VersionAndBranch versionAndBranch)
        {
            var assemblyInfoBuilder = new AssemblyInfoBuilder
                                      {
                                          VersionAndBranch = versionAndBranch,
                                          SignAssembly = SignAssembly
                                      };
            var assemblyInfo = assemblyInfoBuilder.GetAssemblyInfoText();

            var tempFileName = string.Format("AssemblyInfo_{0}_{1}.cs", Path.GetFileNameWithoutExtension(ProjectFile), Path.GetRandomFileName());
            AssemblyInfoTempFilePath = Path.Combine(TempFileTracker.TempPath, tempFileName);
            File.WriteAllText(AssemblyInfoTempFilePath, assemblyInfo);
        }
 void WriteTeamCityParameters(VersionAndBranch versionAndBranch)
 {
     foreach (var buildParameters in TeamCity.GenerateBuildLogOutput(versionAndBranch))
     {
         this.LogWarning(buildParameters);
     }
 }