Esempio n. 1
0
        public static void Main(string[] args)
        {
            try
            {
                string startingPath = args[0];

                var repositoryVersionInformationLoader = new RepositoryVersionInformationLoader();

                RepositoryVersionInformation repositoryVersionInformation = repositoryVersionInformationLoader.GetRepositoryVersionInformation(startingPath);

                var calculator = new VersionCalculator();

                var version = calculator.CalculateVersion(
                    repositoryVersionInformation.LastTaggedVersion,
                    repositoryVersionInformation.AnnotationMessage,
                    repositoryVersionInformation.CommitsSinceLastTaggedVersion,
                    repositoryVersionInformation.PrereleaseOverride);

                Console.WriteLine("{");
                Console.WriteLine("\"Version\": \"" + version.Version + "\",");
                Console.WriteLine("\"NugetVersion\": \"" + version.NugetVersion + "\",");
                Console.WriteLine("\"InformationalVersion\": \"" + version.InformationalVersion + "\"");
                Console.WriteLine("}");
            }
            catch (Exception exception)
            {
                Console.WriteLine("Error occured: " + exception);
            }
        }
Esempio n. 2
0
        protected override void TransformConfiguration(Options options, Configuration config)
        {
            var calculator = new VersionCalculator();
            var version    = calculator.CalculateVersion(options);

            config.Major = version.Major;
            config.Minor = version.Minor;

            Console.WriteLine("Please enter the major and minor versions for this repository");
            Console.Write("Major: ({0}) ", version.Major);
            var input = Console.ReadLine();

            if (!string.IsNullOrEmpty(input) && int.TryParse(input, out var major))
            {
                config.Major = major;
            }

            Console.Write("Minor: ({0}) ", version.Minor);
            input = Console.ReadLine();

            if (!string.IsNullOrEmpty(input) && int.TryParse(input, out var minor))
            {
                config.Minor = minor;
            }
        }
Esempio n. 3
0
        public int Execute(Options options)
        {
            var calculator = new VersionCalculator();
            var finder     = new GitFolderFinder();

            var version = calculator.CalculateVersion(options);

            if (version == null)
            {
                return(1);
            }

            if (version.IsDirty)
            {
                Console.WriteLine("Cannot apply tag with uncommitted changes");
                return(1);
            }

            var gitFolder = finder.FindGitFolder(options.Path);

            using (var repo = new Repository(gitFolder))
            {
                repo.ApplyTag(version.SemVer);
            }

            Console.WriteLine($"Created Tag: {version.SemVer}");

            return(0);
        }
Esempio n. 4
0
        private static VersionInformation CalculateVersion(RepositoryVersionInformation repositoryVersionInformation)
        {
            var calculator = new VersionCalculator();

            var version = calculator.CalculateVersion(
                repositoryVersionInformation.LastTaggedVersion,
                repositoryVersionInformation.AnnotationMessage,
                repositoryVersionInformation.CommitsSinceLastTaggedVersion,
                repositoryVersionInformation.PrereleaseOverride);

            return(version);
        }
Esempio n. 5
0
        public int Execute(Options options)
        {
            var calculator = new VersionCalculator();
            var version    = calculator.CalculateVersion(options);

            if (version == null)
            {
                return(1);
            }

            if (string.Compare(options.Format, "json", StringComparison.OrdinalIgnoreCase) == 0)
            {
                Console.WriteLine(JsonConvert.SerializeObject(version, Formatting.Indented));
            }
            else
            {
                Console.WriteLine(version.SemVer);
            }

            return(0);
        }
Esempio n. 6
0
        public override bool Execute()
        {
            try
            {
                string startingPath = this.SolutionDirectory;

                var repositoryVersionInformationLoader = new RepositoryVersionInformationLoader();

                RepositoryVersionInformation repositoryVersionInformation = repositoryVersionInformationLoader.GetRepositoryVersionInformation(startingPath);

                this.Log.LogMessage(MessageImportance.Normal, "version pattern = " + repositoryVersionInformation.LastTaggedVersion + ", commits since tag = " + repositoryVersionInformation.CommitsSinceLastTaggedVersion);

                var calculator = new VersionCalculator();

                var version = calculator.CalculateVersion(
                    repositoryVersionInformation.LastTaggedVersion,
                    repositoryVersionInformation.AnnotationMessage,
                    repositoryVersionInformation.CommitsSinceLastTaggedVersion,
                    repositoryVersionInformation.PrereleaseOverride);

                this.Log.LogMessage(MessageImportance.Normal, "Version: " + version.Version);
                this.Log.LogMessage(MessageImportance.Normal, "NugetVersion: " + version.NugetVersion);
                this.Log.LogMessage(MessageImportance.Normal, "InformationalVersion:" + version.InformationalVersion);
                this.Log.LogMessage(MessageImportance.Normal, "PrereleaseOverride:" + repositoryVersionInformation.PrereleaseOverride);

                string versionAssemblyInfo = string.Format(
            @"
            using System;
            using System.Reflection;

            [assembly: AssemblyVersion(""{0}"")]
            [assembly: AssemblyFileVersion(""{0}"")]
            [assembly: AssemblyInformationalVersion(""{1}"")]
            ",
             version.Version,
             version.InformationalVersion);

                string tempFolder = Path.Combine(Path.GetTempPath(), "Appccelerate.VersionTask");

                if (!Directory.Exists(tempFolder))
                {
                    Directory.CreateDirectory(tempFolder);
                }

                foreach (string tempFilePath in Directory.GetFiles(tempFolder))
                {
                    try
                    {
                        // we cannot delete just all files because they might be used in other projects currently built
                        if (File.GetLastWriteTime(tempFilePath) < DateTime.Now.AddDays(-1))
                        {
                            File.Delete(tempFilePath);
                        }
                    }
                    // ReSharper disable once EmptyGeneralCatchClause
                    catch
                    {
                        // try next time
                    }
                }

                var tempFileName = string.Format("AssemblyInfo_{0}_{1}.g.cs", Path.GetFileNameWithoutExtension(this.ProjectFile), Path.GetRandomFileName());
                this.TempAssemblyInfoFilePath = Path.Combine(tempFolder, tempFileName);
                File.WriteAllText(this.TempAssemblyInfoFilePath, versionAssemblyInfo);

                TeamCity.WriteSetParameterMessage("Version", version.Version.ToString(), this.WriteToLog);
                TeamCity.WriteSetParameterMessage("InformationalVersion", version.InformationalVersion, this.WriteToLog);
                TeamCity.WriteSetParameterMessage("NugetVersion", version.NugetVersion, this.WriteToLog);

                return true;
            }
            catch (Exception exception)
            {
                this.Log.LogErrorFromException(exception);

                return false;
            }
        }