public void CanBumpVersions( string version, VersionBump bump, int expectedMajor, int expectedMinor, int expectedPatch, string expectedPreRelease, string expectedBuildMeta ) { var semver = _bumper.Bump( SemVer.FromString(version), bump, version ); Assert.Equal(expectedMajor, semver.Major); Assert.Equal(expectedMinor, semver.Minor); Assert.Equal(expectedPatch, semver.Patch); Assert.Equal(expectedPreRelease, semver.PreRelease); Assert.Equal(expectedBuildMeta, semver.BuildMeta); }
public VersionInfo Execute(VersionCliArgs args) { if (!args.DryRun && args.DoVcs && !_vcsTool.IsVcsToolPresent()) { throw new OperationCanceledException( $"Unable to find the vcs tool {_vcsTool.ToolName()} in your path"); } if (!args.DryRun && args.DoVcs && !_vcsTool.IsRepositoryClean()) { throw new OperationCanceledException( "You currently have uncomitted changes in your repository, please commit these and try again"); } var csProjXml = _fileDetector.FindAndLoadCsProj(args.CsProjFilePath); _fileParser.Load(csProjXml); var semVer = _bumper.Bump( SemVer.FromString(_fileParser.PackageVersion), args.VersionBump, args.SpecificVersionToApply, args.BuildMeta, args.PreReleasePrefix ); var versionString = semVer.ToSemVerVersionString(); if (!args.DryRun) // if we are not in dry run mode, then we should go ahead { _fileVersionPatcher.Load(csProjXml); _fileVersionPatcher.PatchVersionField( _fileParser.Version, versionString ); _fileVersionPatcher.Flush( _fileDetector.ResolvedCsProjFile ); if (args.DoVcs) { // Run git commands _vcsTool.Commit(_fileDetector.ResolvedCsProjFile, $"v{versionString}"); _vcsTool.Tag($"v{versionString}"); } } var theOutput = new VersionInfo { Product = new ProductOutputInfo { Name = ProductInfo.Name, Version = ProductInfo.Version }, OldVersion = _fileParser.PackageVersion, NewVersion = versionString, ProjectFile = _fileDetector.ResolvedCsProjFile, VersionStrategy = args.VersionBump.ToString().ToLowerInvariant() }; if (args.OutputFormat == OutputFormat.Json) { WriteJsonToStdout(theOutput); } else { Console.WriteLine($"Bumped {_fileDetector.ResolvedCsProjFile} to version {versionString}"); } return(theOutput); }