Beispiel #1
0
 public static List <KeyValuePair <string, BranchConfig> > GetReleaseBranchConfig(this Config configuration)
 {
     return(configuration.Branches
            .Where(b => b.Value.IsReleaseBranch == true)
            .ToList());
 }
Beispiel #2
0
        public static EffectiveConfiguration CalculateEffectiveConfiguration(this Config configuration, BranchConfig currentBranchConfig)
        {
            var name = currentBranchConfig.Name;

            if (!currentBranchConfig.VersioningMode.HasValue)
            {
                throw new Exception($"Configuration value for 'Versioning mode' for branch {name} has no value. (this should not happen, please report an issue)");
            }
            if (!currentBranchConfig.Increment.HasValue)
            {
                throw new Exception($"Configuration value for 'Increment' for branch {name} has no value. (this should not happen, please report an issue)");
            }
            if (!currentBranchConfig.PreventIncrementOfMergedBranchVersion.HasValue)
            {
                throw new Exception($"Configuration value for 'PreventIncrementOfMergedBranchVersion' for branch {name} has no value. (this should not happen, please report an issue)");
            }
            if (!currentBranchConfig.TrackMergeTarget.HasValue)
            {
                throw new Exception($"Configuration value for 'TrackMergeTarget' for branch {name} has no value. (this should not happen, please report an issue)");
            }
            if (!currentBranchConfig.TracksReleaseBranches.HasValue)
            {
                throw new Exception($"Configuration value for 'TracksReleaseBranches' for branch {name} has no value. (this should not happen, please report an issue)");
            }
            if (!currentBranchConfig.IsReleaseBranch.HasValue)
            {
                throw new Exception($"Configuration value for 'IsReleaseBranch' for branch {name} has no value. (this should not happen, please report an issue)");
            }

            if (!configuration.AssemblyVersioningScheme.HasValue)
            {
                throw new Exception("Configuration value for 'AssemblyVersioningScheme' has no value. (this should not happen, please report an issue)");
            }
            if (!configuration.AssemblyFileVersioningScheme.HasValue)
            {
                throw new Exception("Configuration value for 'AssemblyFileVersioningScheme' has no value. (this should not happen, please report an issue)");
            }
            if (!configuration.CommitMessageIncrementing.HasValue)
            {
                throw new Exception("Configuration value for 'CommitMessageIncrementing' has no value. (this should not happen, please report an issue)");
            }
            if (!configuration.LegacySemVerPadding.HasValue)
            {
                throw new Exception("Configuration value for 'LegacySemVerPadding' has no value. (this should not happen, please report an issue)");
            }
            if (!configuration.BuildMetaDataPadding.HasValue)
            {
                throw new Exception("Configuration value for 'BuildMetaDataPadding' has no value. (this should not happen, please report an issue)");
            }
            if (!configuration.CommitsSinceVersionSourcePadding.HasValue)
            {
                throw new Exception("Configuration value for 'CommitsSinceVersionSourcePadding' has no value. (this should not happen, please report an issue)");
            }

            var versioningMode    = currentBranchConfig.VersioningMode.Value;
            var tag               = currentBranchConfig.Tag;
            var tagNumberPattern  = currentBranchConfig.TagNumberPattern;
            var incrementStrategy = currentBranchConfig.Increment.Value;
            var preventIncrementForMergedBranchVersion = currentBranchConfig.PreventIncrementOfMergedBranchVersion.Value;
            var trackMergeTarget = currentBranchConfig.TrackMergeTarget.Value;
            var preReleaseWeight = currentBranchConfig.PreReleaseWeight ?? 0;

            var nextVersion = configuration.NextVersion;
            var assemblyVersioningScheme     = configuration.AssemblyVersioningScheme.Value;
            var assemblyFileVersioningScheme = configuration.AssemblyFileVersioningScheme.Value;
            var assemblyInformationalFormat  = configuration.AssemblyInformationalFormat;
            var assemblyVersioningFormat     = configuration.AssemblyVersioningFormat;
            var assemblyFileVersioningFormat = configuration.AssemblyFileVersioningFormat;
            var gitTagPrefix        = configuration.TagPrefix;
            var majorMessage        = configuration.MajorVersionBumpMessage;
            var minorMessage        = configuration.MinorVersionBumpMessage;
            var patchMessage        = configuration.PatchVersionBumpMessage;
            var noBumpMessage       = configuration.NoBumpMessage;
            var commitDateFormat    = configuration.CommitDateFormat;
            var updateBuildNumber   = configuration.UpdateBuildNumber ?? true;
            var tagPreReleaseWeight = configuration.TagPreReleaseWeight ?? DefaultTagPreReleaseWeight;

            var commitMessageVersionBump = currentBranchConfig.CommitMessageIncrementing ?? configuration.CommitMessageIncrementing.Value;

            return(new EffectiveConfiguration(
                       assemblyVersioningScheme, assemblyFileVersioningScheme, assemblyInformationalFormat, assemblyVersioningFormat, assemblyFileVersioningFormat, versioningMode, gitTagPrefix,
                       tag, nextVersion, incrementStrategy,
                       currentBranchConfig.Regex,
                       preventIncrementForMergedBranchVersion,
                       tagNumberPattern, configuration.ContinuousDeploymentFallbackTag,
                       trackMergeTarget,
                       majorMessage, minorMessage, patchMessage, noBumpMessage,
                       commitMessageVersionBump,
                       configuration.LegacySemVerPadding.Value,
                       configuration.BuildMetaDataPadding.Value,
                       configuration.CommitsSinceVersionSourcePadding.Value,
                       configuration.Ignore.ToFilters(),
                       currentBranchConfig.TracksReleaseBranches.Value,
                       currentBranchConfig.IsReleaseBranch.Value,
                       commitDateFormat,
                       updateBuildNumber,
                       preReleaseWeight,
                       tagPreReleaseWeight));
        }
Beispiel #3
0
        public static void Reset(this Config config)
        {
            config.AssemblyVersioningScheme ??= AssemblyVersioningScheme.MajorMinorPatch;
            config.AssemblyFileVersioningScheme ??= AssemblyFileVersioningScheme.MajorMinorPatch;
            config.AssemblyInformationalFormat  = config.AssemblyInformationalFormat;
            config.AssemblyVersioningFormat     = config.AssemblyVersioningFormat;
            config.AssemblyFileVersioningFormat = config.AssemblyFileVersioningFormat;
            config.TagPrefix ??= Config.DefaultTagPrefix;
            config.VersioningMode ??= VersioningMode.ContinuousDelivery;
            config.ContinuousDeploymentFallbackTag ??= "ci";
            config.MajorVersionBumpMessage ??= IncrementStrategyFinder.DefaultMajorPattern;
            config.MinorVersionBumpMessage ??= IncrementStrategyFinder.DefaultMinorPattern;
            config.PatchVersionBumpMessage ??= IncrementStrategyFinder.DefaultPatchPattern;
            config.NoBumpMessage ??= IncrementStrategyFinder.DefaultNoBumpPattern;
            config.CommitMessageIncrementing ??= CommitMessageIncrementMode.Enabled;
            config.LegacySemVerPadding ??= 4;
            config.BuildMetaDataPadding ??= 4;
            config.CommitsSinceVersionSourcePadding ??= 4;
            config.CommitDateFormat ??= "yyyy-MM-dd";
            config.UpdateBuildNumber ??= true;
            config.TagPreReleaseWeight ??= DefaultTagPreReleaseWeight;

            var configBranches = config.Branches.ToList();

            ApplyBranchDefaults(config, GetOrCreateBranchDefaults(config, Config.DevelopBranchKey), Config.DevelopBranchRegex,
                                new List <string>(),
                                defaultTag: "alpha",
                                defaultIncrementStrategy: IncrementStrategy.Minor,
                                defaultVersioningMode: config.VersioningMode == VersioningMode.Mainline ? VersioningMode.Mainline : VersioningMode.ContinuousDeployment,
                                defaultTrackMergeTarget: true,
                                tracksReleaseBranches: true);
            ApplyBranchDefaults(config, GetOrCreateBranchDefaults(config, Config.MasterBranchKey), Config.MasterBranchRegex,
                                new List <string>
            {
                "develop", "release"
            },
                                defaultTag: string.Empty,
                                defaultPreventIncrement: true,
                                defaultIncrementStrategy: IncrementStrategy.Patch,
                                isMainline: true);
            ApplyBranchDefaults(config, GetOrCreateBranchDefaults(config, Config.ReleaseBranchKey), Config.ReleaseBranchRegex,
                                new List <string>
            {
                "develop", "master", "support", "release"
            },
                                defaultTag: "beta",
                                defaultPreventIncrement: true,
                                defaultIncrementStrategy: IncrementStrategy.None,
                                isReleaseBranch: true);
            ApplyBranchDefaults(config, GetOrCreateBranchDefaults(config, Config.FeatureBranchKey), Config.FeatureBranchRegex,
                                new List <string>
            {
                "develop", "master", "release", "feature", "support", "hotfix"
            },
                                defaultIncrementStrategy: IncrementStrategy.Inherit);
            ApplyBranchDefaults(config, GetOrCreateBranchDefaults(config, Config.PullRequestBranchKey), Config.PullRequestRegex,
                                new List <string>
            {
                "develop", "master", "release", "feature", "support", "hotfix"
            },
                                defaultTag: "PullRequest",
                                defaultTagNumberPattern: @"[/-](?<number>\d+)",
                                defaultIncrementStrategy: IncrementStrategy.Inherit);
            ApplyBranchDefaults(config, GetOrCreateBranchDefaults(config, Config.HotfixBranchKey), Config.HotfixBranchRegex,
                                new List <string>
            {
                "develop", "master", "support"
            },
                                defaultTag: "beta",
                                defaultIncrementStrategy: IncrementStrategy.Patch);
            ApplyBranchDefaults(config, GetOrCreateBranchDefaults(config, Config.SupportBranchKey), Config.SupportBranchRegex,
                                new List <string>
            {
                "master"
            },
                                defaultTag: string.Empty,
                                defaultPreventIncrement: true,
                                defaultIncrementStrategy: IncrementStrategy.Patch,
                                isMainline: true);

            // Any user defined branches should have other values defaulted after known branches filled in.
            // This allows users to override any of the value.
            foreach (var branchConfig in configBranches)
            {
                var regex = branchConfig.Value.Regex;
                if (regex == null)
                {
                    throw new ConfigurationException($"Branch configuration '{branchConfig.Key}' is missing required configuration 'regex'{System.Environment.NewLine}" +
                                                     "See https://gitversion.net/docs/configuration/ for more info");
                }

                var sourceBranches = branchConfig.Value.SourceBranches;
                if (sourceBranches == null)
                {
                    throw new ConfigurationException($"Branch configuration '{branchConfig.Key}' is missing required configuration 'source-branches'{System.Environment.NewLine}" +
                                                     "See https://gitversion.net/docs/configuration/ for more info");
                }

                ApplyBranchDefaults(config, branchConfig.Value, regex, sourceBranches);
            }

            // This is a second pass to add additional sources, it has to be another pass to prevent ordering issues
            foreach (var branchConfig in configBranches)
            {
                if (branchConfig.Value.IsSourceBranchFor == null)
                {
                    continue;
                }
                foreach (var isSourceBranch in branchConfig.Value.IsSourceBranchFor)
                {
                    config.Branches[isSourceBranch].SourceBranches.Add(branchConfig.Key);
                }
            }
        }
Beispiel #4
0
 public static bool IsReleaseBranch(this Config config, string branchName) => config.GetConfigForBranch(branchName)?.IsReleaseBranch ?? false;
Beispiel #5
0
 public static Config ApplyDefaults(this Config config)
 {
     config.Reset();
     return(config);
 }