Пример #1
0
        public void Execute()
        {
            log.Info($"Running on {(RunningOnUnix ? "Unix" : "Windows")}.");

            var variables = gitVersionCalculator.CalculateVersionVariables();

            switch (arguments.Output)
            {
            case OutputType.BuildServer:
            {
                var buildServer = buildServerResolver.Resolve();
                buildServer?.WriteIntegration(Console.WriteLine, variables);

                break;
            }

            case OutputType.Json:
                switch (arguments.ShowVariable)
                {
                case null:
                    Console.WriteLine(JsonOutputFormatter.ToJson(variables));
                    break;

                default:
                    if (!variables.TryGetValue(arguments.ShowVariable, out var part))
                    {
                        throw new WarningException($"'{arguments.ShowVariable}' variable does not exist");
                    }
                    Console.WriteLine(part);
                    break;
                }

                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            if (arguments.UpdateWixVersionFile)
            {
                using var wixVersionFileUpdater = new WixVersionFileUpdater(arguments.TargetPath, variables, fileSystem, log);
                wixVersionFileUpdater.Update();
            }

            using var assemblyInfoUpdater = new AssemblyInfoFileUpdater(arguments.UpdateAssemblyInfoFileName, arguments.TargetPath, variables, fileSystem, log, arguments.EnsureAssemblyInfo);
            if (arguments.UpdateAssemblyInfo)
            {
                assemblyInfoUpdater.Update();
            }

            var execRun    = RunExecCommandIfNeeded(arguments, arguments.TargetPath, variables, log);
            var msbuildRun = RunMsBuildIfNeeded(arguments, arguments.TargetPath, variables, log);

            if (!execRun && !msbuildRun)
            {
                assemblyInfoUpdater.CommitChanges();
                //TODO Put warning back
                //if (!context.CurrentBuildServer.IsRunningInBuildAgent())
                //{
                //    Console.WriteLine("WARNING: Not running in build server and /ProjectFile or /Exec arguments not passed");
                //    Console.WriteLine();
                //    Console.WriteLine("Run GitVersion.exe /? for help");
                //}
            }
        }
Пример #2
0
        public static void Run(Arguments arguments, IFileSystem fileSystem)
        {
            Logger.WriteInfo(string.Format("Running on {0}.", runningOnMono ? "Mono" : "Windows"));

            var noFetch                   = arguments.NoFetch;
            var authentication            = arguments.Authentication;
            var targetPath                = arguments.TargetPath;
            var targetUrl                 = arguments.TargetUrl;
            var dynamicRepositoryLocation = arguments.DynamicRepositoryLocation;
            var targetBranch              = arguments.TargetBranch;
            var commitId                  = arguments.CommitId;
            var overrideConfig            = arguments.HasOverrideConfig ? arguments.OverrideConfig : null;
            var noCache                   = arguments.NoCache;
            var pathFilter                = arguments.PathFilter;

            var executeCore = new ExecuteCore(fileSystem);
            var variables   = executeCore.ExecuteGitVersion(targetUrl, dynamicRepositoryLocation, authentication, targetBranch, noFetch, targetPath, commitId, overrideConfig, noCache, pathFilter);

            if (arguments.Output == OutputType.BuildServer)
            {
                foreach (var buildServer in BuildServerList.GetApplicableBuildServers())
                {
                    buildServer.WriteIntegration(Console.WriteLine, variables);
                }
            }

            if (arguments.Output == OutputType.Json)
            {
                switch (arguments.ShowVariable)
                {
                case null:
                    Console.WriteLine(JsonOutputFormatter.ToJson(variables));
                    break;

                default:
                    string part;
                    if (!variables.TryGetValue(arguments.ShowVariable, out part))
                    {
                        throw new WarningException($"'{arguments.ShowVariable}' variable does not exist");
                    }
                    Console.WriteLine(part);
                    break;
                }
            }

            using (var assemblyInfoUpdater = new AssemblyInfoFileUpdater(arguments.UpdateAssemblyInfoFileName, targetPath, variables, fileSystem, arguments.EnsureAssemblyInfo))
            {
                if (arguments.UpdateAssemblyInfo)
                {
                    assemblyInfoUpdater.Update();
                }
                var execRun    = false;
                var msbuildRun = false;
#if NETDESKTOP
                execRun    = RunExecCommandIfNeeded(arguments, targetPath, variables);
                msbuildRun = RunMsBuildIfNeeded(arguments, targetPath, variables);
#endif
                if (!execRun && !msbuildRun)
                {
                    assemblyInfoUpdater.CommitChanges();
                    //TODO Put warning back
                    //if (!context.CurrentBuildServer.IsRunningInBuildAgent())
                    //{
                    //    Console.WriteLine("WARNING: Not running in build server and /ProjectFile or /Exec arguments not passed");
                    //    Console.WriteLine();
                    //    Console.WriteLine("Run GitVersion.exe /? for help");
                    //}
                }
            }
        }
Пример #3
0
        public void Execute(Arguments arguments, IFileSystem fileSystem, IEnvironment environment, ILog log, IConfigFileLocator configFileLocator)
        {
            log.Info($"Running on {(runningOnUnix ? "Unix" : "Windows")}.");

            var noFetch                   = arguments.NoFetch;
            var authentication            = arguments.Authentication;
            var targetPath                = arguments.TargetPath;
            var targetUrl                 = arguments.TargetUrl;
            var dynamicRepositoryLocation = arguments.DynamicRepositoryLocation;
            var targetBranch              = arguments.TargetBranch;
            var commitId                  = arguments.CommitId;
            var overrideConfig            = arguments.HasOverrideConfig ? arguments.OverrideConfig : null;
            var noCache                   = arguments.NoCache;
            var noNormalize               = arguments.NoNormalize;

            var executeCore = new ExecuteCore(fileSystem, environment, log, configFileLocator);
            var variables   = executeCore.ExecuteGitVersion(targetUrl, dynamicRepositoryLocation, authentication, targetBranch, noFetch, targetPath, commitId, overrideConfig, noCache, noNormalize);

            switch (arguments.Output)
            {
            case OutputType.BuildServer:
            {
                BuildServerList.Init(environment, log);
                foreach (var buildServer in BuildServerList.GetApplicableBuildServers(log))
                {
                    buildServer.WriteIntegration(Console.WriteLine, variables);
                }

                break;
            }

            case OutputType.Json:
                switch (arguments.ShowVariable)
                {
                case null:
                    Console.WriteLine(JsonOutputFormatter.ToJson(variables));
                    break;

                default:
                    if (!variables.TryGetValue(arguments.ShowVariable, out var part))
                    {
                        throw new WarningException($"'{arguments.ShowVariable}' variable does not exist");
                    }
                    Console.WriteLine(part);
                    break;
                }

                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            if (arguments.UpdateWixVersionFile)
            {
                using (var wixVersionFileUpdater = new WixVersionFileUpdater(targetPath, variables, fileSystem, log))
                {
                    wixVersionFileUpdater.Update();
                }
            }

            using (var assemblyInfoUpdater = new AssemblyInfoFileUpdater(arguments.UpdateAssemblyInfoFileName, targetPath, variables, fileSystem, log, arguments.EnsureAssemblyInfo))
            {
                if (arguments.UpdateAssemblyInfo)
                {
                    assemblyInfoUpdater.Update();
                }

                var execRun    = RunExecCommandIfNeeded(arguments, targetPath, variables, log);
                var msbuildRun = RunMsBuildIfNeeded(arguments, targetPath, variables, log);

                if (!execRun && !msbuildRun)
                {
                    assemblyInfoUpdater.CommitChanges();
                    //TODO Put warning back
                    //if (!context.CurrentBuildServer.IsRunningInBuildAgent())
                    //{
                    //    Console.WriteLine("WARNING: Not running in build server and /ProjectFile or /Exec arguments not passed");
                    //    Console.WriteLine();
                    //    Console.WriteLine("Run GitVersion.exe /? for help");
                    //}
                }
            }
        }