Ejemplo n.º 1
0
        /// <summary>
        /// Gets the <see cref="BranchConfig"/> for the current commit.
        /// </summary>
        public BranchConfig GetBranchConfiguration(IBranch targetBranch, ICommit currentCommit, Config configuration, IList <IBranch> excludedInheritBranches = null)
        {
            var matchingBranches = configuration.GetConfigForBranch(targetBranch.Name.WithoutRemote);

            if (matchingBranches == null)
            {
                log.Info($"No branch configuration found for branch {targetBranch}, falling back to default configuration");

                matchingBranches = BranchConfig.CreateDefaultBranchConfig(FallbackConfigName)
                                   .Apply(new BranchConfig
                {
                    Regex          = "",
                    VersioningMode = configuration.VersioningMode,
                    Increment      = configuration.Increment ?? IncrementStrategy.Inherit,
                });
            }

            if (matchingBranches.Increment == IncrementStrategy.Inherit)
            {
                matchingBranches = InheritBranchConfiguration(targetBranch, matchingBranches, currentCommit, configuration, excludedInheritBranches);
                if (matchingBranches.Name.IsEquivalentTo(FallbackConfigName) && matchingBranches.Increment == IncrementStrategy.Inherit)
                {
                    // We tried, and failed to inherit, just fall back to patch
                    matchingBranches.Increment = IncrementStrategy.Patch;
                }
            }

            return(matchingBranches);
        }
Ejemplo n.º 2
0
        private static void ApplyBranchOverrides(Config targetConfig, Config overrideConfig)
        {
            if (overrideConfig.Branches != null && overrideConfig.Branches.Count > 0)
            {
                // We can't just add new configs to the targetConfig.Branches, and have to create a new dictionary.
                // The reason is that GitVersion 5.3.x (and earlier) merges default configs into overrides. The new approach is opposite: we merge overrides into default config.
                // The important difference of these approaches is the order of branches in a dictionary (we should not rely on Dictionary's implementation details, but we already did that):
                // Old approach: { new-branch-1, new-branch-2, default-branch-1, default-branch-2, ... }
                // New approach: { default-branch-1, default-branch-2, ..., new-branch-1, new-branch-2 }
                // In case when several branch configurations match the current branch (by regex), we choose the first one.
                // So we have to add new branches to the beginning of a dictionary to preserve 5.3.x behavior.

                var newBranches = new Dictionary <string, BranchConfig>();

                var targetConfigBranches = targetConfig.Branches;

                foreach (var(key, source) in overrideConfig.Branches)
                {
                    if (!targetConfigBranches.TryGetValue(key, out var target))
                    {
                        target = BranchConfig.CreateDefaultBranchConfig(key);
                    }

                    source.MergeTo(target);
                    newBranches[key] = target;
                }

                foreach (var(key, branchConfig) in targetConfigBranches)
                {
                    if (!newBranches.ContainsKey(key))
                    {
                        newBranches[key] = branchConfig;
                    }
                }

                targetConfig.Branches = newBranches;
            }
        }
Ejemplo n.º 3
0
        private static Config CreateDefaultConfiguration()
        {
            var config = new Config
            {
                AssemblyVersioningScheme     = AssemblyVersioningScheme.MajorMinorPatch,
                AssemblyFileVersioningScheme = AssemblyFileVersioningScheme.MajorMinorPatch,
                TagPrefix      = Config.DefaultTagPrefix,
                VersioningMode = VersioningMode.ContinuousDelivery,
                ContinuousDeploymentFallbackTag = "ci",
                MajorVersionBumpMessage         = IncrementStrategyFinder.DefaultMajorPattern,
                MinorVersionBumpMessage         = IncrementStrategyFinder.DefaultMinorPattern,
                PatchVersionBumpMessage         = IncrementStrategyFinder.DefaultPatchPattern,
                NoBumpMessage                    = IncrementStrategyFinder.DefaultNoBumpPattern,
                CommitMessageIncrementing        = CommitMessageIncrementMode.Enabled,
                LegacySemVerPadding              = 4,
                BuildMetaDataPadding             = 4,
                CommitsSinceVersionSourcePadding = 4,
                CommitDateFormat                 = "yyyy-MM-dd",
                UpdateBuildNumber                = true,
                TagPreReleaseWeight              = DefaultTagPreReleaseWeight
            };

            AddBranchConfig(Config.DevelopBranchKey,
                            new BranchConfig
            {
                Regex                 = Config.DevelopBranchRegex,
                SourceBranches        = new HashSet <string>(),
                Tag                   = "alpha",
                Increment             = IncrementStrategy.Minor,
                TrackMergeTarget      = true,
                TracksReleaseBranches = true,
                PreReleaseWeight      = 0,
            });

            AddBranchConfig(Config.MasterBranchKey,
                            new BranchConfig
            {
                Regex          = Config.MasterBranchRegex,
                SourceBranches = new HashSet <string> {
                    Config.DevelopBranchKey, Config.ReleaseBranchKey
                },
                Tag = string.Empty,
                PreventIncrementOfMergedBranchVersion = true,
                Increment        = IncrementStrategy.Patch,
                IsMainline       = true,
                PreReleaseWeight = 55000,
            });

            AddBranchConfig(Config.ReleaseBranchKey,
                            new BranchConfig
            {
                Regex          = Config.ReleaseBranchRegex,
                SourceBranches = new HashSet <string> {
                    Config.DevelopBranchKey, Config.MasterBranchKey, Config.SupportBranchKey, Config.ReleaseBranchKey
                },
                Tag = "beta",
                PreventIncrementOfMergedBranchVersion = true,
                Increment        = IncrementStrategy.None,
                IsReleaseBranch  = true,
                PreReleaseWeight = 30000,
            });

            AddBranchConfig(Config.FeatureBranchKey,
                            new BranchConfig
            {
                Regex          = Config.FeatureBranchRegex,
                SourceBranches = new HashSet <string> {
                    Config.DevelopBranchKey, Config.MasterBranchKey, Config.ReleaseBranchKey, Config.FeatureBranchKey, Config.SupportBranchKey, Config.HotfixBranchKey
                },
                Increment        = IncrementStrategy.Inherit,
                PreReleaseWeight = 30000,
            });

            AddBranchConfig(Config.PullRequestBranchKey,
                            new BranchConfig
            {
                Regex          = Config.PullRequestRegex,
                SourceBranches = new HashSet <string> {
                    Config.DevelopBranchKey, Config.MasterBranchKey, Config.ReleaseBranchKey, Config.FeatureBranchKey, Config.SupportBranchKey, Config.HotfixBranchKey
                },
                Tag = "PullRequest",
                TagNumberPattern = @"[/-](?<number>\d+)",
                Increment        = IncrementStrategy.Inherit,
                PreReleaseWeight = 30000,
            });

            AddBranchConfig(Config.HotfixBranchKey,
                            new BranchConfig
            {
                Regex          = Config.HotfixBranchRegex,
                SourceBranches = new HashSet <string> {
                    Config.DevelopBranchKey, Config.MasterBranchKey, Config.SupportBranchKey
                },
                Tag              = "beta",
                Increment        = IncrementStrategy.Patch,
                PreReleaseWeight = 30000,
            });

            AddBranchConfig(Config.SupportBranchKey,
                            new BranchConfig
            {
                Regex          = Config.SupportBranchRegex,
                SourceBranches = new HashSet <string> {
                    Config.MasterBranchKey
                },
                Tag = string.Empty,
                PreventIncrementOfMergedBranchVersion = true,
                Increment        = IncrementStrategy.Patch,
                IsMainline       = true,
                PreReleaseWeight = 55000,
            });

            return(config);

            void AddBranchConfig(string name, BranchConfig overrides)
            {
                config.Branches[name] = BranchConfig.CreateDefaultBranchConfig(name).Apply(overrides);
            }
        }