/// <summary> /// Entry point for SimpleVersion invocation. /// </summary> /// <param name="args">The array of arguments.</param> /// <returns>0 if success, otherwise an error exit code.</returns> public static int Main(string[] args) { var exitCode = 0; try { var path = System.IO.Directory.GetCurrentDirectory(); if (args.Length > 0) { path = args[0]; } var result = VersionCalculator .Default() .GetResult(path); Console.Out.WriteLine(JsonConvert.SerializeObject(result, Formatting.Indented)); } #pragma warning disable CA1031 // Do not catch general exception types catch (Exception ex) { Console.Error.WriteLine($"[Error] {ex.Message}"); exitCode = -1; } #pragma warning restore CA1031 // Do not catch general exception types return(exitCode); }
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); } }
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); }
/// <summary> /// Entry point for SimpleVersion invocation. /// </summary> /// <param name="args">The array of arguments.</param> /// <returns>0 if success, otherwise an error exit code.</returns> public static int Main(string[] args) { var exitCode = 0; try { // TODO: arguments and options var path = System.IO.Directory.GetCurrentDirectory(); if (args?.Length > 0) { path = args[0]; } var calculator = new VersionCalculator(path); calculator.WriteResult(Console.Out); } #pragma warning disable CA1031 // Do not catch general exception types catch (Exception ex) { Console.Error.WriteLine($"[Error] {ex.Message}"); exitCode = -1; } #pragma warning restore CA1031 // Do not catch general exception types return(exitCode); }
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; } }
public async Task NoCommitHasMinVersionAlpha1() { var repo = new MockRepoInspector(Array.Empty <MockRepoCommit>()); var semver = await VersionCalculator.FromRepository(repo, new() { QueryRemoteTags = true }); semver.Should().Be(new SemVer(0, 1, 0, "alpha.1")); }
public void ThrowsInvalidOperationException_WhenVersionPatternWithoutPlaceholderAndCommitsSinceVersionTaggedCommitGreaterZero() { const string VersionPattern = "1.2.3.0"; Action action = () => this.testee.CalculateVersion(VersionPattern, null, 1, null); action.ShouldThrow <InvalidOperationException>() .And.Message.Should().Be(VersionCalculator.FormatCannotVersionDueToMissingCommitsCountingPlaceholderExceptionMessage(VersionPattern)); }
public void NextVersionWithInvalidAutoIncrementThrows() { var opts = new VersionCalculationOptions() { AutoIncrement = VersionPart.None, }; Assert.Throws <InvalidOperationException>(() => VersionCalculator.NextVersion(new SemVer(1, 0, 0), opts)); }
private static VersionInformation CalculateVersion(RepositoryVersionInformation repositoryVersionInformation) { var calculator = new VersionCalculator(); var version = calculator.CalculateVersion( repositoryVersionInformation.LastTaggedVersion, repositoryVersionInformation.AnnotationMessage, repositoryVersionInformation.CommitsSinceLastTaggedVersion, repositoryVersionInformation.PrereleaseOverride); return(version); }
public void NextVersion(string versionStr, VersionPart part, string expectedNextStr) { var version = SemVer.Parse(versionStr); var expectedNext = SemVer.Parse(expectedNextStr); var opts = new VersionCalculationOptions() { AutoIncrement = part, }; var actualNext = VersionCalculator.NextVersion(version, opts); actualNext.Should().Be(expectedNext); }
public static VersionResult SimpleVersion( this ICakeContext context, string path = null) { if (string.IsNullOrWhiteSpace(path)) { path = context.Environment.WorkingDirectory.FullPath; } return(VersionCalculator .Default() .GetResult(path)); }
public void CheckVersionBumps(string?versionStr, string?minVer, int height, string resultStr) { var options = new VersionCalculationOptions() { MinimumVersion = SemVer.Parse(minVer ?? "0.1.0"), }; var version = versionStr is null ? (SemVer?)null: SemVer.Parse(versionStr); var result = SemVer.Parse(resultStr); var gotVersion = VersionCalculator.FromTagInfomation(version, options, height); gotVersion.Should().Be(result); gotVersion.ToString().Should().Be(resultStr); }
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); }
private static Model.VersionResult GetResult(RepositoryFixtureBase repo) => VersionCalculator.Default().GetResult(repo.RepositoryPath);
public VersionCalculatorFacts() { this.testee = new VersionCalculator(); }
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; } }
private async Task <bool> ExecuteAsync() { var log = new MsBuildLogger(Log) { Verbosity = DecodeVerbosity(Verbosity, nameof(Verbosity)), }; var commandRunner = new MsBuildCommandRunner( new SystemCommandRunner(), Log); var opts = new VersionCalculationOptions(); { FilterTags = FilterTags.Trim(); bool disableTagPrefix = bool.TryParse(DisableTagPrefix, out bool parsedBool) && parsedBool; if (disableTagPrefix) { if (!string.IsNullOrWhiteSpace(TagPrefix)) { throw new MsBuildException("TagPrefix cannot be set with DisablePrefix."); } opts.TagPrefix = ""; } else if (!string.IsNullOrWhiteSpace(TagPrefix)) { opts.TagPrefix = TagPrefix; } if (!string.IsNullOrWhiteSpace(DefaultPrereleasePhase)) { opts.DefaultPrereleasePhase = DefaultPrereleasePhase; } if (!string.IsNullOrWhiteSpace(MinimumVersion)) { opts.MinimumVersion = DecodeVersion( MinimumVersion, nameof(MinimumVersion)); } if (!string.IsNullOrWhiteSpace(PrereleaseBaseHeight)) { opts.PrereleaseBaseHeight = DecodeInt( PrereleaseBaseHeight, nameof(PrereleaseBaseHeight)); } if (!string.IsNullOrWhiteSpace(VersionOverride)) { opts.VersionOverride = DecodeVersion( VersionOverride, nameof(VersionOverride)); } if (!string.IsNullOrWhiteSpace(BuildMetadata)) { opts.BuildMetadata = BuildMetadata; } if (!string.IsNullOrWhiteSpace(AutoIncrement)) { opts.AutoIncrement = DecodeVersionPart( AutoIncrement, nameof(AutoIncrement)); } } var version = opts.VersionOverride ?? new SemVer(); if (opts.VersionOverride is null) { var repo = await GitRepoInspector.FromPath(ProjectDirectory, log, commandRunner); ITagFilter?tagFilter = null; if (!string.IsNullOrWhiteSpace(FilterTags)) { tagFilter = new CommandTagFilter(commandRunner, log, FilterTags, ProjectDirectory); } version = await VersionCalculator.FromRepository(repo, opts, log, tagFilter); } Version = version.ToString(); VersionMajor = version.Major.ToString(CultureInfo.InvariantCulture); VersionMinor = version.Minor.ToString(CultureInfo.InvariantCulture); VersionPatch = version.Patch.ToString(CultureInfo.InvariantCulture); VersionPrerelease = version.Prerelease ?? string.Empty; VersionBuildMetadata = version.BuildMetadata ?? string.Empty; return(true); }
public VersionCalculatorFixture() { _sut = new VersionCalculator(); }