Beispiel #1
0
        static void Main(string[] args)
        {
            var appConfigurator        = AppConfigurator.GetAppConfigurator();
            var appConfiguratorDefault = appConfigurator.Default;

            var(ownerCommand, runningCommand) = SubCommandParser.ParseCommandlineValue(args);

            if (runningCommand.Count == 0)
            {
                return;
            }

            // 其中的 OwnerCommand 先忽略
            // 判断 runningCommand 是否存在需要转换的参数
            var actualCommandline = CommandlineEngine.FillCommandline(runningCommand.ToArray(), appConfiguratorDefault);

            var commandlineArgString = new StringBuilder();

            for (var i = 1; i < actualCommandline.Length; i++)
            {
                var arg = actualCommandline[i];
                Console.WriteLine($"[{i}] = {arg}");
                commandlineArgString.Append(ProcessCommand.ToArgumentPath(arg));
                commandlineArgString.Append(' ');
            }

            var arguments = commandlineArgString.ToString();

            Console.WriteLine($"Command = {actualCommandline[0]} {arguments}");
            var(success, output) = ProcessCommand.ExecuteCommand(actualCommandline[0], arguments);
            Console.WriteLine(output);
        }
        private static void FormatCode()
        {
            var(_, output) = ProcessCommand.ExecuteCommand("dotnet", "tool update -g dotnet-format");
            Console.WriteLine(output);

            // dotnet format
            Console.WriteLine($"Start dotnet format");
            ProcessCommand.ExecuteCommand("dotnet", "format");
            Console.WriteLine($"Finish dotnet format");
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            var appConfigurator      = AppConfigurator.GetAppConfigurator();
            var compileConfiguration = appConfigurator.Of <CompileConfiguration>();

            // 用于替换的列表
            var replaceDictionary = new Dictionary <string, string>()
            {
                { "$(AppVersion)", compileConfiguration.AppVersion }
            };

            // 替换一些变量,然后原原本本传入到 dotnet 命令里面
            var argsString = new StringBuilder();

            foreach (var arg in args)
            {
                var temp = arg;
                if (replaceDictionary.TryGetValue(temp, out var replaceValue))
                {
                    temp = replaceValue;
                }

                temp = ProcessCommand.ToArgumentPath(temp);

                argsString.Append(temp);
                argsString.Append(' ');
            }

            Log.Info($"dotnet {argsString}");
            var(success, output) = ProcessCommand.ExecuteCommand("dotnet", argsString.ToString());
            if (success)
            {
                Log.Info(output);
            }
            else
            {
                Log.Error(output);
            }
        }
Beispiel #4
0
 /// <summary>
 /// 执行命令
 /// </summary>
 /// <param name="args"></param>
 /// <returns></returns>
 public (bool success, string output) ExecuteCommand(string args)
 {
     return(ProcessCommand.ExecuteCommand("git", args, Repo.FullName));
 }
Beispiel #5
0
 public static (bool success, string output) ExecuteCommand(this Git git, string args)
 {
     return(ProcessCommand.ExecuteCommand("git", args, git.Repo.FullName));
 }
        public void CompileAllCommitAndCopy()
        {
            _git.FetchAll();

            var commitList = GetCommitList().Reverse().ToList();

            for (var i = 0; i < commitList.Count; i++)
            {
                var commit = commitList[i];
                try
                {
                    Log($"开始 {commit} 二分,本次任务第{i + 1}次构建,总共{commitList.Count}次构建");

                    if (!CheckNeedCompile(commit))
                    {
                        Log($"已构建过 {commit} 无须再次运行,跳过此构建");
                        continue;
                    }

                    CleanDirectory(commit);

                    // 如果没有指定使用 bat 脚本构建,那么执行通用构建

                    var compilerBatFile = BinaryChopCompileConfiguration.CompilerBatFile;
                    if (string.IsNullOrEmpty(compilerBatFile) || !File.Exists(compilerBatFile))
                    {
                        Log($"找不到指定的 bat 构建脚本文件 {compilerBatFile} 将使用默认的方式构建");

                        // 这里是代码里面自己带的构建配置文件
                        var appConfigurator = GetCurrentBuildConfiguration();

                        var currentBuildLogFile = GetCurrentBuildLogFile(appConfigurator);

                        // 填充一下文件路径
                        var fileSniff = new FileSniff(appConfigurator);
                        fileSniff.Sniff();

                        var msbuildConfiguration = AppConfigurator.Of <MsbuildConfiguration>();

                        var msBuildCompiler = new MSBuild(appConfigurator);
                        msBuildCompiler.Build(new MSBuildCommandOptions()
                        {
                            ShouldRestore = msbuildConfiguration.ShouldRestore,
                            MaxCpuCount   = msbuildConfiguration.MaxCpuCount,
                        });

                        MoveFile(commit, currentBuildLogFile);
                    }
                    else
                    {
                        Log($"开始执行 {compilerBatFile} 构建脚本文件");

                        var(success, output) = ProcessCommand.ExecuteCommand(compilerBatFile, null);
                        // 将输出写入到文件里面
                        var logFile = Path.GetTempFileName();
                        File.WriteAllText(logFile, output);
                        MoveFile(commit, new FileInfo(logFile));
                    }

                    LastCommit = commit;

                    Log($"构建 {commit} 完成,休息一下。休息 {BinaryChopCompileConfiguration.SecondTimeToRest} 秒中");
                    // 构建完成,休息一下
                    // 同步的等待,这里是调度任务,不需要使用异步
                    Task.Delay(TimeSpan.FromSeconds(BinaryChopCompileConfiguration.SecondTimeToRest)).Wait();
                }
                catch (Exception e)
                {
                    Log(e.ToString());
                }
            }
        }