public void CommitDateFormatTest(string format, string expectedOutcome) { var date = new DateTime(2017, 10, 6); var formatValues = new SemanticVersionFormatValues( new SemanticVersion { BuildMetaData = new SemanticVersionBuildMetaData("950d2f830f5a2af12a6779a48d20dcbb02351f25", 0, "master", "3139d4eeb044f46057693473eacc2655b3b27e7d", "3139d4eeb", new DateTimeOffset(date, TimeSpan.Zero)), // assume time zone is UTC }, new EffectiveConfiguration( AssemblyVersioningScheme.MajorMinorPatch, AssemblyFileVersioningScheme.MajorMinorPatch, "", "", "", VersioningMode.ContinuousDelivery, "", "", "", IncrementStrategy.Inherit, "", true, "", "", false, "", "", "", "", CommitMessageIncrementMode.Enabled, 4, 4, 4, Enumerable.Empty <IVersionFilter>(), false, true, format, 0) ); Assert.That(formatValues.CommitDate, Is.EqualTo(expectedOutcome)); }
public void CommitDateFormatTest(string format, string expectedOutcome) { var date = new DateTime(2017, 10, 6); var semanticVersionBuildMetaData = new SemanticVersionBuildMetaData( "950d2f830f5a2af12a6779a48d20dcbb02351f25", 0, MainBranch, "3139d4eeb044f46057693473eacc2655b3b27e7d", "3139d4eeb", new DateTimeOffset(date, TimeSpan.Zero), 0); var semanticVersion = new SemanticVersion { BuildMetaData = semanticVersionBuildMetaData // assume time zone is UTC }; var configuration = new TestEffectiveConfiguration(commitDateFormat: format); var formatValues = new SemanticVersionFormatValues(semanticVersion, configuration); Assert.That(formatValues.CommitDate, Is.EqualTo(expectedOutcome)); }
public VersionVariables GetVariablesFor(SemanticVersion semanticVersion, EffectiveConfiguration config, bool isCurrentCommitTagged) { var isContinuousDeploymentMode = config.VersioningMode == VersioningMode.ContinuousDeployment && !isCurrentCommitTagged; if (isContinuousDeploymentMode) { semanticVersion = new SemanticVersion(semanticVersion); // Continuous Deployment always requires a pre-release tag unless the commit is tagged if (!semanticVersion.PreReleaseTag.HasTag()) { semanticVersion.PreReleaseTag.Name = nextVersionCalculator.GetBranchSpecificTag(config, semanticVersion.BuildMetaData.Branch, null); if (string.IsNullOrEmpty(semanticVersion.PreReleaseTag.Name)) { semanticVersion.PreReleaseTag.Name = config.ContinuousDeploymentFallbackTag; } } } // Evaluate tag number pattern and append to prerelease tag, preserving build metadata var appendTagNumberPattern = !string.IsNullOrEmpty(config.TagNumberPattern) && semanticVersion.PreReleaseTag.HasTag(); if (appendTagNumberPattern) { var match = Regex.Match(semanticVersion.BuildMetaData.Branch, config.TagNumberPattern); var numberGroup = match.Groups["number"]; if (numberGroup.Success) { semanticVersion.PreReleaseTag.Name += numberGroup.Value.PadLeft(config.BuildMetaDataPadding, '0'); } } if (isContinuousDeploymentMode || appendTagNumberPattern || config.VersioningMode == VersioningMode.Mainline) { PromoteNumberOfCommitsToTagNumber(semanticVersion); } var semverFormatValues = new SemanticVersionFormatValues(semanticVersion, config); var informationalVersion = CheckAndFormatString(config.AssemblyInformationalFormat, semverFormatValues, environment, semverFormatValues.InformationalVersion, "AssemblyInformationalVersion"); var assemblyFileSemVer = CheckAndFormatString(config.AssemblyFileVersioningFormat, semverFormatValues, environment, semverFormatValues.AssemblyFileSemVer, "AssemblyFileVersioningFormat"); var assemblySemVer = CheckAndFormatString(config.AssemblyVersioningFormat, semverFormatValues, environment, semverFormatValues.AssemblySemVer, "AssemblyVersioningFormat"); var variables = new VersionVariables( semverFormatValues.Major, semverFormatValues.Minor, semverFormatValues.Patch, semverFormatValues.BuildMetaData, semverFormatValues.BuildMetaDataPadded, semverFormatValues.FullBuildMetaData, semverFormatValues.BranchName, semverFormatValues.EscapedBranchName, semverFormatValues.Sha, semverFormatValues.ShortSha, semverFormatValues.MajorMinorPatch, semverFormatValues.SemVer, semverFormatValues.LegacySemVer, semverFormatValues.LegacySemVerPadded, semverFormatValues.FullSemVer, assemblySemVer, assemblyFileSemVer, semverFormatValues.PreReleaseTag, semverFormatValues.PreReleaseTagWithDash, semverFormatValues.PreReleaseLabel, semverFormatValues.PreReleaseNumber, semverFormatValues.WeightedPreReleaseNumber, informationalVersion, semverFormatValues.CommitDate, semverFormatValues.NuGetVersion, semverFormatValues.NuGetVersionV2, semverFormatValues.NuGetPreReleaseTag, semverFormatValues.NuGetPreReleaseTagV2, semverFormatValues.VersionSourceSha, semverFormatValues.CommitsSinceVersionSource, semverFormatValues.CommitsSinceVersionSourcePadded); return(variables); }