예제 #1
0
        public void Execute()
        {
            log.Info($"Running on {(RunningOnUnix ? "Unix" : "Windows")}.");

            var variables = gitVersionCalculator.CalculateVersionVariables();

            var arguments = options.Value;

            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(variables.ToString());
                    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();
                assemblyInfoUpdater.CommitChanges();
            }

            RunExecCommandIfNeeded(arguments, arguments.TargetPath, variables, log);
            RunMsBuildIfNeeded(arguments, arguments.TargetPath, variables, log);
        }
        public static void Run(Arguments arguments, IFileSystem fileSystem)
        {
            Logger.WriteInfo($"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 executeCore = new ExecuteCore(fileSystem, arguments.ConfigFileLocator);
            var variables   = executeCore.ExecuteGitVersion(targetUrl, dynamicRepositoryLocation, authentication, targetBranch, noFetch, targetPath, commitId, overrideConfig, noCache);

            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:
                    if (!variables.TryGetValue(arguments.ShowVariable, out var part))
                    {
                        throw new WarningException($"'{arguments.ShowVariable}' variable does not exist");
                    }
                    Console.WriteLine(part);
                    break;
                }
            }

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

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

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

                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()
        {
            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");
                //}
            }
        }