/// <summary> /// 部署 /// </summary> public void Deploy() { //根目录 string domainPath = GlobalTo.GetValue("WebHook:GitHub:DomainRootPath"); //子域名&文件夹 string subdomain = PrepositoryName; if (!string.IsNullOrWhiteSpace(PhomePage)) { subdomain = PhomePage.Replace("//", "^").Split('^')[1].Split('.')[0]; } string path = domainPath + subdomain; //异步 ThreadPool.QueueUserWorkItem(callBack => { if (!Directory.Exists(path)) { string cmd = CmdFor.GitClone(PgitUrl, path); CmdTo.Shell(cmd); } else { string cmd = CmdFor.GitPull(path); CmdTo.Shell(cmd); } }); }
public async Task <SharedResultVM> WebHook() { var vm = new SharedResultVM(); try { if (Request.Method == "POST") { using var ms = new MemoryStream(); await Request.Body.CopyToAsync(ms); string postStr = Encoding.UTF8.GetString(ms.ToArray()); Console.WriteLine(postStr); //TO DO var jo = postStr.ToJObject(); var respName = jo["repository"]["name"].ToString(); var projectPath = $"/package/site/{respName}"; if (Directory.Exists(projectPath) && Directory.Exists(Path.Combine(projectPath, ".git"))) { var arg = $"git -C \"{projectPath}\" pull --all"; Console.WriteLine(arg); var cr = CmdTo.Execute(arg); var rt = cr.CrOutput + cr.CrError; Console.WriteLine(rt); vm.Log.AddRange(rt.Split('\n')); } else { var errorMsg = $"{projectPath} Not Exists(.git)"; Console.WriteLine(errorMsg); vm.Log.Add(errorMsg); } vm.Set(SharedEnum.RTag.success); } } catch (Exception ex) { vm.Set(ex); } return(vm); }